def post(self, recovery_id): password = self.request.get('password') password_confirm = self.request.get('password_confirm') precovery = PasswordRecovery.all().filter('random_url =',recovery_id).fetch(1) for i in precovery: username = i.username break if not password or password.isspace(): self.pass_template_value_recovery_page(username = username, error = "Please enter a valid password") elif password != password_confirm: self.pass_template_value_recovery_page(username = username, error = "Passwords do not match") else: userdb = UserDB.all().filter('username =',username).fetch(1) for i in userdb: i.password = self.encrypt_password(password) i.put() break for i in precovery: i.reset = True i.put() # home = "http://localhost:8080/blogname" self.response.out.write("""password has been changed successfully. <a href = "http://pagevista.appspot.com/login">return</a>""")
def get_search_result(self, search_key,cursor_start,tags_or_people): key_length = len(search_key) if key_length <= 3: """ ************************************************** ************************************************** Retrieve the username from encoded username for len < 3. ************************************************* *************************************************""" if tags_or_people == 'tags': tagsdb = TagsDB.all().filter('tagname =',search_key).fetch(100) elif tags_or_people == 'people': tagsdb = UserDB.all().filter('username =',search_key).fetch(100) l = [] for i in tagsdb: l.append((i.tagname,1)) elif key_length > 3 and key_length <= 5: mismatch = 1 l = self.return_tags_username(mismatch, search_key, tags_or_people) elif key_length > 5 and key_length <= 8: mismatch = 2 l = self.return_tags_username(mismatch, search_key, tags_or_people) else: mismatch = 3 l = self.return_tags_username(mismatch, search_key, tags_or_people) return set(l)
def return_tags_username(self, mismatch, search_key, tags_or_people): l = [] if tags_or_people == 'tags': tagsdb = TagsDB.all().fetch(1000) for i in tagsdb: if abs(len(i.tagname) - len(search_key)) > mismatch+1: continue else: var = self.within_mismatch_limit(mismatch, i.tagname, search_key) if var or var == 0 : if (i.tagname,var) not in l: l.append((i.tagname,var)) return l elif tags_or_people == 'people': userdb = UserDB.all().fetch(1000) for i in userdb: username = self.return_username_if_valid_cookie(i.username) if abs(len(username) - len(search_key)) > mismatch+1: # print 'if' continue else: # print 'else' var = self.within_mismatch_limit(mismatch, username, search_key) if var or var == 0 : if (username,var) not in l: l.append((username,var)) return l
def get_people(self,username = ''): if not username: userdb = UserDB.all().fetch(500) users = [] for i in userdb: users.append(self.return_username_if_valid_cookie(i.username)) return users else: """call searchpages function"""
def post(self): username_ck = str(self.request.cookies.get("username_ck")) username = self.return_username_if_valid_cookie(username_ck) avatar = images.resize(self.request.get("image"), 90, 90) userdb = UserDB.all().filter("username ="******"/hello_user/%s" % username)
def is_valid_username(self, username): """ check if the username is already existing or not. Return username or False If the user submits wrong the first time, only then cache the usernames from the DB """ userdata = UserDB.all() userdatas = userdata.fetch(1000) username_sec = self.encrypt_username(username) for userdata in userdatas: if userdata.username == username_sec: return None return username
def post(self,username): is_follow = self.request.POST.get('follow') is_get_image = self.request.POST.get('upload_image') if is_get_image: avatar = images.resize(self.request.get('image'),90,90) whos_page = username username_ck = str(self.request.cookies.get('username_ck')) userdb = UserDB.all().filter('username ='******'username_ck')) userdb = UserDB.all().filter('username ='******'/hello_user/%s'%username)
def post(self): username = str(self.request.get('username')) username_sec = self.encrypt_username(username) userdb = UserDB.all().filter('username ='******''.join(random.choice(random_string) for i in range(15)) # self.response.out.write(random_url) for i in userdb: email = i.email_id break recovery_link = "http://pagevista.appspot.com/recovery/"+random_url sender = "<*****@*****.**>" to = "<" + email + ">" body = "reset your password here " + recovery_link subject = "ZOOSMASH - password reset" body = """Dear""" + username +""", Here is the link for resetting your password as per requested """ + recovery_link + """ Please follow the instructions. If you had not requested a password reset for your account please ignore this mail. Thank you, myGreenPage team """ # self.response.out.write(random_url + " " + to + " " + body) mail.send_mail(sender= sender, to = to, subject = "reset mail", body = body) precovery = PasswordRecovery(random_url = random_url, username = username_sec) precovery.put() self.pass_template_value_password_reset_page(error = "A link to reset your password has" + "been mailed to you.Plese follow instructions mentioned "+ "in it to reset yor password. ")
def load_upload(self,title, content, username, username_ck, tag1 = "", tag2 = "", tag3 = ""): users = UserDB.all().filter('username ='******'-rating', update = True) self.loadAllTagsDb(update = True) self.redirect('/done/%d'%post_username.key().id()) break # if not users: # content = "no usres returned from the query " + username_ck """instead of passing to the new_page redirect to the done page"""
def get(self,username): """The homepage of username is hidden from non-logged in user. This may prompt him to register for the site.""" username_ck = str(self.request.cookies.get('username_ck')) if not username_ck or username_ck == 'None': self.redirect('/login') else: username_sec = self.encrypt_username(username) userdb = UserDB.all().filter('username ='******'userdb =',i).fetch(100) for post in posts: date = self.get_date_without_decimal_in_seconds(post.date) l.append((post.key().id(), post.title, post.author, post.subject, date, post.like_count, post.comment_count, post.tag1, post.tag2, post.tag3, post.like, post.dislike)) user_posts = l whos_page = username username = self.return_username_if_valid_cookie(username_ck) q = PeopleDB.all().filter('people_follows =',username_ck).fetch(100) following = [] for i in q: following.append(i.people_followed) if whos_page != username: if whos_page in following: follow = "" else: follow = "follow" following = "" else: follow = "" self.pass_template_value_hellouser_page(logout = 'Logout',image_id_key = image_key, username = username ,whos_page = whos_page, follow = follow, posts = user_posts, following = following)
def post(self): """ Fetch a maximum of 1000 usernames as of now and compare to see if the username entered is valid. """ username_entered = str(self.request.get('username')) password_entered = str(self.request.get('password')) login_valid = False if not username_entered or not password_entered: loginpage_error = "invalid username and password" login_valid = False self.pass_template_value_login_page(loginpage_error = loginpage_error) else: q = UserDB.all() results = q.fetch(1000) password_sec = self.encrypt_password(password_entered) username_sec = self.encrypt_username(username_entered) username_found = False for result in results: if result.username == username_sec and result.password == password_sec: login_valid = True break elif result.username == username_sec: username_found = True if login_valid: """set cookie and redirect to the users homepage """ self.response.headers.add_header('Set-Cookie','username_ck=%s'%username_sec) self.redirect('/hello_user/%s'%username_entered) else: if username_found: # self.response.out.write("username found") self.pass_template_value_login_page(signup = "Signup", valid_username = "******") else: loginpage_error = "invalid username and password" login_valid = False self.pass_template_value_login_page(loginpage_error = loginpage_error,signup = "Signup")
def post(self): username_ck = str(self.request.cookies.get('username_ck')) if not username_ck or username_ck == 'None': login = "******" signup = "Signup" username = "" logout = "" else: username = self.return_username_if_valid_cookie(username_ck) login = "" signup = "" logout = "Logout" is_tag_search = self.request.POST.get('tag_search') if is_tag_search: search_key = str(self.request.get('search_key')) is_tag_or_people = self.request.POST.get('tags_or_people') # is_tag_or_people = is_tag_or_people.strip() search_key = search_key.strip() if not search_key or not is_tag_or_people: self.redirect('/trending') else: # self.redirect('search/%s'%search_key) tags = SearchPage().get_search_result(search_key,0,is_tag_or_people) tags = sorted(tags, key = lambda x: x[1] ) l = [] for (tag,rank) in tags: l.append(tag) display_tag = False display_people = False if is_tag_or_people == 'tags': display_tag = True if is_tag_or_people == "people": display_people = True # self.response.out.write('hi') self.pass_template_value_search_page(logout = logout, username = username, signup = signup, login = login, search_key = search_key, tags = l, display_tag = display_tag, display_people = display_people) # FOR LOGGING IN FROM THE LOGIN POPUP WINDOW username_entered = str(self.request.get('username')) password_entered = str(self.request.get('password')) login_valid = False if not username_entered or not password_entered: loginpage_error = "invalid username and password" login_valid = False self.pass_template_value_login_page(loginpage_error = loginpage_error) else: q = UserDB.all() results = q.fetch(1000) password_sec = self.encrypt_password(password_entered) username_sec = self.encrypt_username(username_entered) for result in results: if result.username == username_sec and result.password == password_sec: login_valid = True break if login_valid: """set cookie and redirect to the users homepage """ self.response.headers.add_header('Set-Cookie','username_ck=%s'%username_sec) self.redirect('/trending') else: loginpage_error = "invalid username and password" login_valid = False self.pass_template_value_login_page(loginpage_error = loginpage_error,signup = "Signup")
def post(self): username = str(self.request.get('username')) email = str(self.request.get('email')) password = str(self.request.get('password')) password_confirm = str(self.request.get('password_confirm')) signup_success = True username_error = "" email_error = "" password_error = "" password_confirm_error = "" # username = self.is_valid_username(username) email = self.is_valid_email(email) if not username: username_error = "Please provide a valid username!" username = "" signup_success = False elif len(username) < 4: username_error = "A username must be atleast 4 characters long" username = "" signup_success = False elif not self.is_valid_username(username): username_error = "The username '" + username +"' 'is already taken!" # username = "" signup_success = False elif not self.chech_username_syntax(username): username_error = "The username must contain alphanumeric characters only" signup_success = False if not email or not self.is_valid_email(email): email_error = "Please provide a valid email address!" email = "" signup_success = False elif not self.email_already_present(email): email_error = "The holder of this email is already a user" email = "" signup_success = False if not password: password_error = "Please provide a valid password!" signup_success = False elif not password_confirm or password_confirm != password: password_confirm_error = "Passwords do not match!" signup_success = False if not signup_success: self.pass_template_value_signup_page(username = username, email = email, username_error = username_error,email_error = email_error,password_error = password_error, password_confirm_error = password_confirm_error) else: username_sec = self.encrypt_username(username) #email_sec = self.encrypt_email(email) email_sec = email password_sec = self.encrypt_password(password) userdb = UserDB(username = username_sec,email_id = email_sec,password = password_sec) userdb.put() self.response.headers.add_header('Set-Cookie','username_ck=%s'%username_sec) #self.response.headers.add_header('Set-Cookie','email_ck=%s'%email) #self.response.headers.add_header('Set-Cookie','password_ck=%s'%password) #self.response.headers.add_header('Set-Cookie','password_confirm_ck=%s'%password_confirm) self.redirect('/hello_user/%s'%username)
def email_already_present(self,email): userdb = UserDB.all().fetch(1000) for i in userdb: if i.email_id == email: return None return email