def hello_world(): form = UserForm(request.form) if form.validate(): user = { "username": form.username.data, "email": form.email.data, "password": form.password.data, "confirm": form.confirm.data, "is_vip": form.is_vip.data } return generate_response(ResponseStatus.StatusCode.SUCCESS.value, ResponseStatus.StatusMessage.SUCCESS.value, user) else: return generate_response( ResponseStatus.StatusCode.ARGS_VALIDATE_ERROR.value, ResponseStatus.StatusMessage.ARGS_VALIDATE_ERROR.value, [])
def register(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): fname = form.fname.data lname = form.lname.data email = form.email.data password = form.password.data confirm = form.confirm_password.data # ipaddr = request.environ.get('HTTP_X_REAL_IP', request.remote_addr) # loc = get_coords(ipaddr) ipaddr = '157.37.154.227' # hard coded till we deploy it loc = get_coords(ipaddr) lat, lon = loc[0], loc[1] emaildata = db.execute("SELECT email FROM users WHERE email=:email", {"email": email}).fetchone() if emaildata is not None: flash("Email taken", "danger") return render_template("userregister.html", form=form) if password == confirm: db.execute("INSERT INTO users (first_name, last_name, email, pass,lon, lat) VALUES (:fname, :lname, :email, :password, :lon,:lan)", { "fname": fname, "lname": lname, "email": email, "password": password, "lon":lon, "lat":lat}) db.commit() email = request.form['email'] token = s.dumps(email, salt='email-confirm') msg = Message('Confirm Email', sender='*****@*****.**', recipients=[email]) link = url_for('confirm_email', token=token, _external=True) msg.body = link mail.send(msg) flash("A confirmation email has been sent. Please confirm your email.", "success") return render_template("userregister.html", form=form) else: flash("Passwords do not match", "danger") return render_template("userregister.html",form=form) return render_template("userregister.html",form=form)