def edit(id): user = AuthController().find_by_id(id) print(user) if request.method == 'POST': email = request.form.get( 'email' ) first_name = request.form.get('first_name') last_name = request.form.get('last_name') middle_name = request.form.get('middle_name') birth_date = request.form.get('birth_date') role = request.form.get('role') modified = datetime.now().strftime('%Y-%m-%d %H:%M:%S') fields_list = [email, first_name, last_name, middle_name, birth_date, role, modified] try: AuthController().edit(fields_list, id) return redirect(url_for('auth.show_all')) except Exception as ex: flash(ex) groups = GroupsController().all() return render_template('edit_user.html', user=user, groups=groups)
def login(): if request.method == 'POST': email = request.form.get('email').strip() password = request.form.get('password').strip() try: if AuthController().login(email, password): return redirect(url_for('dashboard.Dashboard')) else: raise Exception(f"`{email}` user not found !") except Exception as ex: flash(str(ex)) return render_template('login.html')
def add(): if request.method == "POST": first_name = request.form.get('first_name').strip().strip('\n') last_name = request.form.get('last_name').strip().strip('\n') email = request.form.get('email').strip().strip('\n') role = request.form.get('role').strip().strip('\n') fields = [first_name, last_name, email, role] try: print(fields) AuthController().new(fields) except Exception as ex: flash(ex) return render_template("create_user.html")
def reset_password(token=None, id=None): if request.method == "POST": password = request.form.get('password').strip().strip('\n') rep_password = request.form.get('repeat_password').strip().strip('\n') try: if len(password) == 0: raise Exception('Password required') if len(rep_password) == 0: raise Exception('Repeat password required') if password == rep_password: print("ch_pas") AuthController().change_password(id, password) return redirect(url_for('auth.login')) else: raise Exception('The password does not match. Please try again.') except Exception as ex: flash(ex) return render_template('reset_password.html')
def sign_up(token): if AuthController().check_token(token) != 0: id = AuthController().check_token(token) return redirect(url_for('auth.reset_password', token=token, id=id)) else: flash("token is incorrect")
def delete(id): AuthController().delete(id) return redirect(url_for('auth.show_all'))
def show_all(): all = AuthController().get_all() return render_template('users_table.html', users=all)