Coverage for src/typedal/web2py_py4web_shared.py: 100%
19 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-08-05 19:10 +0200
« prev ^ index » next coverage.py v7.5.1, created at 2024-08-05 19:10 +0200
1"""
2Both py4web and web2py can share this Auth User table definition.
3"""
5import datetime as dt
7from pydal.validators import CRYPT, IS_EMAIL, IS_NOT_EMPTY, IS_NOT_IN_DB, IS_STRONG
9from .core import TypeDAL, TypedField, TypedTable
10from .fields import PasswordField
13class AuthUser(TypedTable):
14 """
15 Class for db.auth_user in py4web and web2py.
16 """
18 # call db.define with redefine=True and migrate=False on this when ready
20 first_name = TypedField(str, requires=IS_NOT_EMPTY())
21 last_name = TypedField(str, requires=IS_NOT_EMPTY())
22 email = TypedField(str)
23 password = PasswordField(requires=[IS_STRONG(entropy=45), CRYPT()])
24 sso_id = TypedField(str, readable=False, writable=False, notnull=False)
25 action_token = TypedField(str, readable=False, writable=False, notnull=False)
26 last_password_change = TypedField(dt.datetime, default=dt.datetime.now, readable=False, writable=False)
27 registration_key = TypedField(str, readable=False, writable=False, notnull=False)
28 reset_password_key = TypedField(str, readable=False, writable=False, notnull=False)
29 registration_id = TypedField(str, readable=False, writable=False, notnull=False)
31 @classmethod
32 def __on_define__(cls, db: TypeDAL) -> None:
33 """
34 When we have access to 'db', set the IS_NOT_IN_DB requirement.
35 """
36 super().__on_define__(db)
38 cls.email.requires = (
39 IS_EMAIL(),
40 IS_NOT_IN_DB(
41 db,
42 "auth_user.email",
43 ),
44 )