def edit(username): account = Account.find_account(username) generated_password = generate_random_password() form = AccountForm(obj=account) form.role.default = account.role form.process() if form.validate_on_submit(): form.populate_obj(account) db.session.commit() flash(f'Account updated for { account.username }', 'success') else: flash('Account not modified', 'danger') print('==================== ERRORS: edit() ================') for err in form.errors: print(err) return render_template('pages/write_account.html', form=form, account=account, generated_password=generated_password) return redirect(url_for('it.accounts_page'))
def profile(): form = AccountForm(obj=current_user) if form.validate_on_submit(): form.populate_obj(current_user) current_user.save() return(redirect(url_for('main.profile'))) return render_template('/pages/profile.html', form=form)
def signup(): if(current_user.is_authenticated and current_user.is_active): return redirect(url_for('main.home')) form = AccountForm(request.form) if form.validate_on_submit(): account = Account() form.populate_obj(account) account.password = password_encrypt(account.password) account.save() if login_user(account) and account.is_active(): account.update_activity_tracking(request.remote_addr) return redirect(url_for('main.home')) return render_template('/pages/signup.html', form=form)
def register(): form = AccountForm() # Set required fields form.password.validators.append(DataRequired()) form.confirm_pass.validators.append(DataRequired()) if form.validate_on_submit(): account = Account() form.populate_obj(account) db.session.add(account) db.session.commit() flash(f'Account for { account.username } created successfully', 'success') else: flash('Account not created', 'danger') print('==================== ERRORS: register() ================') for err in form.errors: print(err) return render_template('pages/write_account.html', form=form) return redirect(url_for('it.accounts_page'))