def userhome(): # Hardcoded till we deploy it so that we can get user ip addr ipaddr = '157.37.154.227' loc = get_coords(ipaddr) mymap = get_map(loc) if request.form.get("packets"): packets = request.form['packets'] email = session["USER"] current = db.execute("SELECT quantity FROM users WHERE email=:email", {"email": email}).fetchone() if int(packets) < 1: flash("Invalid Quantity", "danger") return redirect(url_for('userhome')) if int(packets) > 6: flash("Maximum 6 from one signup", "danger") return redirect(url_for('userhome')) if int(current.quantity) != 0: flash("You already submitted a request","danger") return redirect(url_for('userhome')) else: db.execute("UPDATE users SET quantity=:quantity WHERE email=:email", {"quantity": packets, "email": email}) db.commit() flash("Your Request has been submitted", "success") return redirect(url_for('userhome')) # ipaddr = request.environ.get('HTTP_X_REAL_IP', request.remote_addr) # loc = get_coords(ipaddr) return render_template("userhome.html", mymap= mymap)
def get_post(): content = request.get_json(silent=True) id = content["id"] coords = [] coords.append(content["lng"]) coords.append(content["lat"]) models.insert_coords(id, coords, False) json_data = calculate(id, HUB, models.get_coords()) if json_data == None: abort(400) print(json_data) return jsonify(json_data)
def ngohome(): # Hardcoded till we deploy it so that we can get user ip addr ipaddr = '157.37.154.227' loc = get_coords(ipaddr) # hardcoded can be taken by nearest requesters loc2 = [26.9363461, 75.9213346] mymap = get_map(loc) calc_dist = haversine(loc,loc2) if calc_dist<20: print("yes there is a request") return render_template("ngohome.html", mymap=mymap)
def ngoregister(): form = NGOForm(request.form) if request.method == 'POST' and form.validate(): name = form.name.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("ngoregister.html", form=form) if password == confirm: db.execute("INSERT INTO users (first_name, email, pass, usertype ,lon, lat) VALUES (:fname, :email, :password, :usertype, :lon,:lat)", { "fname": name, "email": email, "password": password, "usertype":3, "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("ngoregister.html", form=form) else: flash("Passwords do not match", "danger") return render_template("ngoregister.html",form=form) return render_template("ngoregister.html",form=form)