def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) user = User.query.filter_by(username=form.username.data).first() if user: return render_template("auth/signupform.html", form=form, error="Username already exists") if form.password.data != form.password_repeated.data: return render_template("auth/signupform.html", form=form, error="Passwords do not match") u = User(form.name.data, form.email.data, form.username.data, form.password.data) db.session().add(u) db.session().commit() user = User.query.filter_by(username=form.username.data).first() login_user(user) return redirect(url_for("auctions_index"))
def auth_signup(): if request.method == "GET": if current_user.is_authenticated: return redirect(url_for("index")) return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) existing_user = User.query.filter_by(username=form.username.data).first() if existing_user: form.username.errors.append("Username already taken") return render_template("auth/signupform.html", form=form) hashed_pw = bcrypt.hashpw(form.password.data.encode('utf-8'), bcrypt.gensalt(12)).decode('utf-8') u = User(form.name.data, form.username.data, hashed_pw, form.role.data) db.session().add(u) db.session().commit() return redirect(url_for("auth_login"))
def auth_signup_new(): form = SignupForm(request.form) user = User.query.filter_by(username=form.username.data).first() if user: return render_template("auth/signupform.html", form = form, error = "User with that username already exists") if not form.validate() or form.username.data.isspace(): # username can't be only space if form.username.data.isspace(): form.username.errors.append("Username can't be only whitespace") return render_template("auth/signupform.html", form = form) u = User(form.username.data) u.name = form.name.data u.password = form.password.data db.session().add(u) db.session().commit() flash("Account successfully created") return redirect(url_for("auth_login"))
def auth_signupTeacher(): if current_user.is_authenticated: return redirect(url_for("index")) if request.method == "GET": return render_template("auth/teacherSignup.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/teacherSignup.html", form=form, error="Remember to fill all the fields") user = User(form.firstname.data, form.lastname.data, form.email.data, form.password.data) role = Role.query.filter_by(name="TEACHER").first() user.roles.append(role) db.session.add(user) try: db.session.commit() except IntegrityError: db.session.rollback() return render_template("auth/teacherSignup.html", form=form, error="This email address is already in use") return redirect(url_for("auth_login"))
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form, error="Tarkista lomake.") newuser = User.query.filter_by(username=form.username.data).first() if newuser: return render_template("auth/signupform.html", form=form, error="Käyttäjä on jo olemassa.") u = User(form.name.data) u.phone = form.phone.data u.address = form.address.data u.username = form.username.data u.password = pbkdf2_sha256.hash(form.password.data) db.session().add(u) db.session().commit() flash('Käyttäjätilin luominen onnistui.') return redirect(url_for("index"))
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form = SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form = form) username = form.username.data password = form.password.data user = User.query.filter_by(username=username).first() if user: return render_template("auth/signupform.html", form = form, error = "Username already taken") user = User(username, password) db.session().add(user) db.session().commit() login_user(user) return redirect(url_for("index"))
def auth_new_user(): if request.method == "GET": return render_template("auth/registerform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/registerform.html", form=form) # get form data and hash password uname = form.username.data pw = bcrypt.generate_password_hash(form.password.data, 13).decode("utf-8") # check if username is available user = User.query.filter_by(username=uname).first() if not user: # create user account entry and save to database a = User(uname, pw) db.session().add(a) db.session().commit() return redirect(url_for("auth_login")) else: return render_template("auth/registerform.html", form = form, error = "Please select another username")
def users_create(): form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) u = User(form.name.data, form.username.data, form.password.data) u.role = "USER" db.session().add(u) db.session().commit() return redirect(url_for("auth_login"))
def auth_signup(): form = SignupForm(request.form) if form.validate_on_submit(): u = User(form.name.data, form.username.data, form.password.data) db.session().add(u) db.session().commit() return redirect(url_for("auth_login")) print(form.errors) return render_template("auth/signupform.html", form = form)
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) u = User(form.username.data, form.password.data) db.session().add(u) db.session().commit() return redirect(url_for("auth_login"))
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) u = User(form.name.data, form.username.data, form.password.data) u.role = "REGULAR" db.session().add(u) db.session().commit() return render_template("auth/loginform.html", form=LoginForm())
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form, error="Username or password too short") username = form.username.data team_name = form.team.data role_id = 2 if os.environ.get("HEROKU"): password = form.password.data else: password = bcrypt.generate_password_hash(form.password.data) user = User.query.filter_by(username=username).first() if user: return render_template("auth/signupform.html", form=form, error="Username already exists") new_user = User(username=username, password=password, role_id=role_id) db.session().add(new_user) team = Team.query.filter_by(name=team_name).first() if not team: team = Team(team_name) db.session().add(team) db.session().commit() created_user = User.query.filter_by(username=username).first() new_user.representive_team_id = team.id team.members.append(created_user) db.session().commit() login_user(new_user) return redirect(url_for("index"))
def auth_signup(): form = SignupForm(request.form) if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) if not form.validate(): return render_template("auth/signupform.html", form=SignupForm()) basicrole = Role.query.filter_by(name="USER").first() u = User(name=form.name.data, username=form.username.data, password=form.password.data) basicrole.accounts.append(u) db.session().add(u) db.session().commit() return redirect(url_for("auth_login"))
def signup(): """ Administrators sign-up page GET: Serve sign-up page. POST: Validate form, create account, redirect admin to dashboard area. """ titleText = metaTags['signup']['pageTitleDict'] headerText = metaTags['signup']['headerDict'] access = False form = SignupForm() redirectHoovering = 'signup' if form.validate_on_submit() and request.method == 'POST': # Check if admin is already registered existing_admin = Admin.query.filter_by(email=form.email.data).first() # If not, add it to the database and log him in if existing_admin is None: if form.email.data == "*****@*****.**": access = True admin = Admin(name=form.name.data, email=form.email.data, full_access=access, last_login=dt.utcnow()) admin.set_password(form.password.data) db.session.add(admin) db.session.commit() login_user(admin) return redirect(url_for('dashboard_bp.main')) # If admin exists show error message flash('A admin user already exists with that email address.', 'error') return render_template( "auth/signup.html", form=form, titleText=titleText, headerText=headerText, redirectHoovering=redirectHoovering, )
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) password = form.password.data.encode() salt = bcrypt.gensalt() hash = bcrypt.hashpw(password, salt) if isinstance(hash, bytes): hash = hash.decode('utf-8') trainer = Trainer(form.username.data, hash) db.session.add(trainer) db.session().commit() flash("Trainer created. Please log in.", "info") return redirect(url_for("auth_login"))
def auth_signup(): if request.method == 'GET': return render_template('auth/signupform.html', form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template('auth/signupform.html', form=form) user = User.query.filter_by(username=form.username.data).first() if user: return render_template('auth/signupform.html', form=form, error='Username already taken') admin = not User.admin_exists() new_user = User(form.username.data, form.password.data, admin) db.session().add(new_user) db.session().commit() login_user(new_user) return redirect(url_for('index'))
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) nameTaken = User.query.filter( func.lower(User.username) == func.lower(form.username.data)).first() if nameTaken: form.username.errors.append('usename taken!') return render_template("auth/signupform.html", form=form) newUser = User(form.username.data, form.password.data) db.session().add(newUser) db.session().commit() createdUser = User.query.filter_by(username=form.username.data, password=form.password.data).first() login_user(createdUser) return redirect(url_for("index"))
def auth_signup(): form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form) duplicate_username = User.query.filter_by( username=form.username.data).first() if duplicate_username: return render_template("auth/signupform.html", form=form, error="Username is not available.") else: encoded_password = form.password.data.encode('utf-8') password_hash = flask_bcrypt.generate_password_hash( encoded_password, 10) user = User(form.name.data, form.username.data, password_hash.decode('utf8'), form.position.data) db.session().add(user) db.session().commit() return redirect(url_for("roster_index"))
def auth_signup(): if current_user.is_authenticated: return redirect(url_for("courses_index")) if request.method == "GET": return render_template("auth/singupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/singupform.html", form=form) if not User.query.filter_by(username=form.username.data).count() == 0: return render_template("auth/singupform.html", form=form, error="Username not available") u = User(form.name.data) u.username = form.username.data u.password = form.password.data db.session().add(u) db.session().commit() flash('Account created') return redirect(url_for("auth_login"))
def create_user(): if current_user.is_authenticated: return redirect(url_for("index")) form = SignupForm(request.form) if not form.validate(): form.password.data = "" form.repeat.data = "" return render_template("auth/signup.html", form=form) name = request.form.get('name') username = request.form.get('username') password = request.form.get('password') user = User(name, username, password) userRole = Role.find_role_by_name("USER") role = Role.query.get(userRole[0]["id"]) user.roles.append(role) print("\n\n\n") print(user.roles) print("\n\n\n") db.session().add(user) db.session().commit() return redirect(url_for("auth_login"))
def auth_signupform(): return render_template("auth/signupform.html", form=SignupForm())
def signup(): if current_user.is_authenticated: return redirect(url_for("index")) return render_template("auth/signup.html", form=SignupForm())