예제 #1
0
def change_password():
    title = "Change Password"
    meta_description = "Change Password Here."
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if form.validate_on_submit():
            user = User.query.get(current_user.id)
            if user and bcrypt.check_password_hash(user.password,
                                                   form.password.data):
                new_hashed_password = bcrypt.generate_password_hash(
                    form.new_password.data).decode('utf-8')
                User.query.filter_by(id=current_user.id).update(
                    {User.password: new_hashed_password})
                db.session.commit()
                logout_user()
                flash(f'Password Changed Successfully', 'success')
                return redirect(url_for('login'))
            else:
                flash(
                    f'An Error Occurred. You Might Have Typed a Wrong Password',
                    'warning')
    return render_template('change_password.html',
                           title=title,
                           meta_description=meta_description,
                           form=form)
예제 #2
0
파일: user.py 프로젝트: charlee/flashpins
def authenticate(email, password):
  """
  Verify if Email and password are correct
  """
  user_id = User.get_id_by_email(email)
  if user_id:
    user = User.get(user_id, ['password_digest'])

    if bcrypt.check_password_hash(user.password_digest, password):
      return user_id

    return False
예제 #3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.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 email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
예제 #4
0
def login():
    if current_user.is_authenticated:
        redirect(url_for('main'))
    title = "Login"
    meta_description = "Please Login to build your own Technical/Hospitality Rider." \
                       " You may try multiple times to achieve best results, so login system is necessary"
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=True)
            return redirect(url_for('main'))
        else:
            flash('Login Error', 'danger')
    return render_template('login.html',
                           title=title,
                           form=form,
                           meta_description=meta_description)
예제 #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    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)
            flash(f'Welcome back {form.username.data}!')
            return redirect(url_for('account'))
        elif not user:
            flash(
                "Please register for an account if you don't already have one."
            )
            return redirect(url_for('register'))
        else:
            flash("Invalid username or password.")
            return redirect(url_for('login'))
    return render_template('login.html', title='Login', form=form)
예제 #6
0
def login():
    if current_user.is_authenticated:
        flash('You already Logged in bro', 'warning')
        return redirect(url_for('home'))

    form = LoginForm()
    if form.validate_on_submit():
        student = Student.query.filter_by(username=form.username.data).first()
        #  Decrypting password
        if student and bcrypt.check_password_hash(student.password,
                                                  form.password.data):
            flash('You have successfully logged in Mr.' + student.username,
                  'success')
            # send_email('*****@*****.**', 'Fresh Registration', 'mail/new_user')
            #  to = str(student.phone)
            #  send_message('You are logged in bro for',to,'Carnival')
            login_user(student)
            return redirect(url_for('home'))
        else:
            flash('Credentials are wrong', 'danger')
    return render_template('login.html',
                           title='Login',
                           form=form,
                           sidebar=True)
예제 #7
0
 def verify_password(self, password):
     """
     Method is used to verify a users password matches the
     password passed
     """
     return bcrypt.check_password_hash(self._password, password)