Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finally getting account login/logout to work

  • Loading branch information...
commit b60e89ddae4b2140ba39cc6a15342e3bcb45953c 1 parent 2af2f3a
@arfrank authored
View
3  app.yaml
@@ -10,7 +10,6 @@ handlers:
- url: /(.*)/accounts/.*
script: handlers/accounts.py
-
-
- url: .*
script: handlers/main.py
+ secure: always
View
5 appengine_config.py
@@ -0,0 +1,5 @@
+from libraries.gaesessions import SessionMiddleware
+
+def webapp_add_wsgi_middleware(app):
+ app = SessionMiddleware(app, cookie_key="asfakjsdljnljksdbcjhabschjbasjkdbcjkhasbcjkabs")
+ return app
View
BIN  appengine_config.pyc
Binary file not shown
View
43 handlers/main.py
@@ -19,7 +19,7 @@
from google.appengine.ext.webapp import template
import os
-from libraries import gaesessions
+from libraries.gaesessions import get_current_session
from models import accounts
from helpers import application
@@ -34,10 +34,19 @@ def get(self):
self.response.out.write(template.render(path,{}))
def post(self):
+ from hashlib import sha256
required = ['email','password','password_confirm']
if application.required(required,self.request) and self.request.get('password') == self.request.get('password_confirm'):
- account = accounts.Account()
-
+ exist_account = accounts.Account.get_by_key_name(self.request.get('email'))
+ if exist_account is None:
+ account = accounts.Account.new(key_name = self.request.get('email'), email=self.request.get('email'),password=self.request.get('password'))
+ account.put()
+ session = get_current_session()
+ session.regenerate_id()
+ session['account'] = account
+ self.redirect('/account')
+ else:
+ Register.get(self)
else:
Register.get(self)
@@ -48,18 +57,36 @@ def get(self):
self.response.out.write(template.render(path,{}))
def post(self):
- pass
-
+ required = ['email','password']
+ if application.required(required,self.request):
+ account = accounts.Account.get_by_key_name(self.request.get('email'))
+ if account is not None and account.check_password(self.request.get('password')):
+ session = get_current_session()
+ session.regenerate_id()
+ session['account'] = account
+ self.redirect('/account')
+ else:
+ Login.get(self)
class Account(webapp.RequestHandler):
def get(self):
- path = os.path.join(os.path.dirname(__file__), '../templates/account.html')
- self.response.out.write(template.render(path,{}))
-
+ session = get_current_session()
+ if session['account'] is None:
+ self.redirect('/login')
+ else:
+ path = os.path.join(os.path.dirname(__file__), '../templates/account.html')
+ self.response.out.write(template.render(path,{'data':{'account':session['account']}}))
+
+class Logout(webapp.RequestHandler):
+ def get(self):
+ session = get_current_session()
+ session.terminate()
+ self.redirect('/')
def main():
application = webapp.WSGIApplication([
('/', MainHandler),
('/register',Register),
('/login',Login),
+ ('/logout',Logout),
('/account',Account)
],
debug=True)
View
2  helpers/sid.py
@@ -7,8 +7,6 @@
def compute_sid(params_dictionary):
hash_string = ''
keys = params_dictionary.items()#.sort()
- print keys
- print 'asdfasdf'
for key in keys:
pass
# hash_string += key + '=' + params_dictionary[key]
View
BIN  libraries/__init__.pyc
Binary file not shown
View
BIN  libraries/gaesessions/__init__.pyc
Binary file not shown
View
20 models/accounts.py
@@ -1,8 +1,26 @@
from google.appengine.ext import db
from models import base
-
+from hashlib import sha256
+import random
+import string
class Account(base.CommonModel):
Sid = db.StringProperty()
FriendlyName = db.StringProperty()
Status = db.StringProperty()
AuthToken = db.StringProperty()
+ Salt = db.StringProperty()
+ Email = db.EmailProperty()
+ Password = db.StringProperty()
+
+ @classmethod
+ def new(cls, key_name, email, password):
+ Salt = ''.join(random.choice(string.digits) for x in range(32))
+ Sid = 'AC'+sha256(email).hexdigest()
+ Password = sha256(Sid+password+Salt).hexdigest()
+ AuthToken = sha256(Sid+Password).hexdigest()
+ return cls(key_name=email,Email = email, FriendlyName = email,
+ Sid=Sid,Status='Active',Salt=Salt,
+ Password=Password,AuthToken=AuthToken)
+
+ def check_password(self,password):
+ return self.Password == sha256(self.Sid+password+self.Salt).hexdigest()
View
BIN  models/accounts.pyc
Binary file not shown
View
12 templates/account.html
@@ -1,4 +1,16 @@
{% extends "../templates/base.html" %}
{% block 'content' %}
<h1 id="account_information">Account Information</h1>
+ <h2>Account Information</h2>
+ <p>
+ Account Sid: {{data.account.Sid}}<br />
+ Account Token: {{data.account.AuthToken}}<br />
+ Email: {{data.account.Email}}<br />
+ Friendly Name: {{data.account.FriendlyName}}<br />
+ </p>
+ <h2>Links</h2>
+ <p>
+ <a href="/phone-numbers">Phone Numbers</a><br>
+ <a href="/logout">Logout</a>
+ </p>
{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.