Exemplo n.º 1
0
    def post(self):

        data = parser.parse_args()
        current_user = UserModel.find_by_username(data['username'])

        if not current_user:
            return create_response({'message': 'User {} doesn\'t exist'
                                   .format(data['username'])}, 404)

        if UserModel.verify_hash(data['password'], current_user.password):
            access_token = create_access_token(identity=data['username'],
                                               expires_delta=False)
            return create_response({
                'message': 'Logged in as {}'.format(current_user.username),
                'access_token': access_token}, 201)
        else:
            return create_response({'message': 'Wrong credentials'}, 401)
Exemplo n.º 2
0
    def post(self):
        data = user_parser.parse_args()
        current_user = UserModel.find_by_username(data['username'])
        if not current_user:
            return {
                'message': 'User {} doesn\'t exist'.format(data['username'])
            }

        if UserModel.verify_hash(data['password'], current_user.password):
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'Logged in as {}'.format(current_user.username),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        else:
            return {'message': 'Wrong credentials'}
Exemplo n.º 3
0
 def test_hash(self):
     password = "******"
     pass_hash = UserModel.generate_hash(password)
     self.assertTrue(UserModel.verify_hash(password, pass_hash))