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 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 get_profile_id(self): """""" user = User.get_account_by_username(UserSession.get_username()) self.profile_id = user.profile_id