def post(self): json_data = request.get_json() username = json_data.get('username') email = json_data.get('email') non_hash_password = json_data.get('password') if User.get_by_username(username): return {'message': 'username already'}, HTTPStatus.BAD_REQUEST if User.get_by_email(email): return {'message': 'email already exists'}, HTTPStatus.BAD_REQUEST password = hash_password(non_hash_password) user = User(username=username, email=email, password=password) user.save() data = { 'id': user.id, 'username': user.username, 'email': user.email } return data, HTTPStatus.CREATED
def post(self): json_data = request.get_json() email = json - data.get('email') password = json_data.get('password') user = User.get_by_email(email=email) if not user or not check_password(password, user.password): return { 'message': 'email or password is incorrect' }, HTTPStatus.UNAUTHORIZED access_token = create_access_token(identity=user.id) return {'access_token': access_token}, HTTPStatus.OK