예제 #1
0
def reset_token(token):
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('home'))
    form = ResetPasswordForm()
    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)
        user.password = hashed_pw
        db.session.commit()
        flash('Your password has been reset, please login', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form_picture=form)
예제 #2
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    email=form.email.data,
                    password=hashed_password,
                    number=form.number.data)
        db.session.add(user)
        db.session.commit()
        flash('YOUR ACCOUNT IS CREATED ! YOU CAN LOGIN')
        return redirect(url_for('login'))
    return render_template('signup.html', title='SignUp', form=form)
예제 #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,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are able to login',
              'success')
        return redirect(url_for('users.login'))  # name of the function
    return render_template('register.html', title='Register', form=form)
예제 #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        userjson = db.user.find_one({'email': form.email.data})
        if userjson and bcrypt.check_password_hash(userjson['password'],
                                                   form.password.data):
            user = User(email=userjson['email'])
            login_user(user, remember=form.remenber.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login Unsuccessful. Please check username and password:)',
                  'danger')
    return render_template('login.html', title='Login', form=form)
예제 #5
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 able to login',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)