Beispiel #1
0
    def reset(self, request):
        """Get reset form and handle rest password
        """
        key = request.urlargs['key']

        if request.method == 'GET':
            form = get_form_layout(request, 'reset-password')
            if not form:
                raise Http404
            request.api.passwords.head(key, jwt=True)
            html = form(request).as_form(action=request.full_path(),
                                         enctype='multipart/form-data',
                                         method='post')
            return self.html_response(request, html)

        else:
            form = _auth_form(request, 'reset-password')
            if form.is_valid():
                try:
                    result = request.api.passwords.post(
                        key,
                        json=form.cleaned_data,
                        jwt=True
                    ).json()
                except Exception as exc:
                    result = form_http_exception(form, exc)
            else:
                result = form.tojson()
            return self.json_response(request, result)
Beispiel #2
0
    def reset(self, request):
        """Get reset form and handle rest password
        """
        key = request.urlargs['key']

        if request.method == 'GET':
            form = get_form_layout(request, 'reset-password')
            if not form:
                raise Http404
            request.api.passwords.head(key, jwt=True)
            html = form(request).as_form(action=request.full_path(),
                                         enctype='multipart/form-data',
                                         method='post')
            return self.html_response(request, html)

        else:
            form = _auth_form(request, 'reset-password')
            if form.is_valid():
                try:
                    result = request.api.passwords.post(key,
                                                        json=form.cleaned_data,
                                                        jwt=True).json()
                except Exception as exc:
                    result = form_http_exception(form, exc)
            else:
                result = form.tojson()
            return self.json_response(request, result)
Beispiel #3
0
 def post(self, request):
     form = _auth_form(request, 'password-recovery')
     if form.is_valid():
         try:
             result = request.api.passwords.post(json=form.cleaned_data,
                                                 jwt=True).json()
         except Exception as exc:
             result = form_http_exception(form, exc)
     else:
         result = form.tojson()
     return self.json_response(request, result)
Beispiel #4
0
 def post(self, request):
     form = _auth_form(request, 'password-recovery')
     if form.is_valid():
         try:
             result = request.api.passwords.post(
                 json=form.cleaned_data,
                 jwt=True
             ).json()
         except Exception as exc:
             result = form_http_exception(form, exc)
     else:
         result = form.tojson()
     return self.json_response(request, result)
Beispiel #5
0
 def post(self, request):
     form = _auth_form(request, 'signup')
     if form.is_valid():
         try:
             result = request.api.registrations.post(json=form.cleaned_data,
                                                     jwt=True).json()
             result = {'email': result['user']['email']}
             request.response.status_code = 201
         except Exception as exc:
             result = form_http_exception(form, exc)
     else:
         result = form.tojson()
     return self.json_response(request, result)
Beispiel #6
0
    def post(self, request):
        form = _auth_form(request, 'login')

        if form.is_valid():
            auth_backend = request.cache.auth_backend
            try:
                auth_backend.login(request, **form.cleaned_data)
                result = {'success': True}
            except Exception as exc:
                result = form_http_exception(form, exc)
        else:
            result = form.tojson()

        return self.json_response(request, result)
Beispiel #7
0
    def post(self, request):
        form = _auth_form(request, 'login')

        if form.is_valid():
            auth_backend = request.cache.auth_backend
            try:
                auth_backend.login(request, **form.cleaned_data)
                result = {'success': True}
            except Exception as exc:
                result = form_http_exception(form, exc)
        else:
            result = form.tojson()

        return self.json_response(request, result)
Beispiel #8
0
 def post(self, request):
     form = _auth_form(request, 'signup')
     if form.is_valid():
         try:
             result = request.api.registrations.post(
                 json=form.cleaned_data,
                 jwt=True
             ).json()
             result = {'email': result['user']['email']}
             request.response.status_code = 201
         except Exception as exc:
             result = form_http_exception(form, exc)
     else:
         result = form.tojson()
     return self.json_response(request, result)