示例#1
0
def changepswd():
    """
    Handles the change of password for the current user
    """

    form = ChangePassForm()

    if form.validate_on_submit():
        try:
            user = current_user
            print "here"
            if user.verify_password(form.oldpass.data):
                print "pass ok"
                user.password = form.newpass.data
                print user.username.value
                print form.newpass.data
                user.save()
                flash('Parola schimbata!',category='alert-success')
                return redirect(request.args.get('next') or '/home/')
            else:
                raise Exception('Not authorised',form.email.data)

        except Exception as err:
            print err
            flash('Modificarea nu poate fi facuta!', category='alert-danger')

    return render_template('users/edit.html', pagetitle='Schimba parola', form=form)
示例#2
0
def profilepage():
    changepass_form = ChangePassForm()
    # Get old password, compare with form and change password
    if changepass_form.validate_on_submit():
        old_pass = changepass_form.oldpassword.data
        new_pass = changepass_form.newpassword.data
        changepass_form.oldpassword.data = changepass_form.newpassword.data = ""
        if old_pass == current_user.password:
            current_user.password = new_pass
            db.session.commit()
            message = 'Password successfuly changed.'
            return render_template("profilepage.html",
                                   user=current_user,
                                   changepass_form=changepass_form,
                                   message=message)
        # Error message if old password mismatches
        error = 'Old password mismatch.'
        return render_template("profilepage.html",
                               user=current_user,
                               changepass_form=changepass_form,
                               error=error)

    return render_template("profilepage.html",
                           user=current_user,
                           changepass_form=changepass_form)
示例#3
0
def userpref_page():
    '''
    Dashbaord User Preferences:
    This will allow a user to change user preferences, i.e. Password
    '''
    verify = verifyLogin(app.config['SECRET_KEY'],
                         app.config['COOKIE_TIMEOUT'], request.cookies)
    if verify:
        user = User()
        user.config = app.config
        user.get('uid', verify, g.rdb_conn)
        data = startData(user)
        data['active'] = 'dashboard'
        if user.status != "active":
            data['url'] = '/dashboard/mod-subscription'
            tmpl = 'member/mod-subscription.html'
        else:
            # Start processing the change password form
            form = ChangePassForm(request.form)
            if request.method == 'POST':
                if form.validate():
                    result = user.checkPass(form.old_password.data, g.rdb_conn)
                    if result:
                        update = user.setPass(form.password.data, g.rdb_conn)
                        if update:
                            print(
                                "/dashboard/user-preferences - Password changed"
                            )
                            flash('Password successfully changed.', 'success')
                        else:
                            print("/dashboard/user-preferences - \
                                  Password change failed")
                            flash('Password change was unsuccessful.',
                                  'danger')
                    else:
                        print(
                            "/login - User change password error: wrong old password"
                        )
                        flash('Old password does not seem valid.', 'danger')
            data['url'] = '/dashboard/user-preferences'
            tmpl = 'member/user-preferences.html'
        page = render_template(tmpl, data=data, form=form)
        return page
    else:
        flash('Please Login.', 'warning')
        return redirect(url_for('user.login_page'))
示例#4
0
def change_password():
    if 'email' not in session:
        return redirect(url_for('signin'))
    form = ChangePassForm()
    if request.method == 'POST':
        if not form.validate():
            return render_template('change_password.html', form=form)
        else:
            user = User.query.filter_by(email=session['email']).first()
            if user is None:
                return redirect(url_for('signin'))
            else:
                user.pwdhash = generate_password_hash(form.new_pass.data)
                db.session.commit()
                return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('change_password.html', form=form)
示例#5
0
def change_pass():
    form = ChangePassForm()
    error = False
    if request.method == 'POST' and form.validate():
        m = hashlib.md5()
        m.update(form.old_password.data)
        user = database.get_user(username=current_user.username,
                                 password=m.hexdigest())
        if user is not None:
            m = hashlib.md5()
            m.update(form.password.data)
            user = database.update_user(username=current_user.username,
                                        password=m.hexdigest())
            return redirect(url_for("change_pass_success"))
        error = True
    return render_template("accounts/password_change_form.html",
                           form=form,
                           error=error)
示例#6
0
def userpref_page():
    '''
    Dashbaord User Preferences:
    This will allow a user to change user preferences, i.e. Password
    '''
    verify = verifyLogin(
        app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
    if verify:
        user = User()
        user.get('uid', verify, g.rdb_conn)
        data = startData(user)
        data['active'] = 'dashboard'
        if user.status != "active":
            data['url'] = '/dashboard/mod-subscription'
            tmpl = 'member/mod-subscription.html'
        else:

            # Start processing the change password form
            form = ChangePassForm(request.form)
            if request.method == 'POST':
                if form.validate():
                    result = user.setPass(form.password.data, g.rdb_conn)
                    if result:
                        data['msg'] = "Password successfully changed"
                        print("/dashboard/user-preferences - Password changed")
                        data['error'] = False
                    else:
                        data['msg'] = "Password change was unsuccessful"
                        print("/dashboard/user-preferences - Password change failed")
                        data['error'] = True
            data['url'] = '/dashboard/user-preferences'
            tmpl = 'member/user-preferences.html'
        page = render_template(tmpl, data=data, form=form)
        return page
    else:
        return redirect(url_for('user.login_page'))