def signup():
    # Check if current user is anonymous, else send to index page
    if not current_user.is_anonymous:
        return redirect(url_for('home.index'))
    # Use the defined UserForm
    form = UserForm()
    if form.validate_on_submit():  # Add user to database if validate
        user = User(name=form.name.data, email=form.email.data,
                    password=form.password.data, picture=form.picture.data)
        db.session.add(user)
        db.session.commit()
        if app.debug:
            app.logger.debug("User {} signed up!".format(
                (user.id, user.name)))
        flash("You are now signed up. Please login to your account",
              category='success')
        return redirect(url_for('home.index'))

    return render_template('home/signup.html', action="Sign up",
                           form_action='home.signup',
                           form=form)