Example #1
0
def signup():
    """
    User Sign-Up

    GET requests serve sign-up page
    POST requests validate form & user registration
    """
    form = SignupForm()
    if form.validate_on_submit():
        # prepare new user data
        data = {}
        data["name"] = form.name.data
        data["email"] = form.email.data
        data["password"] = form.password.data
        # create new user
        # new_user =  User(
        #    name = form.name.data,
        #    email = form.email.data,
        #    password = form.password.data
        #)

        user = User.create_from_json(data)

        login_user(user)  # Log in as newly created user

        # remember login date and time
        user.last_login = "******"

        flash(u'Congratulation! You were successfully registered!', 'success')
        return redirect(url_for('views.index'))

    return render_template('auth/signup.html',
                           title='New user registration',
                           form=form)
Example #2
0
 def post(self):
     # extract new user data from request
     json_data = request.get_json()
     if not json_data:
         return {"message": "New user details were not provided."}, 400
         
     # Validate and deserialize input
     try:
         data = UserSchema().load(json_data)
     except ValidationError as err:
         return err.messages, 422
     
     # create new user
     result = User.create_from_json(json_data)
     if isinstance(result, User):
         return {"message": "New user was created.", "user": UserSchema().dump(result)}, 201
     
     return result