Exemplo n.º 1
0
    def post(self):
        data = parser.parse_args()
        if User.query.filter_by(username=data['username']).scalar():
            response = jsonify({
                'message':
                'The user {} already exists.'.format(data['username'])
            })
            response.status_code = 409
            return response

        new_user = User(username=data['username'],
                        password=User.generate_hash(data['password']))

        new_user.save()

        access_token = create_access_token(identity=data['username'])
        refresh_token = create_refresh_token(identity=data['username'])

        return {
            'message': 'User {} was created.'.format(data['username']),
            'access_token': access_token,
            'refresh_token': refresh_token
        }
Exemplo n.º 2
0
def test_staticmethod_verify_hash(init_db, new_user):
    user_hash = User.generate_hash(new_user.password)

    assert User.verify_hash(new_user.password, user_hash)