Fix test cookie logic
set_test_cookie has to be in a separate request/response cycle than test_ and delete_test_cookie. Add some comments about what's going on.
This commit is contained in:
		
							parent
							
								
									b25eb12d7e
								
							
						
					
					
						commit
						e3e8295e47
					
				
					 1 changed files with 5 additions and 1 deletions
				
			
		
							
								
								
									
										6
									
								
								views.py
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								views.py
									
										
									
									
									
								
							|  | @ -7,20 +7,24 @@ def index(request): | ||||||
|     have a session id) return the follower_graph view. Otherwise, render the |     have a session id) return the follower_graph view. Otherwise, render the | ||||||
|     index page.''' |     index page.''' | ||||||
|     if request.method == 'POST': |     if request.method == 'POST': | ||||||
|         request.session.set_test_cookie() |  | ||||||
|         return redirect('login') |         return redirect('login') | ||||||
|     if 'sessionid' in request.session: |     if 'sessionid' in request.session: | ||||||
|         return follower_graph(request) |         return follower_graph(request) | ||||||
|  |     # Set a test cookie. When the user clicks the 'Login' button, test and make | ||||||
|  |     # sure this cookie was set properly. | ||||||
|  |     request.session.set_test_cookie() | ||||||
|     return render_to_response('login.html') |     return render_to_response('login.html') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def login(request): | def login(request): | ||||||
|     '''Do a quick check to make sure cookies are enabled. If so, redirect to |     '''Do a quick check to make sure cookies are enabled. If so, redirect to | ||||||
|     GitHub so the user can login.''' |     GitHub so the user can login.''' | ||||||
|  |     # Make sure the user can accept cookies. | ||||||
|     if request.session.test_cookie_worked(): |     if request.session.test_cookie_worked(): | ||||||
|         request.session.delete_test_cookie() |         request.session.delete_test_cookie() | ||||||
|         return redirect('/login/github/') |         return redirect('/login/github/') | ||||||
|     else: |     else: | ||||||
|  |         # TODO: Render an error -- fix your damn cookies! | ||||||
|         return render_to_response('login.html') |         return render_to_response('login.html') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue