Beispiel #1
0
def public_index(request):
    """
    Default route for non authenticated request.

    If request is authenticated, redirect to index.
    Redirect to signin page otherwise.
    """

    if is_user_authenticated(request):
        return redirect(request, 'app.index', optional='');

    return redirect(request, 'user.signin');
Beispiel #2
0
    def handle_signin(self):
        """Validate the user request"""

        # Validate request
        authentication = validate(self.username, self.password)

        # Handle successful request
        if authentication.success is True:
            authenticate_user(self.request, authentication.user)
            return redirect(self.request, 'user.redirect_after_signin')

        # Handle error request
        self.request.status_int = 400
        return {'username': self.username, 'errors': authentication.errors}
Beispiel #3
0
def authenticated_index_html(request):
    """
    Application Route Index served as HTML.

    Ask authenticated_index to do the job.
    Redirect to signin in case user is unauthenticated.
    """

    try:
        return authenticated_index(request)

    except AuthenticationError, e:
        # Send the user on signin page.
        return redirect(request, 'user.signin')
Beispiel #4
0
    def handle_signin(self):
        """Validate the user request"""

        # Validate request
        authentication = validate(self.username, self.password)

        # Handle successful request
        if authentication.success is True:
            authenticate_user(self.request, authentication.user)
            return redirect(self.request, 'user.redirect_after_signin')

        # Handle error request
        self.request.status_int = 400
        return {
                'username':  self.username,
                'errors': authentication.errors
            }
Beispiel #5
0
    def handle_signup(self):
        # Validate request
        username = sanitize_username(self.request)
        email = sanitize_email(self.request)
        password = sanitize_password(self.request)
        password_repeat = sanitize_password(self.request, 'password_repeat')
        creation = validate_signup_params( username=username,
                                           email=email,
                                           password=password,
                                           password_repeat=password_repeat)

        # Handle successful request
        if creation.success is True:
            authenticate_user(self.request, creation.user)
            return redirect(self.request, 'user.redirect_after_signup')

        # Handle error request
        self.request.status_int = 400
        return {
                'username': username,
                'errors': creation.errors
            }
Beispiel #6
0
def signout(self, request):
    # clear current user session
    unauthenticate_user(request)
    request.session.flash(messages['successfully_signed_out'], queue='info')
    return redirect(request, 'user.redirect_after_signout')
Beispiel #7
0
def signout(self, request):
    # clear current user session
    unauthenticate_user(request)
    request.session.flash(messages['successfully_signed_out'], queue='info')
    return redirect(request, 'user.redirect_after_signout')