-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
49 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,35 @@ | ||
from sqlalchemy import create_engine, ForeignKey, Column, Integer, String, Table, text | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker, relationship | ||
import json | ||
import random | ||
import math | ||
|
||
engine = create_engine('sqlite:///users.db', | ||
connect_args={'check_same_thread': False}) | ||
engine = create_engine('sqlite:///users.db',connect_args={'check_same_thread': False}) | ||
|
||
connection = engine.connect() | ||
Base = declarative_base() | ||
Session = sessionmaker(bind=engine) | ||
session = Session() | ||
connection=engine.connect() | ||
Base=declarative_base() | ||
Session= sessionmaker(bind=engine) | ||
session=Session() | ||
|
||
roles_users = Table( | ||
'roles_users', Base.metadata, | ||
roles_users = Table('roles_users',Base.metadata, | ||
Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE")), | ||
Column('role_id', Integer, ForeignKey('roles.id', ondelete="CASCADE"))) | ||
|
||
Column('role_id', Integer, ForeignKey('roles.id', ondelete="CASCADE")) | ||
) | ||
|
||
class User(Base): | ||
__tablename__ = 'users' | ||
__tablename__='users' | ||
|
||
id = Column(Integer, primary_key=True) | ||
email = Column(String(100), unique=True) | ||
password = Column(String(255)) | ||
roles = relationship('Role', secondary=roles_users) | ||
|
||
roles = relationship('Role', secondary=roles_users) | ||
def regist(user_email, user_password): | ||
"""Adds User to Database and gives the standard-role: 'User' | ||
Parameter: user_email = String | ||
Parameter: user_password = String | ||
""" | ||
new_User = User(email=user_email, password=user_password) | ||
new_user_role = session.query(Role).filter(Role.name == 'User').first() | ||
new_User.roles = [new_user_role] | ||
new_User=User(email=user_email, password=user_password) | ||
new_user_role=session.query(Role).filter(Role.name=='User').first() | ||
new_User.roles=[new_user_role] | ||
session_add_and_commit(new_User) | ||
|
||
def login(user_email, user_password): | ||
|
@@ -43,44 +38,38 @@ def login(user_email, user_password): | |
Parameter: user_email = String | ||
Parameter: user_password = String | ||
""" | ||
login_bool = False | ||
users = session.query(User) | ||
login_bool=False | ||
users=session.query(User) | ||
for user in users: | ||
if user_email == user.email and user_password == user.password: | ||
login_bool = True | ||
if user_email==user.email and user_password==user.password: | ||
login_bool=True | ||
return login_bool | ||
|
||
def getall2Dict(): | ||
""" returns Userdata of all Users with roles in a list of Dictionarys | ||
Dict={'ID':user.id,'Email':user.email,'Password':user.password,'Roles':userrolelist} | ||
Return: userdicts = List (dict) | ||
""" | ||
userdicts = [] | ||
users = session.query(User).join(User.roles).all() | ||
userdicts=[] | ||
users=session.query(User).join(User.roles).all() | ||
for user in users: | ||
userrolelist = [] | ||
userrolelist=[] | ||
for role in user.roles: | ||
userrolelist.append(role.name) | ||
userdict = { | ||
'ID': user.id, | ||
'Email': user.email, | ||
'Password': user.password, | ||
'Roles': userrolelist | ||
} | ||
userdicts.append(userdict) | ||
userrolelist.append(role.name) | ||
userdict={'ID':user.id,'Email':user.email,'Password':user.password,'Roles':userrolelist} | ||
userdicts.append(userdict) | ||
return userdicts | ||
|
||
def delete(user_ID): | ||
"""Deletes User with given user_ID | ||
Parameter: user_ID = String""" | ||
user = session.query(User).filter(User.id == user_ID) | ||
user=session.query(User).filter(User.id==user_ID) | ||
if user.first().email != '[email protected]': | ||
user.delete() | ||
session.commit() | ||
|
||
|
||
class Role(Base): | ||
__tablename__ = 'roles' | ||
__tablename__='roles' | ||
|
||
id = Column(Integer, primary_key=True) | ||
name = Column(String(40), unique=True) | ||
|
@@ -90,25 +79,22 @@ def add(role_name, role_description): | |
"""Adds Role to Database | ||
Parameter: role_name = String, role_description = String | ||
""" | ||
new_Role = Role(name=role_name, description=role_description) | ||
new_Role=Role(name=role_name, description=role_description) | ||
session_add_and_commit(new_Role) | ||
|
||
def role2User(user_email, role_name): | ||
"""Adds Role with role_name to User with user_email | ||
Parameter: role_name = String, role_description = String | ||
""" | ||
user_roles = [] | ||
user = session.query(User).join( | ||
User.roles).filter(User.email == user_email).first() | ||
user_roles=[] | ||
user=session.query(User).join(User.roles).filter(User.email==user_email).first() | ||
for role in user.roles: | ||
user_roles.append(role) | ||
new_user_role = session.query(Role).filter( | ||
Role.name == role_name).first() | ||
new_user_role=session.query(Role).filter(Role.name==role_name).first() | ||
user_roles.append(new_user_role) | ||
user.roles = user_roles | ||
user.roles=user_roles | ||
session.commit() | ||
|
||
|
||
def session_add_and_commit(new_obj_name): | ||
"""speichert new_obj_name in Datenbank ein | ||
Parameter: new_obj_name = sqlelement | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "_base.j2" %} | ||
{% set active_link = 'Kalender' %} | ||
{% block styles %} | ||
{{ super() }} | ||
<style> | ||
</style> | ||
{% endblock %} | ||
{% block title %} <title>Kalender</title> {% endblock %} | ||
{% block content %} | ||
<div> | ||
|
||
<!-- Nav tabs --> | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li> | ||
<li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li> | ||
<li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li> | ||
<li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li> | ||
</ul> | ||
|
||
<!-- Tab panes --> | ||
<div class="tab-content"> | ||
<div role="tabpanel" class="tab-pane active" id="home">...</div> | ||
<div role="tabpanel" class="tab-pane" id="profile">...</div> | ||
<div role="tabpanel" class="tab-pane" id="messages">...</div> | ||
<div role="tabpanel" class="tab-pane" id="settings">...</div> | ||
</div> | ||
|
||
</div> | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters