def login(): data = request.get_json() id = user.validate_user(data, password=True) if id: login_user(User(id)) return "", 200 else: return "", 401
def login(): data = request.get_json() id = user.validate_user(data, password=True) if id: login_user(User(id)) return jsonify({"state": user.get_state(id)}) else: return "", 401
def post(self): """Create a user""" # Validate request body with schema model user = validate_user(request.json, create=True) code, result = self.from_dict(user) if code != 200: abort(code, result) return User(**filter_user_response(result)), 201, {'Location': request.path + '/' + str(result['id'])}
def put(self, user_id): """Update a user""" # Validate request body with schema model user = validate_user(request.json, update=True) code, result = self.put_from_dict(user_id, user) if code != 200: abort(code, result) # Retrieve updated user with all public properties return self.get(user_id)
def update_password(): data = request.get_json() user_info = { "userName": current_user.name, "password": data["oldPassword"], } if user.validate_user(user_info, password=True): user.update_password(current_user.id, data["newPassword"]) return "", 200 else: return "", 401
def forget_password(): data = request.get_json() id = user.validate_user(data, email=True) if id: s = TimedJSONWebSignatureSerializer(SECRET_KEY, expires_in=3600) token = s.dumps({"reset_id": str(id)}) send_email.send_forget_password_email( data["email"], "https://loveat2.appspot.com/user/password/reset/{token}".format( token=token.decode()), ) return "", 200 else: return "", 401
def validate(): #info = request.values.to_dict() info = request.get_json() #email = request.values.get("user_id") #password = request.values.get("password") cur_user = user.validate_user(info['user_id'], info['password']) remember = True if request.values.get("rememberMe", "n") == "y" else False if cur_user is None: return "帳密錯誤" login_user(cur_user, remember=remember) if current_user.role == 'teacher': #return redirect('teacher') return jsonify({'role':'teacher'}) elif current_user.role == 'student': return jsonify({'role':'student'}) return jsonify({'role':'boss'})