Ejemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # bcrypt.generate_password_hash(form.password.data) - returns bytes
        # bcrypt.generate_password_hash(form.password.data).decode('utf-8') - returns string
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        user = User(email=form.email.data,
                    username=form.username.data,
                    password=hashed_password)
        # TODO delete
        user.active = True

        db.session.add(user)
        db.session.commit()

        profile = Profile(user_id=user.id, user=user)
        db.session.add(profile)
        db.session.commit()

        user.send_verification_email()
        # 'success' is the name of the BootStrap class for message.
        flash(f'A confirmation email has been sent to {form.email.data}',
              'success')
        return redirect(url_for('users.login'))
    return render_template('users/register.html', title='Register', form=form)
Ejemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in.', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    password=hashed_password,
                    is_admin=True)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('users.login'))
        flash('Registration succesfull', 'success')
    return render_template('master/register.html', form=form, title='register')
Ejemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        flash(f"You are already logged in", 'success')
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # encrypted password
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        flash(f"Account created for {form.username.data}", 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hash_password = sha256_crypt.encrypt(str(form.password.data))
        user = User(name=form.name.data,
                    username=form.username.data,
                    email=form.email.data,
                    password=hash_password)
        db.session.add(user)
        db.session.commit()

        flash('You are now registered and can log in', 'success')

        return redirect(url_for('users.login'))

    return render_template('register.html', title='Register', form=form)
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # db.create_all()
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        #CREATING USER

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Your account has been created, you can now login!', 'success')
        return redirect(url_for('users.signin'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 7
0
def register():

    # If user is already logged in, return to home page
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    # Set form variable to registration form
    form = RegistrationForm()

    # Only run following code if form response passes checks (in users/forms.py)
    if form.validate_on_submit():

        # Remove old user info if exists (and unvalidated)
        olduser = User.query.filter(
            User.username.ilike(
                f'%{form.username.data}%')).first()  # check if username exists
        if olduser and olduser.confirm_account is False:  # remove username
            db.session.delete(olduser)  # delete row entry
            db.session.commit()  # save changes
        oldemail = User.query.filter(User.email.ilike(
            f'%{form.email.data}%')).first()  # check for email in db
        if oldemail and oldemail.confirm_account is False:  # remove email
            db.session.delete(oldemail)  # delete row entry
            db.session.commit()  # save changes

        # Add user to db
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode(
            'utf-8')  # encrypt password
        newuser = User(username=form.username.data,
                       email=form.email.data,
                       password=hashed_pw,
                       date_register=datetime.now())  # noqa
        db.session.add(newuser)  # add row entry
        db.session.commit()  # save changes
        sendemail_auth(newuser)  # send authentication email

        # Inform user that email authentication is required
        flash(f'Email verification request sent to {form.email.data}!',
              'success')
        return redirect(url_for('users.login'))

    return render_template('register.html', title='Register',
                           form=form)  # key variables for .html
Ejemplo n.º 8
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        username = form.username.data
        password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(name=name,
                    email=email,
                    username=username,
                    password=password)
        db.session.add(user)
        db.session.commit()
        flash('You have registered successfully. You may login in now.',
              'success')
        return redirect(url_for('main.home'))

    return render_template('register.html', form=form)