Exemple #1
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 may log-in now', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #2
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user in None:
        flash('Invalid or Expired Token', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Password updated! You may now login.', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', title='Reset Password', form=form)
Exemple #3
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Exemple #4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = Registration_Form()

    if form.validate_on_submit():

        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')  #encryption password

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        #full_name=form.full_name.data, nric=form.nric.data

        #adding the user to database
        db.session.add(user)
        db.session.commit()

        flash(f'Your account has been created! You are now able to log in.',
              'success')

        #get form data
        # username = form.username.data
        # password = form.password.data
        # email = form.email.data

        # fullname = form.full_name.data
        # nric = form.nric.data

        # #flask-mysqldb stuff
        # cur = mysql.connection.cursor()
        # cur.execute("INSERT INTO Users(Username, Password, Email, Full_Name, NRIC) VALUES(%s, %s, %s, %s, %s)",
        #             (username, password, email, fullname, nric))
        # mysql.connection.commit()
        # cur.close()
        return redirect(url_for("login"))

    return render_template("register.html", title="Sign Up", form=form)
Exemple #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = Registration_Form()

    if form.validate_on_submit():

        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')  #encryption password

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        #full_name=form.full_name.data, nric=form.nric.data

        #adding the user to database
        db.session.add(user)
        db.session.commit()

        flash(f'Your account has been created! You are now able to log in.',
              'success')
        return redirect(url_for("login"))

    return render_template("register.html", title="Sign Up", form=form)