Esempio n. 1
0
        def wrapper(*args, **kws):
            print(request.headers)
            token = request.headers.get(config.token_header_key)
            print(token)
            if not token:
                return respond_err("No token", 401)

            token = token.split(config.token_header)[1]
            if not JwtUtil.verify_bearer_token(token):
                return respond_err("Invalid token", 401)
            else:
                username = JwtUtil.get_token_username(token)
                user = DaoFactory.userDao.get_user_by_username(username)

                if not user.role in roles:
                    return respond_err("Bad role", 403)
                return func(*args, **kws)
Esempio n. 2
0
 def sign_up(self, user: UserVO):
     result = self.user_dao.get_user_by_username(user.username)
     if result:
         raise AlreadyExists
     else:
         print(user.__dict__)
         self.user_dao.insert(UserConverter().toModel(user))
         token = JwtUtil.create_token(user.username)
         return token
Esempio n. 3
0
 def sign_in(self, user: UserVO):
     result: UserModel = self.user_dao.get_user_by_username(user.username)
     if not result:
         raise NotFoundException
     if result.password == user.password:
         """成功登录"""
         token = JwtUtil.create_token(user.username)
         return token, result.id
     else:
         raise PasswordWrongException
Esempio n. 4
0
 def patch(self, aID):
     try:
         username = JwtUtil.get_token_username(
             flask.request.headers.get("token"))
         activity = activity_bl.check_register(username, aID)
         return None, 200
     except NotFoundException:
         return {"error": "can not find the activity"}, 404
     except SystemErrorException:
         return {"error": "system is error"}, 500
Esempio n. 5
0
 def patch(self):
     username = JwtUtil.get_token_username(
         flask.request.headers.get("token"))
     try:
         activity_list = activity_bl.get_activity_by_user(username)
         return [DateEncoderUtil().changeDate(i) for i in activity_list]
     except NotFoundException:
         return {"error": "can not find the page"}, 404
     except SystemErrorException:
         return {"error": "system is error"}, 500
Esempio n. 6
0
 def delete(self):
     aID = request.form['aID']
     try:
         activity_bl.leave_activity(
             JwtUtil.get_token_username(flask.request.headers.get("token")),
             aID)
         return None, 200
     except NotFoundException:
         return {"error": "can not find user or activity"}, 404
     except InsertException:
         return {"error": "system is error"}, 500
     except AlreadyExists:
         return {"error": "already exists"}, 405
Esempio n. 7
0
    def get(self, code):
        try:
            username = JwtUtil.get_token_username(
                flask.request.headers.get("token"))
        except:
            return "token_error", 403
        print("here")
        try:
            return userBl.get_open_id(code, username)
        except NotFoundException:
            return None, 404


# print(requests.get("http://www.injusalon.com:5000/api/user").content)
Esempio n. 8
0
 def post(self):
     try:
         total_fee = 1
         open_id = userBl.get_open_id(code='',
                                      username=JwtUtil.get_token_username(flask.request.headers.get("token")))
         print(open_id)
         order_params = self.wechat_order.create(trade_type="JSAPI", body=config.body, total_fee=total_fee,
                                                 notify_url=config.notify_url, client_ip=config.server_ip,
                                                 user_id=open_id,
                                                 device_info="WEB")
         prepay_id = order_params["prepay_id"]
         pay_params = self.wechat_jsapi.get_jsapi_params(prepay_id)
         pay_signature = self.wechat_jsapi.get_jsapi_signature(prepay_id, timestamp=pay_params["timeStamp"],
                                                               nonce_str=pay_params["nonceStr"])
         pay_params["signature"] = pay_signature
         return pay_params, 200
     except PasswordWrongException:
         return {'error': 'wrong password'}, 403
     except NotFoundException:
         return {'error': 'user not found'}, 404