Coverage for src/typedal/web2py_py4web_shared.py: 100%
18 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-19 16:50 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-19 16:50 +0100
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 email = TypedField(str)
21 password = PasswordField(requires=[IS_STRONG(entropy=45), CRYPT()])
22 first_name = TypedField(str, requires=IS_NOT_EMPTY())
23 last_name = TypedField(str, requires=IS_NOT_EMPTY())
24 sso_id = TypedField(str)
25 action_token = TypedField(str)
26 last_password_change = TypedField(dt.datetime, default=dt.datetime.now)
27 registration_key = TypedField(str)
28 reset_password_key = TypedField(str)
29 registration_id = TypedField(str)
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 cls.email.requires = (
37 IS_EMAIL(),
38 IS_NOT_IN_DB(
39 db,
40 "auth_user.email",
41 ),
42 )