def profile(response, username): auth.require_user(response) user = auth.get_user(response) if user == None: return if not username: username = user else: username = User.get(username) if user is not None: firstname = username.get_first_name() lastname = username.get_last_name() email = username.get_email() school = username.get_school() interests = {"activities":None, "tv":None} about = {"birthday":None, "age":None, "website":None} education = {"school":None,"subjects":None,"state":None,"grade":None} picture = username.get_profile_pic_path() if not picture: picture = "/static/images/default_avatar.jpeg" print "PICTURE IS: " + picture fullname = firstname + " " + lastname context = {"title":fullname, 'wallorfeed':'wallupdate', "username":username.get_username(),'current_Wall':username.get_username(), "profile_pic_location":picture, "email":email, "school":school, "css": "profile", "friends":friends.get_friends(username.get_username()), "user": user, "interests": interests, "about": about, "education":education,"user":user,'can_use_wall':can_use_wall(user,username.get_username())} template.render_template("templates/profile.html", context, response)
def login(response, context): #logout(response) page = response.get_field("page") if not page: page = "/" username = response.get_field("username") password = response.get_field("password") if User.exists(username): user = User.get(username) context["firstname"] = user.get_first_name() context["user"] = username context["css"] = "login" if user.password_correct(password): message = "username: "******" password: "******"output"] = message response.set_cookie("User",username) response.redirect(page) else: message = "Wrong Password" firstname = user.get_first_name() context["output"] = message else: message = "User does not exist" context["output"] = message response.redirect(page)
def get_wall(self): final = [] data = self.cursor.execute('SELECT * FROM WALL ORDER BY time DESC') if not data: return 0 for row in data: current_Row = [[row[0],row[1],row[1],row[2],row[4],age(int(row[3])),'']]; if row[2] == self.current_Wall: author = User.get(row[1]) fullname = author.get_first_name() + " " + author.get_last_name() path = author.get_profile_pic_path() if not path: current_Row[0][6] = '/static/images/default_avatar.jpeg' else: current_Row[0][6] = path if current_Row[0][3].isdigit(): current_Row[0][3] = database_subject.get_subject(current_Row[0][3]).get_name() current_Row[0][3] = current_Row[0][3].replace('_',' ') current_Row[0][3] = 'Posted to ' + current_Row[0][3] elif current_Row[0][3] == current_Row[0][2]: current_Row[0][3] = '' else: current_Row[0][3] = 'Posted to ' + current_Row[0][3] +'\'s wall' current_Row[0][1] = fullname final.append(current_Row[0]) return final
def signup(response): username = response.get_field("username") firstname = response.get_field("firstname") lastname = response.get_field("lastname") email = response.get_field("email") password = response.get_field("password") school = response.get_field("school") print username if username and email and firstname and lastname and password and not User.exists( username): newUser = { "username": username, "firstname": firstname, "lastname": lastname, "email": email, "password": password, "school": school } User.add(newUser) print " I am here" x = User.get(username) print x # we're going to be hacky, and manually set a cookie, which shouldn't happen - # but we want to prevent the user from being redirected to the login page, straight # after signing up. response.set_cookie("User", username) response.redirect("/profile/" + username) else: #response.write(SIGNUP) title = "Sign Up" context = {"title": title, "css": "signup", "user": None} template.render_template("templates/signup.html", context, response)
def loginpage(response): username = response.get_cookie("User") page = response.get_field("page") if not page: page = "/" context = {"title":"Login", "output":"", "user":"", "username":"","page":page, "css":"login"} if username and User.get(username): user = User.get(username) context["output"] = "Hello " + user.get_first_name() context["user"] = username context["username"] = username context["firstname"] = user.get_first_name() response.redirect("/") else: username = response.get_field("username") if username: login(response, context) template.render_template("templates/login.html", context, response)
def remove_friend_handler(response, friend_username): auth.require_user(response) user = auth.get_user(response) if user == None: return username = user.get_username() print '\n\n',username, friend_username, '\n\n' friend = User.get(friend_username) remove_friend(username, friend_username) context = {'user':user, 'friend':friend} template.render_template('templates/confirmation.html', context, response)
def add_friend_user(response): auth.require_user(response) user = auth.get_user(response) if user == None: return friend = User.get(response.get_field("user")) if friend == None: pass else: add_friend(user.get_username(), friend.get_username()) context = {'user':user, 'friend':friend} template.render_template('templates/addconfirmation.html', context, response)
def profile(response, username): auth.require_user(response) user = auth.get_user(response) if user == None: return if not username: username = user else: username = User.get(username) if user is not None: firstname = username.get_first_name() lastname = username.get_last_name() email = username.get_email() school = username.get_school() interests = {"activities": None, "tv": None} about = {"birthday": None, "age": None, "website": None} education = { "school": None, "subjects": None, "state": None, "grade": None } picture = username.get_profile_pic_path() if not picture: picture = "/static/images/default_avatar.jpeg" print "PICTURE IS: " + picture fullname = firstname + " " + lastname context = { "title": fullname, 'wallorfeed': 'wallupdate', "username": username.get_username(), 'current_Wall': username.get_username(), "profile_pic_location": picture, "email": email, "school": school, "css": "profile", "friends": friends.get_friends(username.get_username()), "user": user, "interests": interests, "about": about, "education": education, "user": user, 'can_use_wall': can_use_wall(user, username.get_username()) } template.render_template("templates/profile.html", context, response)
def get_wall(self): final = [] data = self.cursor.execute('SELECT * FROM WALL ORDER BY time DESC') if not data: return 0 for row in data: current_Row = [[ row[0], row[1], row[1], row[2], row[4], age(int(row[3])), '' ]] if row[2] == self.current_Wall: author = User.get(row[1]) fullname = author.get_first_name( ) + " " + author.get_last_name() path = author.get_profile_pic_path() if not path: current_Row[0][6] = '/static/images/default_avatar.jpeg' else: current_Row[0][6] = path if current_Row[0][3].isdigit(): current_Row[0][3] = database_subject.get_subject( current_Row[0][3]).get_name() current_Row[0][3] = current_Row[0][3].replace('_', ' ') current_Row[0][3] = 'Posted to ' + current_Row[0][3] elif current_Row[0][3] == current_Row[0][2]: current_Row[0][3] = '' else: current_Row[0][ 3] = 'Posted to ' + current_Row[0][3] + '\'s wall' current_Row[0][1] = fullname final.append(current_Row[0]) return final
def signup(response): username = response.get_field("username") firstname = response.get_field("firstname") lastname = response.get_field("lastname") email = response.get_field("email") password = response.get_field("password") school = response.get_field("school") print username if username and email and firstname and lastname and password and not User.exists(username): newUser = {"username": username, "firstname":firstname,"lastname":lastname,"email":email,"password":password,"school":school} User.add(newUser) print " I am here" x = User.get(username) print x # we're going to be hacky, and manually set a cookie, which shouldn't happen - # but we want to prevent the user from being redirected to the login page, straight # after signing up. response.set_cookie("User", username) response.redirect("/profile/" + username) else: #response.write(SIGNUP) title = "Sign Up" context = {"title":title, "css":"signup", "user":None} template.render_template("templates/signup.html", context, response)
def get_friends(username): friendlist = [] if username in FRIENDS: for friend in FRIENDS[username]: friendlist.append(User.get(friend)) return friendlist
def get_user(response): if response.get_cookie("User"): return User.get(response.get_cookie("User")) else: return None