def auth_register(): if request.method == "GET": return render_template("auth/registerform.html", form=RegisterForm()) register_form = RegisterForm(request.form) if not register_form.validate(): return render_template("auth/registerform.html", form=register_form) user = User.query.filter_by(username=register_form.username.data).first() if user: return render_template("auth/registerform.html", form=register_form, error="Username already taken!") # Everything ok, create new user u = User(register_form.name.data, register_form.username.data, register_form.password.data) db.session().add(u) db.session().commit() # Create a role aswell r = Role() r.account_id = u.id db.session().add(r) db.session().commit() # Login straight away login_user(u) return redirect(url_for("categories_index"))
def insert_initial_roles(*args, **kwargs): db.session.add(Role(role='ADMIN')) db.session.commit() db.session.add(Role(role='GUEST')) db.session.commit() db.session.add(Role(role='USER')) db.session.commit()
def init_categories(): stmt = text('SELECT * FROM Category;') res = db.engine.execute(stmt) if (res.fetchone() != None): return category1 = Category('Sports') category2 = Category('Gaming') category3 = Category('Programming') userrole = Role('USER') adminrole = Role('ADMIN') db.session().add(userrole) db.session().add(adminrole) db.session().add(category1) db.session().add(category2) db.session().add(category3) db.session().commit() normaluser = User(' ', 'user', 'user') adminuser = User(' ', 'admin', 'admin') db.session().add(normaluser) db.session().add(adminuser) db.session().commit() db.session().add(User_Role(normaluser.id, 1)) db.session().add(User_Role(adminrole.id, 2)) db.session().commit()
def auth_register(): if request.method == "GET": return render_template("auth/registerform.html", form=RegisterForm()) form = RegisterForm(request.form) if not form.validate(): return render_template("auth/registerform.html", form=form) user = User.query.filter_by(username=form.username.data).first() if user: return render_template("auth/registerform.html", form=form, error="Username already taken!") user = User(form.name.data, form.username.data, form.password.data) db.session().add(user) db.session().commit() role = Role() role.account_id = user.id db.session().add(role) db.session().commit() login_user(user) return redirect(url_for("index"))
def roles_create(): form = RoleForm(request.form) if not form.validate(): return render_template("roles/new.html", form = RoleForm) n = form.rolename.data r = Role(n) r.account_id = current_user.id db.session().add(r) db.session().commit() return redirect(url_for("roles_index"))
def bettor_create(): form = BettorForm(request.form) if not form.validate(): return render_template("auth/new_bettor.html", form = form) pw = sha256_crypt.encrypt(form.password.data) b = Bettor(form.username.data, pw, 0, 0) db.session().add(b) db.session().commit() # etsitään customer roolia, jonka pitäisi olla Role-taulussa, mutta jos ei ole, luodaan se role = Role.query.filter_by(name="CUSTOMER").first() if role == None: role = Role("CUSTOMER") db.session().add(role) db.session().commit() # kiinnitetään rooli pelaajalle liitostauluun user_role = User_role() user_role.bettor_id = b.id user_role.role_id = role.id db.session().add(user_role) db.session().commit() flash("Account created successfully, please login to your account") flash("After you have logged in, you can transfer money to your account") return redirect(url_for("auth_login"))
def roles_create(): form = RoleForm(request.form) if not form.validate(): return render_template("roles/new.html", form=form) role = Role(form.name.data) db.session().add(role) db.session().commit() return redirect(url_for("roles_index"))
def roles_create(): form = RoleForm(request.form) if not form.validate(): return render_template("roles/list.html", roles=Role.get_role_list(), form=form) role = Role(form.name.data) try: db.session.add(role) db.session.commit() except IntegrityError: db.session.rollback() return render_template("roles/list.html", roles=Role.get_role_list(), form=form, Roles_name_taken=True) return render_template("roles/list.html", roles=Role.get_role_list(), form=form)
def role_update(): if request.method == "GET": return render_template("roles/roleaddform.html", form=RoleForm()) form = RoleForm(request.form) if not form.validate(): return render_template("roles/roleaddform.html", form=form) r = Role.query.filter_by(name=form.name.data, team=form.team.data, role=form.role.data).first() if not r: u = Role(form.name.data, form.team.data, form.role.data) db.session.add(u) db.session.commit() flash('Rooli lisätty') return redirect(url_for("index")) else: flash('Käyttäjällä jo kyseinen rooli') return redirect(url_for("index"))
def registration_form(): form = RegistrationForm() if form.validate_on_submit(): user = User(name=form.name.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() role = Role(account_id=user.id, role_name="USER") db.session.add(role) db.session.commit() return redirect(url_for("auth_login")) return render_template("registration/new.html", title='Register', form=form)
def roles(self): return Role.getRoleByUserId(self.id)
from application.betting_offers_of_coupon import models from application.roles import models from application.user_roles import models from application.auth import views from application.auth import models from application.statistics import views from application.auth.models import Bettor from application.roles.models import Role @login_manager.user_loader def load_user(user_id): return Bettor.query.get(user_id) try: db.create_all() except: pass try: cust = Role.query.filter_by(name="CUSTOMER").first() admin = Role.query.filter_by(name="ADMIN").first() if cust == None: db.session().add(Role("CUSTOMER")) if admin == None: db.session().add(Role("ADMIN")) db.session().commit() except: pass
def roles(self): roles = Role.getRoles(self.name, self.team) if not roles: return [] return roles
def roles_index(): form = RoleForm() return render_template("roles/list.html", roles=Role.get_role_list(), form=form)