Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
 def validate_email(form, field):
     """"""
     if User.get_account_by_email(form.email.data):
         raise ValidationError('The email is already in use')
Exemplo n.º 8
0
 def get_profile_id(self):
     """"""
     user = User.get_account_by_username(UserSession.get_username())
     self.profile_id = user.profile_id