def user_modify(userid): if not session.get('logged_in'): return redirect('/') User.query.all() user = User.query.filter_by(id=userid).first() if user is not None: if request.method == "GET": form = ModifyForm() if user.user_name == session['user_name']: form = ModifyForm() form.firstname.data = user.user_firstname form.lastname.data = user.user_lastname form.signature.data = user.user_signature return render_template('forms/modify.html', form=form) else: return '403 Permission Denied', 403 elif request.method == "POST": User.query.all() user = User.query.filter_by(id=userid).first() # Only update if we are the account owner if session['user_name'] == user.user_name: req_data = request.form['firstname'] firstname = request.form['firstname'] lastname = request.form['lastname'] signature = request.form['signature'] # Update the User user.update_user(firstname, lastname, signature) flash('You successfully updated your information!') return redirect('/user') else: return redirect('/')
def users_data(userid): if not session.get('logged_in'): return redirect('/') name = session['user_name'] form = ModifyForm(request.form) firstname = None lastname = None signature = None creds = {} if request.method == "GET": User.query.all() user = User.query.filter_by(id=userid).first() if user is not None: if user.user_name == name: username = user.user_name mailbox = user.user_mailbox signature = user.user_signature firstname = user.user_firstname lastname = user.user_lastname creds.update({'User Name':username}) creds.update({'Mailbox':mailbox}) creds.update({'First Name':firstname}) creds.update({'Last Name':lastname}) creds.update({'Signature':signature}) form.firstname.data = firstname form.lastname.data = lastname return render_template('lists/view.html', list=creds)
def users(): if not session.get('logged_in'): return redirect('/') form = ModifyForm() User.query.all() user = User.query.filter_by(user_name=session['user_name']).first() if user is not None: form.firstname.data = user.user_firstname form.lastname.data = user.user_lastname form.signature.data = user.user_signature return render_template('pages/users.html', form=form)