def register(): """ Validates the request body and tries to register the user """ body = validate( { "username": field("string", maxlength=180, required=True, empty=False, nullable=False), "email": field("email"), "password": field("password"), "tos": field("tos") }, request.get_json(force=True, silent=True)) if not body["tos"]: raise CustomError( message="Servis kosullarini kabul etmeniz gerekmektedir", status_code=400) user = User(body) user.registration_ip = request.access_route user_register(user) return "User successfully registered."
def forgot_password(): """ Validates the request body and tries to send a password reset mail to the user """ body = validate({"email": field("email")}, request.get_json(force=True, silent=True)) user_forgot_password(body["email"]) return "Password reset email sent"
def resend_verification_email(): """ Resends the verification email """ body = validate({"email": field("email")}, request.get_json(force=True, silent=True)) user_resend_verification_email(body["email"]) return "Resent Verification Email"
def login(): """ Validates the request body and tries to log the user in and returns jwt """ body = validate({ "email": field("email"), "password": field("password") }, request.get_json(force=True, silent=True)) token = user_login(body["email"], body["password"], request.access_route) return jsonify({"token": token})
def reset_password(): """ Validates fields sent on form and updates the password of user after successful jwt authentication """ body = validate({"password": field("password")}, request.get_json(force=True, silent=True)) token = request.headers.get("AUTHORIZATION") Http.auth(token) user_reset_password(g.user["email"], body["password"]) return "Password reset"
def update_user(user_id: int): token = request.headers.get("AUTHORIZATION") Http.auth(token, ["ROLE_ADMIN"]) body = validate( { "enabled": field("integer", required=False, nullable=False, empty=False), "email_verified": field("integer", required=False, nullable=False, empty=False), "roles": field("list", required=False, nullable=False, empty=False) }, request.get_json(force=True, silent=True)) user_update_user(body, user_id) return "ok"
def register(): """ Validates the request body and tries to register the user """ body = validate( { "fullname": field("string", maxlength=100), "email": field("email"), "password": field("password"), "tos": field("tos") }, request.get_json(force=True, silent=True)) if not body["tos"]: raise CustomError(message="ToS is not accepted.", status_code=400) user = User(body) user.registration_ip = request.access_route user_register(user) return "User successfully registered."