def logout(db): # Method to logout. # First checking if the active user is logged in or not. If the user is logged in and has an active session, then # deleting the session from sessions table and redirecting to the index page. active_user = users.session_user(db) if active_user is not None: users.delete_session(db,active_user) return redirect("/")
def login(): """ As a registered user when i wish to log out i see a button that will log me out of PSST! Removes the users session from the database then redirectes them to the homepage """ db = PsstDb() users.delete_session(db, users.session_user(db)) redirect('/')
def logout(): """ Removes cookie from user :return: The homepage """ user = users.session_user(db) if user is not None: users.delete_session(db, user) redirect('/', 302)
def logout(): """Post request for Logout; Upon login, if user submits logout form their session and cookie is deleted. They are then redirected to the Main Page.""" db = COMP249Db() curr_user = users.session_user(db) if curr_user: users.delete_session(db, curr_user) response.delete_cookie(COOKIE_NAME) redirect('/')
def logout(): """ 处理登出 :return:重定向至首页 """ flowTowDataBase = COMP249Db() requestUser = users.session_user(flowTowDataBase) users.delete_session(db=flowTowDataBase, usernick=requestUser) return redirect('/')
def logout(): """Logout""" db = COMP249Db() username = session_user(db) # retrieve user session information from the database if username: delete_session(db, username) # remove user session response.set_header('Location', '/') response.status = 303 return "Redirect to /" # redirect to /
def login(): usern = request.forms.get('nick') passw = request.forms.get('password') if users.check_login(COMP249Db(), usern, passw) is True: users.delete_session(COMP249Db(), usern) session = users.generate_session(COMP249Db(), usern) return redirect('/') return index(False)
def logout_req(db): """The method terminates the users session and redirects to mainpage""" username = users.session_user(db) #delete user cookie users.delete_session(db, username) # reset error message info['message'] = '' return redirect("/")
def logout(db): """"handles logging out of a user, once a user clicks the logout button they are logged out by removing their current session from the database via the function users.delete_session(), their cookie is also removed thus logging them out, a redirect occurs once successfully logged out to index page where they will once again be asked to login """ users.delete_session(db, users.session_user(db)) response.delete_cookie(users.COOKIE_NAME) redirect('/')
def flowtow_app(environ, start_response): headers = [('content-type', 'text/html')] # about page if environ['PATH_INFO'] == '/about': start_response("200 OK", headers) return page_about(environ) # action comment elif environ['PATH_INFO'] == '/comment': action_comment(environ) headers.append(('location', '/')) start_response("303 See Other", headers) return page_index(environ) # action upload elif environ['PATH_INFO'] == '/upload': action_upload(environ) start_response("200 OK", headers) return page_my_images(environ, start_response) # action login elif environ['PATH_INFO'] == '/login': form = cgi.FieldStorage(environ=environ, fp=environ['wsgi.input']) if 'email' in form and 'password' in form: useremail = form.getvalue('email') can_login = check_login(db, useremail, form.getvalue('password')) if can_login: cookie = generate_session(db, useremail) headers.append(('Set-Cookie', cookie[COOKIE_NAME].OutputString())) headers.append(('location', '/')) start_response("303 See Other", headers) return page_index(environ) headers.append(('location', '/?login_failed')) start_response("303 See Other", headers) return page_index(environ) # action logout elif environ['PATH_INFO'] == '/logout': logged_user = user_from_cookie(db, environ) if logged_user: delete_session(db, logged_user) headers.append(('location', '/')) start_response("303 See Other", headers) return page_index(environ) # my images elif environ['PATH_INFO'] == '/my_images': start_response("200 OK", headers) return page_my_images(environ, start_response) # index page elif environ['PATH_INFO'] == '/': start_response("200 OK", headers) return page_index(environ) # 404 else: return page_404(start_response)
def logout(environ, start_response): # success = False current_user = users.user_from_cookie(db, environ) headers = [("content-type", "text/html")] # formdata = cgi.FieldStorage(environ=environ, fp=environ['wsgi.input']) # if 'password' in formdata: # email = formdata.getvalue("email","") # password = formdata.getvalue("password","") # success = users.check_login(db, email, password) # if success: # cookie = users.generate_session(db, email) # headers.append(('Set-Cookie', cookie['sessionid'].OutputString())) # headers.append(("Location", "/")) users.delete_session(db, current_user) start_response("303 See Other", headers) return [redirect_page.encode()]
def test_delete_session(self): """The delete_session procedure should remove all sessions for a given user in the sessions table. Test relies on working generate_session""" # run tests for all test users for passwd, nick, avatar in self.users: users.generate_session(self.db, nick) # now remove the session users.delete_session(self.db, nick) # now check that the session is not present cursor = self.db.cursor() cursor.execute('select sessionid from sessions where usernick=?', (nick, )) rows = cursor.fetchall() self.assertEqual( rows, [], "Expected no results for sessions query from deleted session, got %s" % (rows, ))
def test_delete_session(self): """The delete_session procedure should remove all sessions for a given user in the sessions table. Test relies on working generate_session""" # run tests for all test users for passwd, nick, avatar in self.users: users.generate_session(self.db, nick) # now remove the session users.delete_session(self.db, nick) # now check that the session is not present cursor = self.db.cursor() cursor.execute('select sessionid from sessions where usernick=?', (nick,)) rows = cursor.fetchall() self.assertEqual(rows, [], "Expected no results for sessions query from deleted session, got %s" % (rows,))
def test_delete_session(self): """The delete_session procedure should remove all sessions for a given user in the sessions table. Test relies on working generate_session""" # run tests for all test users for email, password, first, last in self.users: cookie = users.generate_session(self.db, email) self.assertIsInstance(cookie, SimpleCookie, "generate_session failing, can't run delete_session tests") # get the value and verify that it is in the sessions table sessionid = cookie[users.COOKIE_NAME].value # now remove the session users.delete_session(self.db, email) # now check that the session is not present cursor = self.db.cursor() cursor.execute("select sessionid from sessions where useremail=?", (email,)) rows = cursor.fetchall() self.assertEqual(rows, [], "Expected no results for sessions query from deleted session, got %s" % (rows,))
def logout(): users.delete_session(COMP249Db(), users.session_user(COMP249Db())) return redirect('/')
def logout(): db = COMP249Db() users.delete_session(db, users.session_user(db)) response.set_header('Location', '/') response.status = 303 return 'Redirect to /'
def logout(db): name = users.session_user(db) users.delete_session(db, name) redirect('/')
def logout(db): """Username is retrieved from the session and session will be terminated using the delete_session from users.py""" usernick = users.session_user(db) users.delete_session(db, usernick) redirect('/')
def logout(db): usernick = users.session_user(db) users.delete_session(db, usernick) redirect('/')
def logout(): db = COMP249Db() usernick = users.session_user(db) users.delete_session(db, usernick) return redirect('/', code=302)
def logout(db): delete_session(db, session_user(db)) redirect("/")