コード例 #1
0
ファイル: auth_mixin.py プロジェクト: ktsstudio/tornkts
    def get_current_user(self):
        if self.session_get('is_auth', False):
            user_id = self.session_get('user_id', '*')

            user = None
            for auth_cls in self.auth_classes:
                user = get_object_or_none(auth_cls, pk=user_id)
                if user is not None: break

            if user is None:
                return False

            return user
        else:
            return False
コード例 #2
0
    def get_current_user(self):
        if self.session_get('is_auth', False):
            user_id = self.session_get('user_id', '*')

            user = None
            for auth_cls in self.auth_classes:
                user = get_object_or_none(auth_cls, pk=user_id)
                if user is not None: break

            if user is None:
                return False

            return user
        else:
            return False
コード例 #3
0
ファイル: object_handler.py プロジェクト: minisin/tornkts
 def get_object(self):
     id = self.get_str_argument('id', default=None)
     if id is None:
         limit = self.get_int_argument('limit', default=20)
         offset = self.get_int_argument('offset', default=0)
         objects = self.queryset.skip(offset).limit(limit)
         objects = [object.to_dict() for object in objects]
         count = self.MODEL_CLS.objects.count()
     else:
         single_object = get_object_or_none(self.MODEL_CLS, id=id)
         if single_object is None:
             raise ServerError(ServerError.NOT_FOUND)
         else:
             count = 1
             objects = [single_object.to_dict()]
     response = {"items": objects, "count": count}
     self.send_success_response(data=response)
コード例 #4
0
    def auth(self):
        email = self.get_argument('email')
        password = self.get_argument('password')

        admin = None
        for auth_cls in self.auth_classes:
            role = [auth_cls.role]
            admin = get_object_or_none(auth_cls, email=email)
            if admin is not None: break

        if admin is None:
            raise ServerError(ServerError.INVALID_CREDENTIALS)

        if self.current_user and self.current_user.role in role:
            raise ServerError(ServerError.AUTH_NOT_REQUIRED)

        if not PasswordHelper.verify_hash(password, admin.password):
            raise ServerError(ServerError.INVALID_CREDENTIALS)

        self.session_set('user_id', admin.get_id())
        self.session_set('is_auth', True)

        self.send_success_response()
コード例 #5
0
ファイル: auth_mixin.py プロジェクト: ktsstudio/tornkts
    def auth(self):
        email = self.get_argument('email')
        password = self.get_argument('password')

        admin = None
        for auth_cls in self.auth_classes:
            role = [auth_cls.role]
            admin = get_object_or_none(auth_cls, email=email)
            if admin is not None: break

        if admin is None:
            raise ServerError(ServerError.INVALID_CREDENTIALS)

        if self.current_user and self.current_user.role in role:
            raise ServerError(ServerError.AUTH_NOT_REQUIRED)

        if not PasswordHelper.verify_hash(password, admin.password):
            raise ServerError(ServerError.INVALID_CREDENTIALS)

        self.session_set('user_id', admin.get_id())
        self.session_set('is_auth', True)

        self.send_success_response()
コード例 #6
0
ファイル: object_handler.py プロジェクト: minisin/tornkts
 def save_object(self):
     id = self.get_str_argument("id", default=None)
     if id:
         updated_object = get_object_or_none(self.MODEL_CLS, id=id)
         return self.put_object(updated_object=updated_object)
     return self.put_object()
コード例 #7
0
ファイル: object_handler.py プロジェクト: minisin/tornkts
 def delete_object(self):
     id = self.get_str_argument("id")
     single_object = get_object_or_none(self.MODEL_CLS, id=id)
     if single_object is None:
         raise ServerError(ServerError.NOT_FOUND)
     self.delete_logic(single_object)