|
|
@ -9,12 +9,10 @@ from sqlalchemy.orm import Session
|
|
|
|
from sqlalchemy.orm.exc import NoResultFound
|
|
|
|
from sqlalchemy.orm.exc import NoResultFound
|
|
|
|
|
|
|
|
|
|
|
|
from cookie_api.models import User
|
|
|
|
from cookie_api.models import User
|
|
|
|
|
|
|
|
from cookie_api.schema import UserExportSchema, UserCreateSchema
|
|
|
|
from cookie_api.util import ExtJSONResponse
|
|
|
|
from cookie_api.util import ExtJSONResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# from cookie_api.schema import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def login(json_data: http.RequestData, session: Session, jwt: JWT):
|
|
|
|
def login(json_data: http.RequestData, session: Session, jwt: JWT):
|
|
|
|
user_id = json_data.get('email')
|
|
|
|
user_id = json_data.get('email')
|
|
|
|
password = json_data.get('password')
|
|
|
|
password = json_data.get('password')
|
|
|
@ -55,42 +53,42 @@ def logout():
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Add user registration
|
|
|
|
# TODO Add email confirmation to registration
|
|
|
|
# def register(user_rep: UserCreateSchema, session: Session, mail: Mail):
|
|
|
|
# def register(user_data: UserCreateSchema, session: Session, mail: Mail):
|
|
|
|
def register():
|
|
|
|
def register(user_data: UserCreateSchema, session: Session) -> UserExportSchema:
|
|
|
|
# email_check = session.query(User).filter_by(email=user_rep['email']).one_or_none()
|
|
|
|
email_check = session.query(User).filter_by(email=user_data['email']).one_or_none()
|
|
|
|
#
|
|
|
|
|
|
|
|
# if email_check is not None:
|
|
|
|
if email_check is not None:
|
|
|
|
# message = {
|
|
|
|
error = {
|
|
|
|
# 'status': 'error',
|
|
|
|
'status': 'error',
|
|
|
|
# 'message': 'user email address is already in use'
|
|
|
|
'message': 'user email address is already in use'
|
|
|
|
# }
|
|
|
|
}
|
|
|
|
# return http.Response(message, status=400)
|
|
|
|
return ExtJSONResponse(error, 400)
|
|
|
|
#
|
|
|
|
|
|
|
|
# user = User(email=user_rep['email'], password=user_rep['password'])
|
|
|
|
user = User(email=user_data['email'], password=user_data['password'])
|
|
|
|
#
|
|
|
|
|
|
|
|
# session.add(user)
|
|
|
|
session.add(user)
|
|
|
|
# session.commit()
|
|
|
|
session.commit()
|
|
|
|
#
|
|
|
|
|
|
|
|
# msg = Message("Thank you for registering please confirm your email", recipients=[user_rep['email']])
|
|
|
|
# msg = Message("Thank you for registering please confirm your email", recipients=[user_rep['email']])
|
|
|
|
# mail.send(msg)
|
|
|
|
# mail.send(msg)
|
|
|
|
#
|
|
|
|
|
|
|
|
# headers = {}
|
|
|
|
# headers = {}
|
|
|
|
# message = {
|
|
|
|
message = {
|
|
|
|
# 'status': 'success',
|
|
|
|
'status': 'success',
|
|
|
|
# 'message': 'Please check your inbox and confirm your email'
|
|
|
|
'message': 'Please check your inbox and confirm your email',
|
|
|
|
# }
|
|
|
|
'data': UserExportSchema(user)
|
|
|
|
# return http.Response(message, status=201, headers=headers)
|
|
|
|
}
|
|
|
|
pass
|
|
|
|
return ExtJSONResponse(message, 201)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def user_profile(user: JWTUser, session: Session): # -> UserSchema
|
|
|
|
def user_profile(user: JWTUser, session: Session) -> UserExportSchema:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
user = session.query(User).filter_by(id=user.id).one()
|
|
|
|
user = session.query(User).filter_by(id=user.id).one()
|
|
|
|
except NoResultFound as e:
|
|
|
|
except NoResultFound as e:
|
|
|
|
error = {'message': str(e)}
|
|
|
|
error = {'message': str(e)}
|
|
|
|
return ExtJSONResponse(error, 400)
|
|
|
|
return ExtJSONResponse(error, 400)
|
|
|
|
return ExtJSONResponse(user.to_dict())
|
|
|
|
return ExtJSONResponse(UserExportSchema(user))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Add email confirmation
|
|
|
|
# TODO Add email confirmation
|
|
|
@ -105,7 +103,7 @@ def reset():
|
|
|
|
|
|
|
|
|
|
|
|
routes = [
|
|
|
|
routes = [
|
|
|
|
Route('/login', 'POST', login),
|
|
|
|
Route('/login', 'POST', login),
|
|
|
|
# Route('/register', 'POST', register),
|
|
|
|
Route('/register', 'POST', register),
|
|
|
|
Route('/status', 'GET', user_profile)
|
|
|
|
Route('/status', 'GET', user_profile)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|