Esempio n. 1
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_passwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_passwd)
        db.session.add(user)
        db.session.commit()
        flash(f'Your account created successfully. Please login !!! ', category='success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title="Registration", form=form)
Esempio n. 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        if form.validate_on_submit():
            profile_pic = None
            if form.picture.data:
                profile_pic = save_profile_picture(form.picture.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pw,
                    image_file=profile_pic)
        db.session.add(user)
        db.session.commit()
        flash('Your account was created. You can now login!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 3
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('main.home'))
	form = RegistrationForm()
	if form.validate_on_submit():
		hashedPassword = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user = User(username = form.username.data, email = form.email.data, password = hashedPassword)
		db.session.add(user)
		db.session.commit()
		flash('Your account has been created. You can now Sign In!', 'success')
		return redirect(url_for('users.login'))
	return render_template('register.html', title = 'Register', form = form)
Esempio n. 4
0
def register():
    if current_user.administrator != 1:
        abort(403)
    form = RegistrationForm()
    posts = Post.query.all()
    if form.validate_on_submit():
        hashedPassword = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=str(form.username.data).lower(),
                    email=str(form.email.data).lower(),
                    password=hashedPassword)
        db.session.add(user)
        db.session.commit()
        usersLoggedIn(user.username, user.id, user.administrator)
        flash(
            "Account created!  Please finish setting up user details when ready.",
            "success")
        return redirect(url_for("users.admin"))
    return render_template("register.html",
                           title="Register User",
                           form=form,
                           posts=posts)