-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in custom backend. Adding in a style sheet, adding in a login …
…view. refactoring to the 'render()' function as opposed to the render_to_response function.
- Loading branch information
Spencer Romo
committed
Aug 15, 2016
1 parent
81cbafd
commit a1f43c2
Showing
8 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.contrib.auth.models import User | ||
|
||
class EmailAuth: | ||
def authenticate(self, email = '', password = ''): | ||
try: | ||
user = User.objects.get(email = email) | ||
if user.check_password(password): | ||
return user | ||
else: | ||
return None | ||
except Exception, e: | ||
print str(e) | ||
return None | ||
def get_user(self, user_id = ''): | ||
try: | ||
return User.objects.get(pk = user_id) | ||
except User.DoesNotExist: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
from django.shortcuts import render, render_to_response | ||
|
||
from django.shortcuts import render | ||
from django.template.context import RequestContext | ||
|
||
def home(request): | ||
return render_to_response('home.html') | ||
return render(request, 'home.html') | ||
|
||
|
||
def loginTest(request): | ||
return render(request, 'login.html') | ||
|
||
def styleSheet(request): | ||
return render(request, 'style_sheet.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
{% if form.errors %} | ||
<p>Error</p> | ||
{% endif %} | ||
|
||
<form action = '/u/auth' method = 'post'> | ||
{% csrf_token %} | ||
<label for = 'email'> | ||
Email: | ||
</label> | ||
<input type = 'text' name = 'email' value = '' id = 'email'> | ||
<label for = 'password'> | ||
Password: | ||
</label> | ||
<input type = 'password' name = 'password' value = '' id = 'password'> | ||
<input type = 'submit' value = 'login'/> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<h1> components go here! </h1> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.conf.urls import include, url | ||
import views | ||
|
||
urlpatterns = [ | ||
url(r'^auth$', views.authorization), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
from django.shortcuts import render | ||
from django.contrib.auth import authenticate, login | ||
from django.http import HttpResponseBadRequest | ||
|
||
# Create your views here. | ||
|
||
|
||
def authorization(request): | ||
try: | ||
em = request.POST.get('email', '') | ||
print 'em: ', em | ||
pw = request.POST.get('password', '') | ||
print 'pw: ', pw | ||
user = authenticate(email = em, password = pw) | ||
if user is not None: | ||
print 'user successfully logged in' | ||
return render(request, 'home.html') | ||
else: | ||
print 'login failed' | ||
return render(request, 'home.html') | ||
except Exception, e: | ||
return HttpResponseBadRequest(str(e), status = 400) | ||
|
||
|
||
|