Skip to content

Commit

Permalink
Check if mail is verified for login
Browse files Browse the repository at this point in the history
  • Loading branch information
bguillot committed Sep 24, 2024
1 parent 5ea75ac commit e388aa4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fastapi_auth_partner/models/fastapi_auth_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class FastApiAuthDirectory(models.Model):
groups="fastapi_auth_partner.group_partner_auth_manager",
)
sliding_session = fields.Boolean()
force_verified_email = fields.Boolean(
help="If checked, email must be verified to be able to log in"
)

def _compute_count_partner(self):
data = self.env["fastapi.auth.partner"].read_group(

Check warning on line 81 in fastapi_auth_partner/models/fastapi_auth_directory.py

View check run for this annotation

Codecov / codecov/patch

fastapi_auth_partner/models/fastapi_auth_directory.py#L81

Added line #L81 was not covered by tests
Expand Down
8 changes: 8 additions & 0 deletions fastapi_auth_partner/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def _login(self, directory, data):
.log_in(directory, data.login.lower(), data.password)
)
if partner_auth:
if directory.force_verified_email and not partner_auth.mail_verified:
raise AccessError(

Check warning on line 176 in fastapi_auth_partner/routers/auth.py

View check run for this annotation

Codecov / codecov/patch

fastapi_auth_partner/routers/auth.py#L176

Added line #L176 was not covered by tests
_(
"Email address not validated. Validate your email address by "
"clicking on the link in the email sent to you or request a new "
"password. "
)
)
return partner_auth
else:
raise AccessError(_("Invalid Login or Password"))

Check warning on line 185 in fastapi_auth_partner/routers/auth.py

View check run for this annotation

Codecov / codecov/patch

fastapi_auth_partner/routers/auth.py#L185

Added line #L185 was not covered by tests
Expand Down
1 change: 1 addition & 0 deletions fastapi_auth_partner/views/fastapi_auth_directory_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<field name="cookie_duration" />
<field name="sliding_session" />
<field name="set_password_token_duration" />
<field name="force_verified_email" />
</group>
<group
name="impersonate"
Expand Down

0 comments on commit e388aa4

Please sign in to comment.