feature/migrations, closes #19 #20
|
@ -13,15 +13,15 @@ lifetime = 1800
|
||||||
|
|
||||||
def __get_user_agent_platform(ua: str):
|
def __get_user_agent_platform(ua: str):
|
||||||
if "Win" in ua:
|
if "Win" in ua:
|
||||||
return "Windows"
|
return "windows"
|
||||||
if "Mac" in ua:
|
if "Mac" in ua:
|
||||||
return "Macintosh"
|
return "macintosh"
|
||||||
if "Linux" in ua:
|
if "Linux" in ua:
|
||||||
return "Linux"
|
return "linux"
|
||||||
if "Android" in ua:
|
if "Android" in ua:
|
||||||
return "Android"
|
return "android"
|
||||||
if "like Mac" in ua:
|
if "like Mac" in ua:
|
||||||
return "iOS"
|
return "ios"
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,12 +84,12 @@ def validate_token(token, request_headers, permission):
|
||||||
raise Unauthorized
|
raise Unauthorized
|
||||||
|
|
||||||
|
|
||||||
def create(user, user_agent=None) -> Session:
|
def create(user, request_headers=None) -> Session:
|
||||||
"""Create a Session
|
"""Create a Session
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user: For which User is to create a Session
|
user: For which User is to create a Session
|
||||||
user_agent: User agent to identify session
|
request_headers: Headers to validate user agent of browser
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Session: A created Token for User
|
Session: A created Token for User
|
||||||
|
@ -100,8 +100,10 @@ def create(user, user_agent=None) -> Session:
|
||||||
token=token_str,
|
token=token_str,
|
||||||
user_=user,
|
user_=user,
|
||||||
lifetime=lifetime,
|
lifetime=lifetime,
|
||||||
browser=user_agent.browser,
|
platform=request_headers.get("Sec-CH-UA-Platform", None)
|
||||||
platform=user_agent.platform,
|
or __get_user_agent_platform(request_headers.get("User-Agent", "")),
|
||||||
|
browser=request_headers.get("Sec-CH-UA", None)
|
||||||
|
or __get_user_agent_browser(request_headers.get("User-Agent", "")),
|
||||||
)
|
)
|
||||||
session.refresh()
|
session.refresh()
|
||||||
db.session.add(session)
|
db.session.add(session)
|
||||||
|
|
|
@ -40,7 +40,7 @@ def login():
|
||||||
user = userController.login_user(userid, password)
|
user = userController.login_user(userid, password)
|
||||||
if not user:
|
if not user:
|
||||||
raise Unauthorized
|
raise Unauthorized
|
||||||
session = sessionController.create(user, user_agent=request.user_agent)
|
session = sessionController.create(user, request_headers=request.headers)
|
||||||
logger.debug(f"token is {session.token}")
|
logger.debug(f"token is {session.token}")
|
||||||
logger.info(f"User {userid} logged in.")
|
logger.info(f"User {userid} logged in.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue