def create_user(): try: data = request.get_json() if User.find_by_email( data['email']) is not None or User.find_by_username( data['username']) is not None: return response_with(resp.INVALID_INPUT_422) data['password'] = User.generate_hash(data['password']) user_schema = UserSchema() user = user_schema.load(data) token = generate_verification_token(data['email']) verification_email = url_for('user_routes.verify_email', token=token, _external=True) html = render_template_string( "<p>Welcome! Thanks for signing up. Please follow this link to activate your " "account:</p> <p><a href='{{ verification_email }}'>{{ verification_email " "}}</a></p> <br> <p>Thanks!</p>", verification_email=verification_email) subject = "Please Verify your email" send_email(user.email, subject, html) result = user_schema.dump(user.create()) return response_with(resp.SUCCESS_201, value={'author': result}) except Exception as e: print(e) return response_with(resp.INVALID_INPUT_422)
def create_user(): try: data = request.get_json() if (User.find_by_email(data["email"]) is not None or User.find_by_username(data["username"]) is not None): return response_with(resp.INVALID_INPUT_422) data["password"] = User.generate_hash(data["password"]) user_schema = UserSchema() user = user_schema.load(data) token = generate_verification_token(data["email"]) verification_email = url_for("user_routes.verify_email", token=token, _external=True) html = render_template_string( "<p>Welcome! Thanks for signing up. Please follow this link to activate your account:</p> <p><a href='{{ verification_email }}'>{{ verification_email }}</a></p> <br> <p>Thanks!</p>", verification_email=verification_email, ) subject = "Please verify your email." send_email(to=user.email, subject=subject, template=html) result = user_schema.dump(user.create()) return response_with(resp.SUCCESS_201, value={"user": result}) except IntegrityError: return response_with(resp.INVALID_INPUT_422, message="User already registered.") except Exception as e: print(e) return response_with(resp.INVALID_INPUT_422)
def sendEmailToken(email): token = generate_verification_token(email) verification_email = url_for('user_routes.verify_email', token=token, _external=True) print(token) print(verification_email) html = render_template_string( "<p>Welcome! Thanks for signing up. Please follow this link to activate youraccount:</p> <p><a href='{{ verification_email }}'>{{verification_email }}</a></p> <br> <p>Thanks!</p>", verification_email=verification_email) subject = "Please Verify your email" send_email(email, subject, html)
def create_user(): """ Create user endpoint -- parameters: - in: body name: body schema: id: UserSignup required: - username - password - email properties: username: type: string description: Unique username of the user default: "Johndoe" password: type: string description: Password of the user default: "somethingstrong" email: type: string description: email of the user default: "*****@*****.**" responses: 201: description: User successfully created schema: id: UserSignUpSchema properties: code: type: string 422: description: Invalid input arguments schema: id: invalidInput properties: code: type: string message: type: string """ try: data = request.get_json() if (User.find_by_email(data['email']) is not None or User.find_by_username(data['username']) is not None): return response_with(resp.INVALID_INPUT_422) data['password'] = User.generate_hash(data['password']) user_schema = UserSchema() user = user_schema.load(data) token = generate_verification_token(data['email']) verification_email = url_for('user_routes.verify_email', token=token, _external=True) html = render_template_string( "<p>Welcome! Thanks for signing up. Please follow this link to activate your account:</p> <p><a href='{{ verification_email }}'>{{ verification_email }}</a></p> <br> <p>Thanks!</p>", verification_email=verification_email) subject = "Please Verify your email" print("::: Sending email to: ", user.email, " :subject: ", subject, " :html: ", html) send_email(user.email, subject, html) result = user_schema.dump(user.create()) return response_with(resp.SUCCESS_201) except Exception as e: print(e) return response_with(resp.INVALID_INPUT_422)
def send_activate_user(email, public_id): html = render_template("register.html", public_id=public_id) subject = "Bienvenid@" send_email(email, subject, html)