class User(Date, AbstractBaseUser, SoftDeletionModel): class Meta: db_table = 'users' objects = UserManager() REGULAR_USER_LEVEL = 'regular_user' SUPER_USER_LEVEL = 'super_user' USERNAME_FIELD = 'email' USER_LEVELS = [ (REGULAR_USER_LEVEL, 'Regular User'), (SUPER_USER_LEVEL, 'Super User'), ] first_name = models.CharField(max_length=128) last_name = models.CharField(max_length=128) email = models.EmailField(unique=True) password = models.CharField(max_length=256) level = models.CharField(max_length=32, default=REGULAR_USER_LEVEL, choices=USER_LEVELS) def get_str_representation(self): return { 'email': self.email, 'level': self.level, } def get_full_name(self): return self.first_name + self.last_name
class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=255, unique=True) is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=True) objects = UserManager() USERNAME_FIELD = 'email' def __repr__(self): return self.email def __str__(self): return self.__repr__()
class User(AbstractBaseUser, PermissionsMixin): username_validator = UnicodeUsernameValidator() username = models.CharField( _('username'), max_length=150, unique=True, help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'), validators=[username_validator], error_messages={ 'unique': _("A user with that username already exists."), }, ) is_staff = models.BooleanField( _('staff status'), default=False, help_text=_('Designates whether the user can log into this admin site.'), ) is_active = models.BooleanField( _('active'), default=True, help_text=_( 'Designates whether this user should be treated as active. ' 'Unselect this instead of deleting accounts.' ), ) date_joined = models.DateTimeField(_('date joined'), default=timezone.now) objects = UserManager() USERNAME_FIELD = 'username' def get_full_name(self): """ Return the first_name plus the last_name, with a space in between. """ return self.username def get_short_name(self): """Return the short name for the user.""" return self.username
import logging from flask_security import verify_password from marshmallow import validate, fields, validates, post_load from werkzeug.exceptions import Unauthorized, Forbidden from app.extensions import ma from app.managers import UserManager from config import Config logger = logging.getLogger(__name__) user_manager = UserManager() class AuthUserLoginSerializer(ma.Schema): email = fields.Str(load_only=True, required=True) password = fields.Str( load_only=True, required=True, validate=validate.Length(min=Config.SECURITY_PASSWORD_LENGTH_MIN, max=50), ) __user = None @validates('email') def validate_email(self, email): args = (user_manager.model.active == True, user_manager.model.deleted_at.is_null(),) self.__user = user_manager.find_by_email(email, *args) if self.__user is None:
def __init__(self, *args, **kwargs): super(UserService, self).__init__(*args, **kwargs) self.manager = UserManager() self.role_manager = RoleManager() self.user_serializer = UserSerializer()
def __init__(self): self.task_service = TaskService() self.user_manager = UserManager() self.auth_user_login_serializer = AuthUserLoginSerializer() self.auth_user_confirm_reset_password = AuthUserConfirmResetPasswordSerializer( )