def login():
email, pw = strip_creds_from_req(request.data)
if not email or not pw:
return rh.error(**ec.INCOMPLETE_LOGIN_CREDS)
user = find(User, dict(email=email, password=pw))
if not user: return rh.error(**ec.USER_NOT_FOUND)
try:
session = create(Session, dict(user_id=user.id))
return rh.json_response(with_cookie=(cookie_name, session.token))
except Exception as e:
app.logger.error('Error logging in existing user with email: {}, with error: {}'.format(email, e))
return rh.error(**ec.USER_LOGIN_ERROR)
评论列表
文章目录