Exemple #1
0
 def success_response(self):
     """
     Return the result to send on successfull authentication
     """
     if self.request.is_xhr:
         result = Apiv1Resp(self.request)
     else:
         result = HTTPFound(
             location=self.get_next_page(),
             headers=self.request.response.headers,
         )
     return result
Exemple #2
0
def api_login_get_view(request):
    """
    View used to check if the user is authenticated

    :returns:
        A json dict :
            user should login :
                {'status': 'error', 'datas': {'login_form': <html string>}}
            user is logged in:
                {'status': 'success', 'datas': {}}
    """
    login = authenticated_userid(request)

    if login is not None:
        result = Apiv1Resp(request)
    else:
        login_form = _get_login_form(request, use_ajax=True)
        form = login_form.render()
        result = Apiv1Error(request, datas={'login_form': form})
    return result
Exemple #3
0
 def redirect(self):
     return Apiv1Resp(self.request,
                      {'signed_status': self.context.signed_status})
Exemple #4
0
 def redirect(self):
     return Apiv1Resp(self.request, {'justified': self.context.justified})
Exemple #5
0
        success : {'status':'success'}
        error : {'status':'error', 'errors':{'field':'error message'}}
    """
    schema = get_json_auth_schema()
    appstruct = request.json_body
    log.info(u"Authenticating : '{0}'".format(appstruct.get('login')))
    try:
        appstruct = schema.deserialize(appstruct)
    except colander.Invalid, err:
        log.exception("  - Erreur")
        raise RestError(err.asdict(), 400)
    else:
        login = appstruct['login']
        log.info(u" + '{0}' has been authenticated".format(login))
        remember(request, login)
    return Apiv1Resp(request)


def _get_login_form(request, use_ajax=False):
    """
    Return the login form object

    :param obj request: The pyramid request object
    :param bool use_ajax: Is this form called through xhr (should it be an ajax
        form) ?
    """
    if use_ajax:
        action = request.route_path('login')
        ajax_options = """{
            'dataType': 'json',
            'success': ajaxAuthCallback