Exemple #1
0
def login(uri, request):
    principal = ptah.resolve(uri)
    info = ptah.auth_service.authenticate_principal(principal)

    if info.status:
        request.registry.notify(
            ptah.events.LoggedInEvent(principal))

        location = '%s/login-success.html'%request.application_url

        headers = security.remember(request, principal.__uri__)
        return HTTPFound(headers = headers, location = location)

    if info.arguments.get('suspended'):
        return HTTPFound(
            location='%s/login-suspended.html'%request.application_url)

    ptah.add_message(request, info.message, 'warning')
    return HTTPFound(location = '%s/login.html'%request.application_url)
Exemple #2
0
def validate(request):
    """Validate account"""
    t = request.GET.get('token')

    data = ptah.token.service.get(t)
    if data is not None:
        user = ptah.resolve(data)
        if user is not None:
            user.validated = True
            ptah.token.service.remove(t)
            ptah.add_message(request,"Account has been successfully validated.")

            request.registry.notify(ptah.events.PrincipalValidatedEvent(user))

            headers = remember(request, user.__uri__)
            return HTTPFound(location=request.application_url, headers=headers)

    ptah.add_message(request, "Can't validate email address.", 'warning')
    return HTTPFound(location=request.application_url)
Exemple #3
0
def verify(request):
    """Verify email"""
    t = request.subpath[0]

    data = ptah.token.service.get(t)
    if data is not None:
        data = json.loads(data)
        session = ptah.get_session()

        principal = ptah.resolve(data['uri'])
        principal.properties.validated = True

        entry = session.query(Storage).filter(Storage.uid==data['uid']).first()
        entry.uri = principal.__uri__
        entry.email = data['email']

        ptah.token.service.remove(t)
        ptah.add_message(request,"Email has been successfully verified.")

        headers = security.remember(request, principal.__uri__)
        return HTTPFound(location=request.application_url, headers=headers)

    ptah.add_message(request, "Can't verify email address.", 'warning')
    return HTTPFound(location=request.application_url)
def redirect(request):
    ptah.add_message(request, 'Redirect to form')
    return HTTPFound('test-form.html')