-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Invitations to register to product (#4739)
- Loading branch information
Showing
13 changed files
with
284 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
60 changes: 60 additions & 0 deletions
60
services/web/server/src/simcore_service_webserver/login/_auth_api.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from datetime import datetime | ||
|
||
from aiohttp import web | ||
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON | ||
|
||
from ..products.api import Product | ||
from ..security.api import check_password, encrypt_password | ||
from ._constants import MSG_UNKNOWN_EMAIL, MSG_WRONG_PASSWORD | ||
from .storage import AsyncpgStorage, get_plugin_storage | ||
from .utils import USER, get_user_name_from_email, validate_user_status | ||
|
||
|
||
async def get_user_by_email(app: web.Application, *, email: str) -> dict: | ||
db: AsyncpgStorage = get_plugin_storage(app) | ||
user: dict = await db.get_user({"email": email}) | ||
return user | ||
|
||
|
||
async def create_user( | ||
app: web.Application, | ||
*, | ||
email: str, | ||
password: str, | ||
status: str, | ||
expires_at: datetime | None | ||
) -> dict: | ||
db: AsyncpgStorage = get_plugin_storage(app) | ||
|
||
user: dict = await db.create_user( | ||
{ | ||
"name": get_user_name_from_email(email), | ||
"email": email, | ||
"password_hash": encrypt_password(password), | ||
"status": status, | ||
"role": USER, | ||
"expires_at": expires_at, | ||
} | ||
) | ||
return user | ||
|
||
|
||
async def check_authorized_user_or_raise( | ||
user: dict, | ||
password: str, | ||
product: Product, | ||
) -> dict: | ||
|
||
if not user: | ||
raise web.HTTPUnauthorized( | ||
reason=MSG_UNKNOWN_EMAIL, content_type=MIMETYPE_APPLICATION_JSON | ||
) | ||
|
||
validate_user_status(user=user, support_email=product.support_email) | ||
|
||
if not check_password(password, user["password_hash"]): | ||
raise web.HTTPUnauthorized( | ||
reason=MSG_WRONG_PASSWORD, content_type=MIMETYPE_APPLICATION_JSON | ||
) | ||
|
||
return user |
This file contains 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
This file contains 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
Oops, something went wrong.