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 = '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 = 'user-preferences.html' page = render_template(tmpl, data=data, form=form) return page else: return redirect(url_for('login_page'))
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)
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'))
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)
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)
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'))
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'))