Beispiel #1
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 = Byke_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)
Beispiel #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(f'Account created for {form.username.data}!', 'success')
        flash('Your account is created and you can login now!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', titile='Register', form=form)
Beispiel #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    name=form.name.data,
                    password=hashed)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}! You can now log in.',
              'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Beispiel #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    hashed = bcrypt.generate_password_hash('pass').decode('utf-8')
    print(bcrypt.check_password_hash(hashed, 'pass'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            return redirect(url_for('main.index'))
        else:
            flash(
                'Login Unsucccessful. Please check username and/or password.',
                'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #5
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 account password has been updated and you can login now!',
              'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Beispiel #6
0
def register():
    if current_user.is_authenticated:
        flash(f"You are already logged in {current_user.mail}", "success")
        return redirect(url_for("home"))
    form = RegForm()
    if form.validate_on_submit():
        pass_hash = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = Users(username=form.username.data,
                     mail=form.mail.data,
                     password=pass_hash)
        db.session.add(user)
        db.session.commit()
        flash(
            f"Thanks for signing up {form.username.data}! You are now logged in!",
            "success")
        return redirect(url_for("login"))
    return render_template("register.html",
                           title="Register",
                           date_now=date_now,
                           form=form)
Beispiel #7
0
 def set_password(self, password):
     self.password = bcrypt.generate_password_hash(password).decode(
         "utf-8", "ignore")