Beispiel #1
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(
            url_for("main.home")
        )  #send the user the home page if they are already logged in

    user = User.verify_reset_token(token)

    if user is None:
        flash("This is invalid or an expired token!", "warning")
        return redirect(url_for("users.reset_request"))
    form = ResetPasswordForm()
    if form.validate_on_submit():

        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashed_pw
        db.session.commit(
        )  #passoword from user is hashed then information is updated to database

        flash("Your Password Has Been Updated!",
              "success")  #sends success message to the user when submit form
        return redirect(url_for("users.login"))

    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Beispiel #2
0
def registeruser():
    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)
        user = User(username=form.username.data, email=form.email.data, password=hashed_password, role='user')
        db.session.add(user)
        db.session.commit()
        flash('Account is created, you can now Sign In!','success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
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('You have created an account','success')
        return redirect(url_for('login'))
    return render_template('register.html',title='Register',form=form)
Beispiel #4
0
def reset_token(token):
    #if current_user.is_authenticated():
    #   return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an 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('Your password has been updated! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', title='Reset Password', form=form )
Beispiel #5
0
def reset(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash(f"Sorry, the link is invalid or has expired!", 'warning')
        return redirect(url_for('users.request_reset'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_pwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_pwd
        db.session.commit()
        flash(f'Password has been reset for the username {user.username}.', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset.html', title = "Reset Password", form = form)
Beispiel #6
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        val = User.query.filter_by(email=form.email.data).first()
        val1 = User.query.filter_by(email=form.email.data).first()
        if val == None and val == None:
            user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
            db.session.add(user)
            db.session.commit()
            flash(f'Account created for {form.username.data}', 'success')
            return redirect(url_for('home'))
        else:
            flash(f'The Username and Email should be unique', 'danger')
    return render_template('register.html', title='Register', form=form)
Beispiel #7
0
def register():
    form = RegistrationForm()
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    if form.validate_on_submit():

        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(
        )  #passoword from user is hashed then information is added to database

        #check to see  if email or username is in  database

        flash(f"Account Has Been Created. You Can Now Login!",
              "success")  #sends success message to the user when submit form
        return redirect(url_for("users.login"))
    return render_template("register.html", title="Register", form=form)