示例#1
0
def reset_password(code):
    if current_user.is_authenticated:
        flash(
            'You are already logged in. If you want to change your password, you can do that in the Account Settings Tab.'
        )
        return render_template('password_templates/reset_password.html')
    form = ResetPassword()
    user = Student.query.filter_by(reset_code=code).first()
    if user == None:
        user = Teacher.query.filter_by(reset_code=code).first()
    if user == None:
        return render_template(
            'password_templates/reset_password.html',
            alert=
            "This link in no longer active. Please click the link send to your email, or ask for a new one to be resent."
        )
    if form.validate_on_submit():
        new_hash = generate_password_hash(form.new_password.data)
        user.password_hash = new_hash
        db.session.commit()
        flash('Your Password has been updated. Please Login.')
        return redirect('/login')
    return render_template('password_templates/reset_password.html',
                           code=code,
                           user=user,
                           form=form)
示例#2
0
def password_reset():
    form = ResetPassword()
    session['email'] = request.form.get('email')
    if form.validate_on_submit():
        if not User.check_form_email_validation(session['email']):
            message = 'Invalid Email Address'
            return render_template('auth/forgotten-password.html', form=form, message=message, title="Forgotten Password")

        if not User.check_email(session['email']):
            message = 'Invalid Email Address'
            return render_template('auth/forgotten-password.html', form=form, message=message, title="Forgotten Password")

        pw_reset_code = User.generate_pw_reset()
        User.updateCodeinDB(session['email'], pw_reset_code, 'password_reset_code')

        Emails(session['email']).resetPassword(pw_reset_code)

        session['password_authorisation'] = True
        
        message = 'Password reset link has been emailed. Please check your email.'
        return render_template('auth/password-email-sent.html', message=message, form=form, title="Password Reset")

    if not User.check_form_email_validation():
        message = 'Invalid Email'
        return render_template('/auth/forgotten-password.html', form=form, message=message)

    message = 'Something went wrong. Please try again later'
    return render_template('/auth/forgotten-password.html', form=form, message=message)
示例#3
0
def reset_password():
   if current_user.is_authenticated:
       return redirect(url_for('index'))
   form = ResetPassword()
   if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_email(user)
        flash('Check your email for instructions')
        return redirect(url_for('login'))
   return render_template('reset.html', title='Reset Password', form=form)
示例#4
0
    def post(self):
        form = ResetPasswordForm(request.form)

        if form.validate():
            account = form.account
            new_pass = pass_util.reset_password(account)

            email_util.reset_password_email(account.email, new_pass)
            flash("Password email sent.", "success")
            return redirect(url_for('login'))

        return self.render_template(form)
示例#5
0
def reset_password():
    form = ResetPassword()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        key = crypto.generate_key()
        user.password_reset_key = key
        db.session.commit()

        email.send_reset_password(app.config.get("PPE_HOSTNAME"), user.email,
                                  key, user.username)
        flash(
            'You should recieve an email with instructions on how to reset your password soon'
        )
        return redirect(url_for('login'))
    return render_template('reset_password.html',
                           title='Reset Password',
                           form=form)
示例#6
0
def reset_password(token):
    form = ResetPassword()
    if current_user.is_authenticated:
        return render_template('error-page.html', title='Error')
    user = User.verify_token(token)
    if user is None:
        return render_template('error-page.html', title='Error')
    if request.method == 'POST':
        if form.validate_on_submit():
            user.password = bcrypt.generate_password_hash(
                form.new_password.data).decode('utf-8')
            db.session.commit()
            return redirect(url_for('index'))
    return render_template('reset-password.html',
                           title='Reset Password',
                           form=form,
                           errors=form.errors)
示例#7
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    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.index'))
    form = ResetPassword()
    if request.method == "POST":
        if form.validate_on_submit():
            user.set_password(request.form['password'])
            db.session.commit()
            flash('Your password has been updated, you are now able to log in',
                  'success')
            return redirect(url_for('main.login'))
    return render_template("reset_password.html",
                           title='Reset Password',
                           form=form)
示例#8
0
def reset_password(hash=0):
    """
    Reset form existing of two fields, password and password_repeat.

    Checks if the hash in the url is found in the database and timestamp
    has not expired.
    """

    form = ResetPassword(request.form)

    # Request the ticket to validate the timer
    ticket = PasswordTicket.query.filter(
        db.and_(PasswordTicket.hash == hash)).first()

    # Check if the request was followed within a hour
    if ticket is None or ((datetime.now() - ticket.created_on).seconds > 3600):
        flash(_('No valid ticket found'))
        return redirect(url_for('user.request_password'))

    if form.validate_on_submit():
        user = User.query.filter(User.id == ticket.user).first()

        if not user:
            flash(_('There is something wrong with the reset link.'), 'danger')
            return redirect(url_for('user.request_password'))

        # Actually reset the password of the user
        user.password = bcrypt.hashpw(form.password.data, bcrypt.gensalt())
        login_user(user)
        db.session.add(user)
        db.session.commit()

        flash(_('Your password has been updated.'), 'success')
        return redirect(url_for('user.view_single', user_id=user.id))

    else:
        flash_form_errors(form)

    return render_template('user/reset_password.htm', form=form)
示例#9
0
def forgotten_password():
    form = ResetPassword()
    return render_template('auth/forgotten-password.html', form=form, title="Forgotten Password")