Example #1
0
def register():
    if current_user.is_authenticated:
        flash('Anda Sudah Masuk Dengan Akun Anda', 'success')
        return redirect(url_for('home'))
    form = RegistrationForm()
    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()
        flash(f'Akun berhasil dibuat!, Mohon Login Menggunakan Akun Anda',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Example #2
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('Token Tidak Valid atau Kadaluarsa', '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(
            'Kata Sandi Anda Berhasil Diperbaharui! Anda DApat Login Menggunakan Kata Sandi Baru!',
            'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           title='Atur Ulang Kata Sandi',
                           form=form)