Beispiel #1
0
def default_options_view(resource, request, methods=None):
    """Default OPTIONS view for resources."""
    response = HTTPNoContent()
    if methods is None:
        state = RestState.from_resource(resource)
        methods = state.supported_methods()
    response.headers['Access-Control-Allow-Methods'] = ', '.join(methods)
    return response
Beispiel #2
0
    def activate_by_email(self,
                          activation_code: str,
                          location: str = None) -> Response:
        """Active a user after user after the activation email.

            * User clicks link in the activation email
            * User enters the activation code on the form by hand

        :param activation_code: Activation code for user account.
        :param location: URL to redirect the user to, after activation.
        :raise: HTTPNotFound is activation_code is invalid.
        :return: Redirect to location.
        """
        request = self.request
        settings = request.registry.settings
        user_registry = UserRegistry(request)

        login_after_activation = asbool(
            settings.get('tm.registry.login_after_activation', False))

        user = user_registry.activate_user_by_email_token(activation_code)
        if not user:
            raise HTTPNotFound("Activation code not found",
                               json={'message': 'Activation code not found.'})

        if login_after_activation:
            login_service = LoginService(self.request)
            return login_service.authenticate_user(user, login_source="email")
        else:
            self.request.registry.notify(
                RegistrationActivatedEvent(self.request, user, None))
            return HTTPNoContent(json=None)
Beispiel #3
0
    def delete(self):
        """Remove the identity"""

        self.request.identity_provider.delete(self.request.identity)
        headers = forget(self.request)
        self.request.response.headers.extend(headers)
        return HTTPNoContent()
Beispiel #4
0
 def get(self):
     """Return user settings."""
     objects = ObjectSettings.list_db(self.user)
     settings = [x.marshall_dict() for x in objects]
     if settings:
         return settings[0]
     raise HTTPNoContent()
Beispiel #5
0
def create(context, request):

    svc = request.find_service(name='annotation_moderation')
    svc.hide(context.annotation)

    event = events.AnnotationEvent(request, context.annotation.id, 'update')
    request.notify_after_commit(event)

    return HTTPNoContent()
Beispiel #6
0
def set_key(request):
    """Update the value of a key.

    You must have a valid session and be authenticated as the target user.
    """
    appid = request.matchdict["appid"].encode("utf8")
    userid = request.matchdict["userid"].encode("utf8")
    key = request.matchdict["key"].encode("utf8")
    store = request.registry.getUtility(ISauropodBackend)
    value = request.POST.get("value")
    if value is None:
        raise HTTPBadRequest("mising value")
    if_match = _get_if_match(request)
    try:
        item = store.set(appid, userid, key, value, if_match=if_match)
    except ConflictError:
        raise HTTPPreconditionFailed()
    r = HTTPNoContent()
    if item.etag:
        r.headers["ETag"] = item.etag
    return r
Beispiel #7
0
 def view(context, request):
     response = HTTPNoContent()
     response.headers['Access-Control-Allow-Methods'] =\
         ', '.join(supported_methods)
     return response