def profile(): username = escape(session['username']) #POST METHOD MEANS UPDATING PASSWORD if request.method == 'POST': if 'searched' in request.form: if request.form['searched']!= "": return redirect(url_for("recipeList", tag = request.form['searched'])) else: real_pwd = MongoWork.find_pword(username) currpwd = request.form.get("curpas") if currpwd != real_pwd: flash("Sorry! Please enter the correct current password!") return redirect(url_for("profile")) newpwdinput = request.form.get("newpas") newrepwdinput = request.form.get("newrepas") if newpwdinput == newrepwdinput and check_pword(newpwdinput): #matched successfully, update passwords username = escape(session['username']) MongoWork.update_password(username,newpwdinput) flash("Password was successfully updated.") return redirect(url_for("profile")) elif not check_pword(newpwdinput): flash("Your password must be at least SIX characters long and have an uppercase letter, lowercase letter, and a number!") return redirect(url_for("profile")) else: flash("Passwords did not match. Password was not updated.") return redirect(url_for("profile")) else: #GET METHOD user_info = MongoWork.find_usrinfo(username) fname = user_info['firstname'] lname = user_info['lastname'] u = user_info['uname'] return render_template("profile.html",fname=fname, lname=lname,u=u);
def login(): error = None if request.method == 'POST': if 'searched' in request.form: if request.form['searched']!= "": #using search bar return redirect(url_for("recipeList", tag = request.form['searched'])) else: userinput = request.form['user'] pwdinput = request.form['passwd'] #print MongoWork.check_user_in_db(userinput) if MongoWork.check_user_in_db(userinput) != None: if MongoWork.find_pword(userinput) == pwdinput: ##SUCCESSFULLY LOGGED IN session['username'] = userinput redirect_necessary = request.args.get('redirect_user') #redirecting after login if redirect_necessary: return redirect(url_for("profile")) else: return redirect(url_for('index',username=userinput)) else:#incorrect password error error = True return render_template("login.html" ,error=error) else: #print "not in users" notreg = True return render_template("login.html", notreg = notreg) else:#request.method == "GET" error = None return render_template("login.html")
def index(): error = None if request.method == 'POST': userinput = request.form['user'] pwdinput = request.form['passwd'] #print MongoWork.check_user_in_db(userinput) if MongoWork.check_user_in_db(userinput) != None: if MongoWork.find_pword(userinput) == pwdinput: ##SUCCESSFULLY LOGGED IN session['username'] = userinput redirect_necessary = request.args.get('redirect_user') if redirect_necessary: return redirect(url_for("user")) else: return redirect(url_for('dashboard',username=userinput)) else:#incorrect password error error = True return render_template("index.html" ,error=error) else: #print "not in users" notreg = True return render_template("index.html", notreg = notreg) else:#request.method == "GET" error = None return render_template("index.html")