コード例 #1
0
    def get(self, token: str):
        confirmation = Confirmation.query.filter_by(id=token).first_or_404(
            description='Token not found')
        if confirmation.activated:
            return {"message": "Your account already activated."}, 200

        if not confirmation.token_is_expired:
            confirmation.activated = True
            confirmation.save_to_db()
            # set access token
            access_token = create_access_token(identity=confirmation.user.id,
                                               fresh=True)
            refresh_token = create_refresh_token(identity=confirmation.user.id)
            # encode jti token to store database redis
            access_jti = get_jti(encoded_token=access_token)
            refresh_jti = get_jti(encoded_token=refresh_token)
            # store to database redis
            revoked_store.set(access_jti, 'false', _ACCESS_EXPIRES)
            revoked_store.set(refresh_jti, 'false', _REFRESH_EXPIRES)
            return {
                "access_token": access_token,
                "refresh_token": refresh_token,
                "username": confirmation.user.username
            }, 200
        return {
            "message": "Upps token expired, you can resend email confirm again"
        }, 400
コード例 #2
0
 def post(self):
     _user_schema = UserSchema(only=(
         "email",
         "password",
     ))
     data = request.get_json()
     args = _user_schema.load(data)
     user = Users.query.filter_by(email=args['email']).first()
     if user and user.check_pass(args['password']):
         if user.confirmation.activated:
             access_token = create_access_token(identity=user.id,
                                                fresh=True)
             refresh_token = create_refresh_token(identity=user.id)
             # encode jti token to store database redis
             access_jti = get_jti(encoded_token=access_token)
             refresh_jti = get_jti(encoded_token=refresh_token)
             # store to database redis
             revoked_store.set(access_jti, 'false', _ACCESS_EXPIRES)
             revoked_store.set(refresh_jti, 'false', _REFRESH_EXPIRES)
             return {
                 "access_token": access_token,
                 "refresh_token": refresh_token,
                 "username": user.username
             }, 200
         return {"message": "Check your email to activated user."}, 400
     return {"message": "Invalid credential"}, 400
コード例 #3
0
 def delete(self):
     jti = get_raw_jwt()['jti']
     revoked_store.set(jti, 'true', _ACCESS_EXPIRES)
     return {"message": "Successfully logged out."}, 200
コード例 #4
0
 def post(self):
     user_id = get_jwt_identity()
     new_token = create_access_token(identity=user_id, fresh=False)
     access_jti = get_jti(new_token)
     revoked_store.set(access_jti, 'false', _ACCESS_EXPIRES)
     return {"access_token": new_token}, 200