def signup_new(): 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_exists = User.query.filter_by(username=form.username.data).first() if user_exists: form.username.errors.append( "This username is already in use. Please choose another username.") return render_template("auth/signupform.html", form=form) name = form.name.data username = form.username.data password = form.password.data new_user = User(name, username, password, 0) db.session.add(new_user) db.session.commit() return redirect(url_for("auth_login"))
def auth_signup(): if request.method == 'GET': return render_template('auth/signup.html', form=SignUpForm()) form = SignUpForm(request.form) if not form.validate(): return render_template('auth/signup.html', form=form) user = User.query.filter_by(username=form.username.data).first() if user: return render_template('auth/signup.html', form=form, error='Username is taken') password = form.password.data.encode() salt = bcrypt.gensalt(rounds=10) phash = bcrypt.hashpw(password, salt) user = User(username=form.username.data, phash=phash.decode()) with session_scope() as session: session.add(user) session.flush() roles = Role.query.filter(Role.name.in_(['APPROVED', 'USER'])).all() session.bulk_save_objects( [UserRole(role_id=role.id, account_id=user.id) for role in roles]) 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) wantedUsername = form.username.data existingUser = User.query.filter_by(username=wantedUsername).first() # jos käyttäjänimi ei ole jo käytössä if not existingUser: try: newUser = User(form.username.data, form.password.data) db.session().add(newUser) db.session.commit() except: flash("Error while creating account, please try again", "alert alert-danger") return redirect(url_for("auth_signup")) # uusi käyttäjä tallennettiin tietokantaan ja kirjataan sisään login_user(newUser) flash( f"Welcome to the Forum, {current_user.username}! You are ready to start posting.", "alert alert-info") return redirect(url_for("posts_index")) else: return render_template( "auth/signupform.html", form=form, error="Wanted username already taken, choose another.")
def auth_sign_up(): if request.method == "GET": return render_template("auth/signup.html", form=SignUpForm()) form = SignUpForm(request.form) if request.method == "POST" and not form.validate_on_submit(): return render_template("auth/signup.html", form=form) name = form.name.data username = form.username.data password = form.password.data new_user = User(name, username, password) existing_user = User.query.filter_by(username=username).first() if existing_user is not None: return render_template( "auth/signup.html", form=form, extra_error="Käyttäjänimi varattu" ) db.session().add(new_user) db.session().commit() return redirect(url_for("auth_login"))
def auth_create(): form = SignUpForm(request.form) if not form.validate(): return render_template("auth/new.html", form=form) hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') t = User(form.name.data, form.username.data, hashed_password) db.session().add(t) db.session().commit() flash('Your account was successfully created') return redirect(url_for("auth_login"))
def show_profile(user_id): user = User.query.get(user_id) form = SignUpForm(obj=user) return render_template("auth/show_profile.html", user=User.query.get(user_id), form=form, user_reseptit=User.user_reseptit(user_id))
def signup(): form = SignUpForm() if form.validate_on_submit(): person = Person() person.username = form.username.data person.email = form.email.data person.password = form.password.data db.session.add(person) db.session.commit() login_user(person, remember=True) return redirect(url_for('index')) return templating.render_template('signup.j2', form=form)
def auth_create(): form = SignUpForm(request.form) if not form.validate(): return render_template("auth/new.html", form=form) usernameExists = User.query.filter_by(username=form.username.data).first() if usernameExists: return render_template("auth/new.html", form=form, error="Username already exists") u = User(form.name.data, form.username.data, form.password.data, form.role.data) db.session().add(u) db.session().commit() return redirect(url_for("courses_index"))
def auth_signup(): if request.method == "GET": return render_template("auth/signup.html", form = SignUpForm()) form = SignUpForm(request.form) if not form.validate(): return render_template("auth/signup.html", form = form) user = User(form.name.data, form.username.data, form.password.data, form.email.data) db.session().add(user) db.session().commit() user.set_default_role() login_user(user) print("Rekisteröinti onnistui") return redirect(url_for("index"))
def auth_register(): if request.method == "GET": return render_template("auth/signup.html", form=SignUpForm()) else: form = SignUpForm(request.form) username = form.username.data name = form.name.data phonenumber = form.phonenumber.data address = form.address.data rolebox = form.rolebox.data if rolebox: roles = "ADMIN" else: roles = "USER" password = form.password.data kayttaja = Kayttaja(username, name, phonenumber, address, password, roles) db.session().add(kayttaja) 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=SignUpForm(), error="Invalid information") user = User.query.filter_by(username=form.username.data).first() if user: return render_template("auth/signupform.html", form=SignUpForm(), error=user.username + " already taken") user = User(form.firstName.data + ' ' + form.lastName.data) user_role = Role.query.filter_by(name='User').first() user.username = form.username.data password = form.password.data pw_hash = generate_password_hash(password).decode('utf-8') user.password = pw_hash user.roles.append(user_role) db.session().add(user) db.session().commit() return redirect(url_for("auth_login"))
def auth_form(): return render_template("auth/new.html", form=SignUpForm())