def profile(): if 'user' in session: user = session['user'] poems = mongo.getPoems(user) poems.reverse() return render_template("profile.html", user=user,poems=poems) else: print "User Not Logged In" return redirect("/")
def home(): print "HOME PAGE ###" #global poem poem = [] poems = mongo.getAllPoems() poems.reverse() poems = poems[:10] error = "" #If the user is in the session if 'user' in session: print "USER IN SESSION" if request.method == "GET": return render_template("home.html" ,poems=poems ,loggedin=True ,error=error) #If the user is not in the session elif request.method == "POST": print "USER NOT IN SESSION" username = request.form.get("username") password = request.form.get("password") button = request.form['button'] #If the button pressed is Login if button=='Login': print "LOGGING IN #############" if mongo.exists(username,password): if mongo.checkUser(username, password): session['user'] = username poems = mongo.getPoems(username) poems.reverse() return render_template("profile.html" ,user=username ,poems=poems) else: error = "Incorrect password" return render_template("home.html" ,poems=poems ,loggedin=False ,error=error) else: error = "Username does not exist" return render_template("home.html" ,poems=poems ,loggedin=False ,error=error) #If the button pressed is Register elif button=='Register': print "ADDING USER ########" if not mongo.exists(username, password): session['user'] = username mongo.addUser(username, password) poem = [] print "ADDED USER" return redirect("/generate") else: error = "Username already exists" return render_template("home.html" ,poems=poems ,loggedin=False ,error=error) return render_template("home.html",poems=poems,loggedin=False,error=error)