Last active
August 29, 2015 14:17
-
-
Save JamesHovious/081052113084c52493b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import json | |
from django.http import HttpResponse | |
from project.libs.pybcrypt import bcrypt | |
class ClassName: | |
def test(self): | |
json_response = json.dumps({"success": 1, "errors": 0, "msg": "test_successfully_sent"}) | |
return HttpResponse(json_response, mimetype="application/json") | |
def register(self, c, json_data): | |
""" | |
Expecting the following structure | |
{ | |
"tag": "register", | |
"data": { | |
"email": "email@email.com", | |
"first_name": "firstname", | |
"last_name": "lastname", | |
"password": "P@$$w0rd", | |
"date": "Month day year" | |
} | |
}""" | |
password = json_data['data']['password'] | |
hashed = bcrypt.hashpw(password, bcrypt.gensalt()) | |
query = """INSERT INTO profiles | |
(RID, first_name, last_name, email, password, date) | |
VALUES (default, %s,%s,%s,%s,%s)""" | |
c.execute (query, [json_data['data']['first_name'], json_data['data']['last_name'], | |
json_data['data']['email'], password, | |
json_data['data']['date']]) | |
json_response = json.dumps({"success": 1, "errors": 0}) | |
return HttpResponse(json_response, mimetype="application/json") | |
def account_page(self, c, json_data): | |
""" | |
Expecting the following structure | |
{ | |
"tag": "account_page", | |
"data": { | |
"email": "email@email.com", | |
"first_name": "firstname", | |
"last_name": "lastname", | |
"data": "Month 01 2015", | |
} | |
}""" | |
json_response = json.dumps({"success": 0, "errors": 0}) | |
try: | |
query = """SELECT email, first_name, last_name, date FROM profiles WHERE email = %s""" | |
c.execute(query, [json_data['data']['email']]) | |
row = c.fetchone() | |
json_response = json.dumps({"success": 1, "errors": 0, "results": row}) | |
except Exception, e: | |
json_response = json.dumps({"success": 0, "errors": e}) # TODO log this | |
finally: | |
return HttpResponse(json_response, mimetype="application/json") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment