|
|
@ -4,6 +4,7 @@ from apistar import Component, Settings, http, Route, Include
|
|
|
|
from apistar.backends.sqlalchemy_backend import Session
|
|
|
|
from apistar.backends.sqlalchemy_backend import Session
|
|
|
|
from apistar_jwt.authentication import get_jwt
|
|
|
|
from apistar_jwt.authentication import get_jwt
|
|
|
|
from apistar_jwt.token import JWT
|
|
|
|
from apistar_jwt.token import JWT
|
|
|
|
|
|
|
|
from sqlalchemy.exc import IntegrityError, InvalidRequestError
|
|
|
|
|
|
|
|
|
|
|
|
from cookie_api.models import User
|
|
|
|
from cookie_api.models import User
|
|
|
|
|
|
|
|
|
|
|
@ -46,8 +47,31 @@ def logout():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Add user registration
|
|
|
|
# TODO Add user registration
|
|
|
|
def register():
|
|
|
|
def register(settings: Settings, json_data: http.RequestData, session: Session):
|
|
|
|
pass
|
|
|
|
user_id = json_data.get('email')
|
|
|
|
|
|
|
|
password = json_data.get('password')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
email_check = session.query(User).filter_by(email=user_id).one_or_none()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if email_check is not None:
|
|
|
|
|
|
|
|
message = {
|
|
|
|
|
|
|
|
'status': 'error',
|
|
|
|
|
|
|
|
'message': 'user email address is already in use'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.Response(message, status=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user = User(email=user_id, password=password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session.add(user)
|
|
|
|
|
|
|
|
session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Send off an email confirmation
|
|
|
|
|
|
|
|
headers = {}
|
|
|
|
|
|
|
|
message = {
|
|
|
|
|
|
|
|
'status': 'success',
|
|
|
|
|
|
|
|
'message': 'Please check your inbox and confirm your email'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.Response(message, status=200, headers=headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Add user profile endpoint
|
|
|
|
# TODO Add user profile endpoint
|
|
|
@ -56,7 +80,7 @@ def user_profile():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Add email confirmation
|
|
|
|
# TODO Add email confirmation
|
|
|
|
def confirm():
|
|
|
|
def confirm(settings: Settings, json_data: http.RequestData, session: Session):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -66,7 +90,8 @@ def reset():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
routes = [
|
|
|
|
routes = [
|
|
|
|
Route('/login', 'POST', login)
|
|
|
|
Route('/login', 'POST', login),
|
|
|
|
|
|
|
|
Route('/register', 'POST', register)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
auth_routes = [Include('/auth', routes)]
|
|
|
|
auth_routes = [Include('/auth', routes)]
|
|
|
|