def register(): if 'username' in session: return redirect(url_for('home')) else: message = "" if request.method=="GET": return render_template("register.html", message = message) else: if request.form['b']=="Register": username = request.form["regusername"] password = request.form["regpassword"] password2 = request.form["regpassword2"] if mongo.user_exists(username) == "exists": message = "Someone already has this username. Please use a different one." return render_template("register.html", message = message) else: if password == password2: mongo.add_user(username, password) session['username']=username return redirect(url_for('signup')) else: message = "Please make sure your passwords match." return render_template("register.html", message = message) if request.form['b']=="Cancel": return redirect(url_for('index'))
def register_amazon_redirect(): data = { 'code': request.args.get('code', None), 'scope': request.args.get('scope', None) } token_data = generate_token(data.get('code')) profile = get_profile_info(token_data.get('access_token')) user = { 'access_token': token_data.get('access_token'), 'refresh_token': token_data.get('refresh_token'), 'token_created_date': datetime.now(), 'token_expiry_date': datetime.now() + timedelta(seconds=token_data['expires_in']), 'email': profile.get('email'), 'name': profile.get('name'), 'user_id': profile.get('user_id') } add_user(user) return render_template('auth_redirect.html')
def register(): if 'username' in session: return redirect(url_for('home')) else: message = "" if request.method == "GET": return render_template("register.html", message=message) else: if request.form['b'] == "Register": username = request.form["regusername"] password = request.form["regpassword"] password2 = request.form["regpassword2"] if mongo.user_exists(username) == "exists": message = "Someone already has this username. Please use a different one." return render_template("register.html", message=message) else: if password == password2: mongo.add_user(username, password) session['username'] = username return redirect(url_for('signup')) else: message = "Please make sure your passwords match." return render_template("register.html", message=message) if request.form['b'] == "Cancel": return redirect(url_for('index'))
def sign_up(): if request.method == 'GET': return render_template('sign_up.html') else: first_name = request.form.get('first_name') last_name = request.form.get('last_name') fb_email = request.form.get('fb_email') email = request.form.get('email') birthday = request.form.get('birthday') mongo.add_user(first_name, last_name, fb_email, email, birthday) return redirect('/show_symptoms')
def verify_token(): email = request.args.get('email', '') token = request.args.get('token', '') user = mongo.verified(email) if user: u = User.from_json(user) s = hashlib.sha3_512() s.update((secret+u.email).encode('utf-8')) if s.hexdigest() == token: mongo.add_user(u) mailgun.add_list_member(u) session['email'] = u.email flash('Welcome %s, thanks for signing up!' % (u.first_name), "success") mongo.delete_verified(u.email) return redirect('/find_symptoms') flash('We could not verify this email', 'error') return render_template('404.html')
def home(): if 'username' in session: return redirect(url_for('welcome')) else: message = "" if request.method=="GET": return render_template("home.html", message=message) else: if request.form['b']=="About": return render_template("home.html", message=message) if request.form['b']=="Log In": username = request.form["logusername"] password = request.form["logpassword"] confirmation = mongo.authenticate(username,password) if confirmation != "match": message = confirmation return render_template("home.html", message=message) if confirmation == "match": session['username'] = username return redirect(url_for('welcome')) if request.form['b']=="Sign Up": username = request.form["signusername"] password = request.form["signpassword"] password2 = request.form["signpassword2"] name = request.form["name"] if mongo.user_exists(username) == "exists": message = "Someone already has this username. Please use a different one." return render_template("home.html", message=message) else: if password == password2: mongo.add_user(username,password,name) message = "Registration Sucessful! Log In to get started." return render_template("home.html", message=message) else: message = "Please make sure your passwords match" return render_template("home.html", message=message) if request.form['b']=="Cancel": return render_template("home.html", message=message)
def register(): user = request.args.get("user") password = request.args.get("pwd") pcheck = request.args.get("pwdcheck") register = request.args.get("register") if (user != None and password != None and pcheck != None): if (len(password) < 5): flash("Password must be at least 5 characters.") return redirect("/register") if (password == pcheck and not(mongo.exists_user(user))): session['name']=user mongo.add_user(user,password) mongo.login_user(user) return redirect("/page") if (mongo.exists_user(user)): flash("This username is taken.") return redirect("/register") if (password != pcheck): flash("The passwords do not match.") return redirect("/register") else: return render_template("register.html")
def register_amazon_redirect(): # the redirect url will also contain parameters such as 'code' and 'scope' # so save it into a dictionary data = { 'code': request.args.get('code', None), 'scope': request.args.get('scope', None) } # get token from the 'code' token_data = generate_token(data.get('code')) # get profile datra from access_token which is available in token data profile = get_profile_info(token_data.get('access_token')) # create a new user from all the details available user = { 'access_token': token_data.get('access_token'), 'refresh_token': token_data.get('refresh_token'), 'token_created_date': datetime.now(), 'token_expiry_date': datetime.now() + timedelta(seconds=token_data['expires_in']), 'email': profile.get('email'), 'name': profile.get('name'), 'user_id': profile.get('user_id') } # add a new user to the mongoDB add_user(user) # finally return a html file return render_template('auth_redirect.html')
def start(bot, update): user_id = update.message.chat.id mongo.add_user(user_id) bot.send_message(chat_id=user_id, text=messages.START, reply_markup=keyboards.START)