def post(self): ''' Create a new user ''' args = user_parser.parse_args() if UserModel.find_by_email(args['email']): return {"message": "Email is already registered."}, 400 new_user = UserModel(fname=args['fname'], lname=args['lname'], username=args['username'], email=args['email']) new_user.set_password(args['password']) new_user.save_to_db() result = api_ns.marshal(new_user, user_model) return result, http.client.CREATED
def post(self): ''' Login and return a valid Authorization header ''' args = login_parser.parse_args() user = UserModel.find_by_email(args['email']) if user and user.check_password(args['password']): # Generate the header payload = { 'userid': user.id, 'username': user.username, 'email': user.email } header = generate_token_header(payload, config.PRIVATE_KEY) return {'Authorized': header}, http.client.OK return { "message": "Invalid email or password" }, http.client.UNAUTHORIZED