コード例 #1
0
ファイル: views.py プロジェクト: EgbieAndersonUku1/myBlog
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)
コード例 #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)
コード例 #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')
コード例 #4
0
ファイル: views.py プロジェクト: EgbieAndersonUku1/myBlog
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)
コード例 #5
0
 def get_profile_id(self):
     """"""
     user = User.get_account_by_username(UserSession.get_username())
     self.profile_id = user.profile_id