Ejemplo n.º 1
0
 async def post(self):
     phone = self.get_arg('phone')
     password = self.get_arg('password')
     user = await FundUser.async_get(phone=phone, password=password, is_delete=FundUser.DELETE_NO)
     if user:
         return self.write_success({'token': FundUser.encode_token(user)})
     return self.write_fail(Code.User.USERNAME_OR_PASSWORD_INVALID, Message.User.USERNAME_OR_PASSWORD_INVALID)
Ejemplo n.º 2
0
 async def post(self):
     phone = self.get_arg('phone')
     name = self.get_arg('name')
     password = self.get_arg('password')
     user = await FundUser.objects.get(FundUser.select().where(
         FundUser.phone == phone, FundUser.password == password))
     if user:
         return self.write_fail(Code.USER_IS_EXIST, Message.USER_IS_EXIST)
     user = await FundUser.async_create(phone=phone,
                                        name=name,
                                        password=password)
     return self.write_success(Code.SUCCESS,
                               {'token': self.token_encode(user.id)})
Ejemplo n.º 3
0
 async def post(self):
     phone = self.get_arg('phone')
     name = self.get_arg('name')
     password = self.get_arg('password')
     user = await FundUser.async_get(phone=phone,
                                     password=password,
                                     is_delete=FundUser.DELETE_NO)
     if user:
         return self.write_fail(Code.User.USER_IS_EXIST,
                                Message.User.USER_IS_EXIST)
     user = await FundUser.async_create(phone=phone,
                                        name=name,
                                        password=password)
     return self.write_success({'token': FundUser.encode_token(user)})
Ejemplo n.º 4
0
    async def wrapper(self, *args, **kwargs):

        from apps.users.user import FundUser

        res = self.request.headers.get('Authorization', ' ').split(' ')
        if len(res) < 2 or not res[1]:
            self.write_bad_request()
        token = res[1]
        data = FundUser.decode_token(token)
        if data is None:
            return self.write_fail(Code.User.TOKEN_INVALID,
                                   Message.User.TOKEN_INVALID)
        self.current_user_id = data.get('user_id')

        return await method(self, *args, **kwargs)
Ejemplo n.º 5
0
 async def post(self):
     phone = self.get_arg('phone')
     password = self.get_arg('password')
     try:
         user = await FundUser.objects.get(FundUser.select().where(
             FundUser.phone == phone, FundUser.password == password))
         if user.id:
             return self.write_success(
                 {'token': self.token_encode(user.id)})
     except Exception as e:
         self.app.logger.info(e)
         return self.write_fail(Code.USERNAME_OR_PASSWORD_INVALID,
                                Message.USERNAME_OR_PASSWORD_INVALID)
     return self.write_fail(Code.USERNAME_OR_PASSWORD_INVALID,
                            Message.USERNAME_OR_PASSWORD_INVALID)
Ejemplo n.º 6
0
    async def get(self):
        user = await FundUser.objects.get(
            FundUser.select().where(FundUser.id == self.user_id))

        return self.write_success(data=user.normal_info())