"""User Model. The user model contains all the necessary information to save user information, and recover them (username, email address, password). The passwords are encrypted in the logic layer (make sure to call the logic layer to create a new user and not this directly). Please note: email addresses are not unique. The secondary global index on email allows duplicates. This is due to users having more than one account under the same email. """ from sukimu.dynamodb import IndexDynamo from sukimu.dynamodb import TableDynamo from sukimu.fields import Field from sukimu.schema import Index from sukimu.schema import Schema from auth import config from auth.connectors import dynamodb from auth.models import group from auth.models import validators User = Schema( TableDynamo(config.TABLE_USER, dynamodb.connection), # Some user like the ability to change their login information. This # becomes challening for all our other systems that rely on this # information. Instead, using an id always ensure it is unique enough. IndexDynamo( Index.PRIMARY, 'id', read_capacity=1, write_capacity=1), # The login is a unique string that defines a user. For now, this is what # we use across our different systems to login users. IndexDynamo( Index.GLOBAL, 'login', name='login_index', unique=True, read_capacity=1, write_capacity=1), # Email addresses are not unique in the system. A user can have more than # one account. We don't use email to perform login operations. IndexDynamo( Index.GLOBAL, 'email', name='email_index', unique=False, read_capacity=1, write_capacity=1), id=Field(required=True, basetype=str), login=Field(required=True, basetype=str), email=Field(required=True, basetype=str), password=Field(required=True, basetype=bytes), groups=Field(validators.only_contains(*group.ALL), basetype=list))