def login(): """Allows the user to login to the application using the GUI""" form, error = LoginForm(), False _is_next_in_url() if UserSession.get_login_token(): return _redirect_user_to_blog_creation_page() elif form.validate_on_submit(): user = User.get_account_by_username(username=form.username.data) if user: email_status = user.get_email_confirmed_status() if email_status == 'EMAIL_CONFIRMED': if user.is_login_valid(password=form.password.data): user.login() return _redirect_user_to_url_in_next_if_found_or_to_blog_creation_page( ) error = _display_error_msg() else: error = _display_error_msg(email_status) else: error = _display_error_msg() return render_template("login/login.html", form=form, error=error)
def confirm_registration(username, code): """""" user = User.get_account_by_username(username) if user and user.is_registration_code_valid(code): user.register() return redirect(url_for('registration_app.confirmed_email_page')) abort(404)
def validate_username(form, field): """""" username = form.username.data if not _match.search(username): raise ValidationError("Invalid username format!") if User.get_account_by_username(username): raise ValidationError('The username is already in use')
def forgotten_password(): form = ResetForgottenPassword() if UserSession.get_login_token(): return redirect(url_for("blogs_app.blog")) elif form.validate_on_submit(): user = User.get_account_by_email(form.email.data) if user: user.send_forgotten_password_code() return redirect(url_for('password_app.reset_password_msg')) return render_template('password/forgotten_password.html', form=form)
def register_user(): """Register user to the application from the GUI register page""" form, error = RegistrationForm(), False if UserSession.get_login_token(): return redirect(url_for("blogs_app.my_blog")) elif form.validate_on_submit(): user = User.extract_web_form(form) user.send_registration_code() return redirect(url_for('registration_app.confirm_email_page')) return render_template('registrations/register.html', form=form, error=error)
def reset_password(username, code): """Allows the user to reset their previous password""" form = ForgottenPasswordForm() user = User.get_account_by_username(username) if not user and not user.is_forgotten_password_code_valid(code): assert user or abort(404) elif form.validate_on_submit(): user.reset_forgotten_password(new_password=form.new_passwd.data) return redirect(url_for('password_app.password_changed')) return render_template('/password/reset_password.html', form=form, username=username, code=code)
def validate_email(form, field): """""" if User.get_account_by_email(form.email.data): raise ValidationError('The email is already in use')
def get_profile_id(self): """""" user = User.get_account_by_username(UserSession.get_username()) self.profile_id = user.profile_id