-
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.
♻️ Is3318/refactoring websever.login plugin (2/3) (#3590)
- Loading branch information
Showing
46 changed files
with
1,937 additions
and
1,561 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
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 |
---|---|---|
|
@@ -13,8 +13,22 @@ | |
from _common import Error, Log | ||
from fastapi import FastAPI, status | ||
from models_library.generics import Envelope | ||
from pydantic import BaseModel, EmailStr, Field, SecretStr, confloat | ||
from pydantic import BaseModel, Field, confloat | ||
from simcore_service_webserver.login.api_keys_handlers import ApiKeyCreate, ApiKeyGet | ||
from simcore_service_webserver.login.handlers import Login2faBody, LoginBody, LogoutBody | ||
from simcore_service_webserver.login.handlers_change import ( | ||
ChangeEmailBody, | ||
ChangePasswordBody, | ||
ResetPasswordBody, | ||
) | ||
from simcore_service_webserver.login.handlers_confirmation import ( | ||
PhoneConfirmationBody, | ||
ResetPasswordConfirmation, | ||
) | ||
from simcore_service_webserver.login.handlers_registration import ( | ||
RegisterBody, | ||
RegisterPhoneBody, | ||
) | ||
|
||
app = FastAPI(redoc_url=None) | ||
|
||
|
@@ -23,103 +37,53 @@ | |
] | ||
|
||
|
||
class RegistrationCreate(BaseModel): | ||
email: EmailStr | ||
password: SecretStr | ||
confirm: Optional[SecretStr] = Field(None, description="Password confirmation") | ||
invitation: Optional[str] = Field(None, description="Invitation code") | ||
|
||
class Config: | ||
schema_extra = { | ||
"examples": [ | ||
{ | ||
"email": "[email protected]", | ||
"password": "my secret", | ||
"confirm": "my secret", | ||
"invitation": "33c451d4-17b7-4e65-9880-694559b8ffc2", | ||
} | ||
] | ||
} | ||
|
||
|
||
@app.post( | ||
"/auth/register", | ||
response_model=Envelope[Log], | ||
tags=TAGS, | ||
operation_id="auth_register", | ||
) | ||
async def register(registration: RegistrationCreate): | ||
async def register(registration: RegisterBody): | ||
"""User registration""" | ||
|
||
|
||
class Verify2FAPhone(BaseModel): | ||
email: EmailStr | ||
phone: str = Field( | ||
..., description="Phone number E.164, needed on the deployments with 2FA" | ||
) | ||
|
||
|
||
@app.post( | ||
"/auth/verify-phone-number", | ||
response_model=Envelope[Log], | ||
tags=TAGS, | ||
operation_id="auth_verify_2fa_phone", | ||
) | ||
async def register_phone(registration: Verify2FAPhone): | ||
async def register_phone(registration: RegisterPhoneBody): | ||
"""user tries to verify phone number for 2 Factor Authentication when registering""" | ||
|
||
|
||
class Validate2FAPhone(BaseModel): | ||
email: str | ||
phone: str = Field( | ||
..., description="Phone number E.164, needed on the deployments with 2FA" | ||
) | ||
code: str | ||
|
||
|
||
@app.post( | ||
"/auth/validate-code-register", | ||
response_model=Envelope[Log], | ||
tags=TAGS, | ||
operation_id="auth_validate_2fa_register", | ||
) | ||
async def phone_confirmation(confirmation: Validate2FAPhone): | ||
async def phone_confirmation(confirmation: PhoneConfirmationBody): | ||
"""user enters 2 Factor Authentication code when registering""" | ||
|
||
|
||
class LoginForm(BaseModel): | ||
email: Optional[str] = None | ||
password: Optional[str] = None | ||
|
||
|
||
class Login2FAForm(BaseModel): | ||
email: str | ||
code: str | ||
|
||
|
||
class LogoutRequest(BaseModel): | ||
client_session_id: Optional[str] = Field( | ||
None, example="5ac57685-c40f-448f-8711-70be1936fd63" | ||
) | ||
|
||
|
||
@app.post( | ||
"/auth/login", | ||
response_model=Envelope[Log], | ||
tags=TAGS, | ||
operation_id="auth_login", | ||
) | ||
async def login(authentication: LoginForm): | ||
async def login(authentication: LoginBody): | ||
"""user logs in""" | ||
|
||
|
||
@app.post( | ||
"/auth/validate-code-login", | ||
response_model=Envelope[Log], | ||
tags=TAGS, | ||
operation_id="auth_validate_2fa_login", | ||
operation_id="auth_login_2fa", | ||
) | ||
async def login_2fa(authentication: Login2FAForm): | ||
async def login_2fa(authentication: Login2faBody): | ||
"""user enters 2 Factor Authentication code when login in""" | ||
|
||
|
||
|
@@ -129,30 +93,21 @@ async def login_2fa(authentication: Login2FAForm): | |
tags=TAGS, | ||
operation_id="auth_logout", | ||
) | ||
async def logout(data: LogoutRequest): | ||
async def logout(data: LogoutBody): | ||
"""user logout""" | ||
|
||
|
||
class ResetPasswordRequest(BaseModel): | ||
email: str | ||
|
||
|
||
@app.post( | ||
"/auth/reset-password", | ||
response_model=Envelope[Log], | ||
tags=TAGS, | ||
operation_id="auth_reset_password", | ||
responses={status.HTTP_503_SERVICE_UNAVAILABLE: {"model": Envelope[Error]}}, | ||
) | ||
async def reset_password(data: ResetPasswordRequest): | ||
async def reset_password(data: ResetPasswordBody): | ||
"""a non logged-in user requests a password reset""" | ||
|
||
|
||
class ResetPasswordForm(BaseModel): | ||
password: str | ||
confirm: str | ||
|
||
|
||
@app.post( | ||
"/auth/reset-password/{code}", | ||
response_model=Envelope[Log], | ||
|
@@ -165,14 +120,10 @@ class ResetPasswordForm(BaseModel): | |
} | ||
}, | ||
) | ||
async def reset_password_allowed(code: str, data: ResetPasswordForm): | ||
async def reset_password_allowed(code: str, data: ResetPasswordConfirmation): | ||
"""changes password using a token code without being logged in""" | ||
|
||
|
||
class ChangeEmailForm(BaseModel): | ||
email: str | ||
|
||
|
||
@app.post( | ||
"/auth/change-email", | ||
response_model=Envelope[Log], | ||
|
@@ -189,16 +140,10 @@ class ChangeEmailForm(BaseModel): | |
}, | ||
}, | ||
) | ||
async def change_email(data: ChangeEmailForm): | ||
async def change_email(data: ChangeEmailBody): | ||
"""logged in user changes email""" | ||
|
||
|
||
class ChangePasswordForm(BaseModel): | ||
current: str | ||
new: str | ||
confirm: str | ||
|
||
|
||
class PasswordCheckSchema(BaseModel): | ||
strength: confloat(ge=0.0, le=1.0) = Field( # type: ignore | ||
..., | ||
|
@@ -230,7 +175,7 @@ class PasswordCheckSchema(BaseModel): | |
}, | ||
}, | ||
) | ||
async def change_password(data: ChangePasswordForm): | ||
async def change_password(data: ChangePasswordBody): | ||
"""logged in user changes password""" | ||
|
||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.12.0 | ||
0.12.2 |
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.