Merge branch 'master' into prod
This commit is contained in:
		
						commit
						3334d6976e
					
				
					 6 changed files with 119 additions and 7 deletions
				
			
		|  | @ -349,8 +349,8 @@ | |||
|     "fields": { | ||||
|         "title": "Log In", | ||||
|         "hint": "", | ||||
|         "url": "/account/login/", | ||||
|         "urlaspattern": false, | ||||
|         "url": "nbpy_login", | ||||
|         "urlaspattern": true, | ||||
|         "tree": 1, | ||||
|         "hidden": false, | ||||
|         "alias": null, | ||||
|  |  | |||
							
								
								
									
										25
									
								
								pinaxcon/account_hooks.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								pinaxcon/account_hooks.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| from account import hooks | ||||
| from django.contrib.auth.models import User | ||||
| 
 | ||||
| 
 | ||||
| class BetterAccountHookSet(hooks.AccountDefaultHookSet): | ||||
| 
 | ||||
|     def get_user_credentials(self, form, identifier_field): | ||||
|         username = form.cleaned_data[identifier_field] | ||||
| 
 | ||||
|         # Find an actual username so we can authenticate | ||||
|         print username, | ||||
|         if identifier_field == "email": | ||||
|             username = self.get_username_by_email(username) | ||||
|         print username, | ||||
| 
 | ||||
|         return { | ||||
|             "username": username, | ||||
|             "password": form.cleaned_data["password"], | ||||
|         } | ||||
| 
 | ||||
|     def get_username_by_email(self, email): | ||||
|         try: | ||||
|             return User.objects.get(email=email).username | ||||
|         except User.DoesNotExist: | ||||
|             return None | ||||
|  | @ -15,7 +15,7 @@ DATABASES = { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| UNPREPEND_WWW = bool(os.environ.get("DJANGO_UNPREPEND_WWW", False)) | ||||
| UNPREPEND_WWW = bool(int(os.environ.get("DJANGO_UNPREPEND_WWW", "0"))) | ||||
| 
 | ||||
| # HEROKU: Update database configuration with $DATABASE_URL. | ||||
| import dj_database_url | ||||
|  | @ -258,17 +258,21 @@ EMAIL_HOST = os.environ.get("DJANGO_EMAIL_HOST", "") | |||
| EMAIL_PORT = int(os.environ.get("DJANGO_EMAIL_PORT", 25)) | ||||
| EMAIL_HOST_USER = os.environ.get("DJANGO_EMAIL_HOST_USER", "") | ||||
| EMAIL_HOST_PASSWORD = os.environ.get("DJANGO_EMAIL_HOST_PASSWORD", "") | ||||
| EMAIL_USE_TLS = bool(os.environ.get("DJANGO_EMAIL_USE_TLS", False)) | ||||
| EMAIL_USE_SSL = bool(os.environ.get("DJANGO_EMAIL_USE_SSL", False)) | ||||
| EMAIL_USE_TLS = bool(int(os.environ.get("DJANGO_EMAIL_USE_TLS", "0"))) | ||||
| EMAIL_USE_SSL = bool(int(os.environ.get("DJANGO_EMAIL_USE_SSL", "0"))) | ||||
| 
 | ||||
| ACCOUNT_LOGIN_URL = "nbpy_login" | ||||
| LOGIN_URL = "nbpy_login" | ||||
| 
 | ||||
| # We need to explicitly switch on signups. | ||||
| ACCOUNT_OPEN_SIGNUP = bool(os.environ.get("DJANGO_ACCOUNT_OPEN_SIGNUP", False)) | ||||
| ACCOUNT_OPEN_SIGNUP = bool(int(os.environ.get("DJANGO_ACCOUNT_OPEN_SIGNUP", "0"))) | ||||
| ACCOUNT_EMAIL_UNIQUE = True | ||||
| ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = False if DEBUG else True | ||||
| ACCOUNT_LOGIN_REDIRECT_URL = "home" | ||||
| ACCOUNT_LOGIN_REDIRECT_URL = "dashboard" | ||||
| ACCOUNT_LOGOUT_REDIRECT_URL = "home" | ||||
| ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2 | ||||
| ACCOUNT_USE_AUTH_AUTHENTICATE = True | ||||
| ACCOUNT_HOOKSET =  "pinaxcon.account_hooks.BetterAccountHookSet" | ||||
| 
 | ||||
| AUTHENTICATION_BACKENDS = [ | ||||
|     "symposion.teams.backends.TeamPermissionsBackend", | ||||
|  |  | |||
							
								
								
									
										59
									
								
								pinaxcon/templates/account_login.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								pinaxcon/templates/account_login.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,59 @@ | |||
| {% extends "page_with_title_and_lede.html" %} | ||||
| 
 | ||||
| {% load bootstrap %} | ||||
| {% load i18n %} | ||||
| 
 | ||||
| {% block head_title %}Log In{% endblock %} | ||||
| 
 | ||||
| {% block heading %}Log In or Sign Up{% endblock %} | ||||
| 
 | ||||
| {% block body_class %}login{% endblock %} | ||||
| 
 | ||||
| {% block content %} | ||||
| 
 | ||||
|   <div class="container"> | ||||
|     <div class="row"> | ||||
|       <div class="col-md-4"> | ||||
| 
 | ||||
|         <form action="{% url 'account_login' %}" method="POST"> | ||||
|           <div class="panel panel-primary"> | ||||
|             <div class="panel-heading"> | ||||
|               <h3 class="panel-title"> | ||||
|                 Log into an existing account | ||||
|               </h3> | ||||
|             </div> | ||||
|             <div class="panel-body"> | ||||
|               {% csrf_token %} | ||||
|               {{ login_form|bootstrap }} | ||||
|             </div> | ||||
|             <div class="panel-footer"> | ||||
|               <button role="submit" class="btn btn-primary">Log In</button> | ||||
|             </div> | ||||
|           </div> | ||||
|         </form> | ||||
| 
 | ||||
|       </div> | ||||
|       {% if signup_open %} | ||||
|         <div class="col-md-4"> | ||||
|           <form action="{% url 'account_signup' %}" method="POST"> | ||||
|             <div class="panel panel-default"> | ||||
|               <div class="panel-heading"> | ||||
|                 <h3 class="panel-title"> | ||||
|                   Sign up for a new account | ||||
|                 </h3> | ||||
|               </div> | ||||
|               <div class="panel-body"> | ||||
|                 {% csrf_token %} | ||||
|                 {{ signup_form|bootstrap }} | ||||
|               </div> | ||||
|               <div class="panel-footer"> | ||||
|                 <button role="submit" class="btn btn-primary">Sign Up</button> | ||||
|               </div> | ||||
|             </div> | ||||
|           </form> | ||||
|         </div> | ||||
|       {% endif %} | ||||
|     </div> | ||||
|   </div> | ||||
| 
 | ||||
| {% endblock %} | ||||
|  | @ -52,6 +52,9 @@ urlpatterns = [ | |||
| 
 | ||||
|     url(r"^admin/", include(admin.site.urls)), | ||||
| 
 | ||||
|     url(r"^login$", views.account_login, name="nbpy_login"), | ||||
|     # Override the default account_login view with one that takes email addys | ||||
|     url(r"^account/login/$", views.EmailLoginView.as_view(), name="account_login"), | ||||
|     url(r"^account/", include("account.urls")), | ||||
| 
 | ||||
|     url(r"^dashboard/", symposion.views.dashboard, name="dashboard"), | ||||
|  |  | |||
|  | @ -1,9 +1,30 @@ | |||
| from django.conf import settings | ||||
| from django.http import HttpResponseServerError | ||||
| from django.shortcuts import render | ||||
| from django.template import RequestContext | ||||
| from django.template import Template | ||||
| from django.template.loader import get_template | ||||
| from django.views import defaults | ||||
| 
 | ||||
| from account.forms import LoginEmailForm, LoginUsernameForm, SignupForm | ||||
| from account.views import LoginView | ||||
| 
 | ||||
| def server_error(request, template_name=defaults.ERROR_500_TEMPLATE_NAME): | ||||
|     t = Template("{%% include '%s' %%}" % template_name) | ||||
|     return HttpResponseServerError(t.render(RequestContext(request))) | ||||
| 
 | ||||
| 
 | ||||
| def account_login(request): | ||||
| 
 | ||||
|     d = { | ||||
|         "login_form": LoginEmailForm(), | ||||
|         "signup_form": SignupForm(), | ||||
|         "signup_open": getattr(settings, "ACCOUNT_OPEN_SIGNUP", True), | ||||
|     } | ||||
| 
 | ||||
|     print d["signup_open"], settings.ACCOUNT_OPEN_SIGNUP | ||||
|     return render(request, "account_login.html", d) | ||||
| 
 | ||||
| 
 | ||||
| class EmailLoginView(LoginView): | ||||
|     form_class = LoginEmailForm | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer