class Comment(EmbeddedDocument): created_at = fields.DateTimeField( default=datetime.datetime.now, editable=False, ) author = fields.StringField(verbose_name="Name", max_length=255) email = fields.EmailField(verbose_name="Email", blank=True) body = fields.StringField(verbose_name="Comment")
class Users(Document): created_at = fields.DateTimeField( default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), required=True, editable=False,unique=False ) user_id = fields.StringField(max_length=36,required=True,unique=True) username = fields.StringField(unique=True, max_length=30) email_id = fields.EmailField(unique=True, max_length=254) first_name = fields.StringField(max_length=30, required=False, allow_null=True,unique=False) last_name = fields.StringField(max_length=30, required=False, null=True,unique=False) profile_url = fields.StringField( default = "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif",unique=False ) followed_users_list = fields.EmbeddedDocumentListField(FollowingList, required=False, default= [], blank=True,unique=False) follower_users_list = fields.EmbeddedDocumentListField(FollowerList, required=False, default= [], blank=True,unique=False) gender = fields.StringField(default=None,unique=False, blank=True, required=False) push_notifications = fields.BooleanField(default=True, unique=False) token = fields.StringField(default=None, blank=True) # phone_number = fields.StringField(min_length=10, max_length=10,blank=True, default=None, required=False) notifications = fields.EmbeddedDocumentListField(Notifications, required=False, default= [], blank=True,unique=False) is_unread_notification = fields.BooleanField(default=False) user_bio = fields.StringField(default=None,unique=False, blank=True, required=False) favorite_genre = fields.StringField(default=None,unique=False, blank=True, required=False) favorite_artist = fields.StringField(default=None,unique=False, blank=True, required=False) favorite_instrument = fields.StringField(default=None,unique=False, blank=True, required=False) farorite_album = fields.StringField(default=None,unique=False, blank=True, required=False) date_of_birth = fields.StringField(default=None,blank=True, required=False) gender = fields.StringField(default=None,blank=True, required=False) pending_requests = fields.EmbeddedDocumentListField(PendingRequests, required=False, default= [], blank=True,unique=False) requested_users = fields.EmbeddedDocumentListField(RequestedUsers, required=False, default= [], blank=True,unique=False)
class ContactMessage(Document): """Represents a message sent via the Contact form""" name = fields.StringField(max_length=100) email = fields.EmailField() content = fields.StringField() @staticmethod def get_by_id(message_id): """Get a message using its primary key Args: message_id: Returns: """ try: return ContactMessage.objects().get(pk=str(message_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_all(): """Get all messages Returns: """ return ContactMessage.objects.all()
class UserLoginSerializer(serializers.DocumentSerializer): username = fields.StringField(max_length=50, blank=True) email = fields.EmailField(label="Email Address", blank=True) class Meta: model = User fields = ('username', 'email', 'password') extra_kwargs = {"password": {"write_only": True}} def validated_data(self, data): user_obj = None email = data.get("email", None) username = data.get("username", None) password = data["password"] if not email and not username: raise ValidationError("A Username or email is required to login.") user = User.objects.filter(Q(email=email) | Q(username=username)) if user and user.count() == 1: user_obj = user.first() else: raise ValidationError("This Username/Email is not valid!") if user_obj: if not user_obj.password == password: raise ValidationError( "Incorrect credentials please try again.") return data
class UserCreateSerializer(serializers.DocumentSerializer): email2 = fields.EmailField(label='Confirm Email') class Meta: model = User fields = ('username', 'email', 'password') extra_kwargs = {"password": {"write_only": True}} def validate_email(self, value): data = self.get_initial() email1 = data.get("email") email2 = value if email1 != email2: raise ValidationError("Emails must match.") user_qs = User.objects.filter(email=email2) if user_qs: raise ValidationError("This user has already registered.") return value def create(self, validated_data): username = validated_data['username'] email = validated_data['email'] password = validated_data['password'] user_obj = User(username=username, email=email, password=password) #user_obj.set_password(password) user_obj.save() return validated_data
class User(Document): name = fields.StringField() username = fields.StringField(unique=True) email = fields.EmailField(unique=True) # these 2 fields are NOT TO BE FILLED ratings = fields.IntField(default=0) date_joined = fields.DateTimeField(default=timezone.now, editable=False) gears = fields.ListField(fields.ReferenceField('Gear'), default=[], blank=True) password = fields.StringField(min_length=8, max_length=128) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['name', 'email', 'password'] def __str__(self): return self.username def get_username(self): return self.username def get_name(self): return self.name def get_ratings(self): return self.ratings def is_active(self): return True def check_password(self, raw_password): """ Checks the password if it matches the stored password """ return check_password(raw_password, self.password)
class UpdateBasicInfo(Document): user_id = fields.StringField(max_length=36,required=True,unique=False) profile_url = fields.StringField( default = "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif",unique=False, required=True ) user_bio = fields.StringField(default=None,unique=False, blank=True, required=False) favorite_genre = fields.StringField(default=None,unique=False, blank=True, required=False) favorite_artist = fields.StringField(default=None,unique=False, blank=True, required=False) date_of_birth = fields.StringField(default=None,blank=True, required=False) gender = fields.StringField(default=None,blank=True, required=False) username = fields.StringField(max_length=16, required=True) password = fields.StringField(max_length=32, required=True) email_id = fields.EmailField(required=True) first_name = fields.StringField(max_length=30, required=False, allow_null=True,unique=False) last_name = fields.StringField(max_length=30, required=False, null=True,unique=False)
class User(Document): email = fields.EmailField( verbose_name='email address', max_length=255, unique=True, ) username = fields.StringField(max_length=50, unique=True) password = fields.StringField(max_length=128, verbose_name=('password')) is_active = fields.BooleanField(default=True) is_staff = fields.BooleanField(default=False) is_admin = fields.BooleanField(default=False) is_superuser = fields.BooleanField(default=False) last_login = fields.DateTimeField(default=datetime.now, verbose_name=('last login')) date_joined = fields.DateTimeField(default=datetime.now, verbose_name=('date joined')) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ["email"] #objects= UserManager() def __str__(self): return self.username def set_password(self, raw_password): self.password = make_password(raw_password) self.save() return self @classmethod def create_user(cls, username, password, email): now = datetime.datetime.now() if email is not None: try: email_name, domain_part = email.strip().split('@', 1) except ValueError: pass else: email = '@'.join([email_name, domain_part.lower()]) user = cls(username=username, email=email, date_joined=now) user.set_password(password) user.save() return user
class ContactMessage(Document): """Represents a message sent via the Contact form""" name = fields.StringField(max_length=100) email = fields.EmailField() content = fields.StringField() @staticmethod def get_by_id(message_id): """ Get a message using its primary key Args: message_id: Returns: """ return ContactMessage.objects().get(pk=str(message_id)) @staticmethod def get_all(): """ Get all messages Returns: """ return ContactMessage.objects.all()
class User(document.Document): """A User document that aims to mirror most of the API specified by Django at http://docs.djangoproject.com/en/dev/topics/auth/#users """ username = fields.StringField( max_length=30, required=True, verbose_name=_('username'), help_text= _("Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters" )) first_name = fields.StringField(max_length=30, verbose_name=_('first name')) last_name = fields.StringField(max_length=30, verbose_name=_('last name')) email = fields.EmailField(verbose_name=_('e-mail address')) password = fields.StringField( max_length=128, verbose_name=_('password'), help_text= _("Use '[algo]$[iterations]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>." )) is_staff = fields.BooleanField( default=False, verbose_name=_('staff status'), help_text=_( "Designates whether the user can log into this admin site.")) is_active = fields.BooleanField( default=True, verbose_name=_('active'), help_text= _("Designates whether this user should be treated as active. Unselect this instead of deleting accounts." )) is_superuser = fields.BooleanField( default=False, verbose_name=_('superuser status'), help_text= _("Designates that this user has all permissions without explicitly assigning them." )) last_login = fields.DateTimeField(default=timezone.now, verbose_name=_('last login')) date_joined = fields.DateTimeField(default=timezone.now, verbose_name=_('date joined')) user_permissions = fields.ListField( fields.ReferenceField(Permission), verbose_name=_('user permissions'), help_text=_('Permissions for the user.')) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['email'] meta = { 'allow_inheritance': True, 'indexes': [{ 'fields': ['username'], 'unique': True, 'sparse': True }] } def __unicode__(self): return self.username def get_full_name(self): """Returns the users first and last names, separated by a space. """ full_name = u'%s %s' % (self.first_name or '', self.last_name or '') return full_name.strip() def is_anonymous(self): return False def is_authenticated(self): return True def set_password(self, raw_password): """Sets the user's password - always use this rather than directly assigning to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ self.password = make_password(raw_password) self.save() return self def check_password(self, raw_password): """Checks the user's password against a provided password - always use this rather than directly comparing to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ return check_password(raw_password, self.password) @classmethod def create_user(cls, username, password, email=None): """Create (and save) a new user with the given username, password and email address. """ now = timezone.now() # Normalize the address by lowercasing the domain part of the email # address. if email is not None: try: email_name, domain_part = email.strip().split('@', 1) except ValueError: pass else: email = '@'.join([email_name, domain_part.lower()]) user = cls(username=username, email=email, date_joined=now) user.set_password(password) user.save() return user def get_group_permissions(self, obj=None): """ Returns a list of permission strings that this user has through his/her groups. This method queries all available auth backends. If an object is passed in, only permissions matching this object are returned. """ permissions = set() for backend in auth.get_backends(): if hasattr(backend, "get_group_permissions"): permissions.update(backend.get_group_permissions(self, obj)) return permissions def get_all_permissions(self, obj=None): return _user_get_all_permissions(self, obj) def has_perm(self, perm, obj=None): """ Returns True if the user has the specified permission. This method queries all available auth backends, but returns immediately if any backend returns True. Thus, a user who has permission from a single auth backend is assumed to have permission in general. If an object is provided, permissions for this specific object are checked. """ # Active superusers have all permissions. if self.is_active and self.is_superuser: return True # Otherwise we need to check the backends. return _user_has_perm(self, perm, obj) def has_module_perms(self, app_label): """ Returns True if the user has any permissions in the given app label. Uses pretty much the same logic as has_perm, above. """ # Active superusers have all permissions. if self.is_active and self.is_superuser: return True return _user_has_module_perms(self, app_label) def email_user(self, subject, message, from_email=None): "Sends an e-mail to this User." from django.core.mail import send_mail send_mail(subject, message, from_email, [self.email]) def get_profile(self): """ Returns site-specific profile for this user. Raises SiteProfileNotAvailable if this site does not allow profiles. """ if not hasattr(self, '_profile_cache'): from django.conf import settings if not getattr(settings, 'AUTH_PROFILE_MODULE', False): raise SiteProfileNotAvailable('You need to set AUTH_PROFILE_MO' 'DULE in your project settings') try: app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') except ValueError: raise SiteProfileNotAvailable( 'app_label and model_name should' ' be separated by a dot in the AUTH_PROFILE_MODULE set' 'ting') try: model = models.get_model(app_label, model_name) if model is None: raise SiteProfileNotAvailable( 'Unable to load the profile ' 'model, check AUTH_PROFILE_MODULE in your project sett' 'ings') self._profile_cache = model._default_manager.using( self._state.db).get(user__id__exact=self.id) self._profile_cache.user = self except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable return self._profile_cache
class User(document.Document): """A User document that aims to mirror most of the API specified by Django at http://docs.djangoproject.com/en/dev/topics/auth/#users """ username = fields.StringField( max_length=30, required=True, verbose_name=_('username'), help_text=_("""Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters""")) first_name = fields.StringField(max_length=30, verbose_name=_('first name')) last_name = fields.StringField(max_length=30, verbose_name=_('last name')) email = fields.EmailField(verbose_name=_('e-mail address')) password = fields.StringField(max_length=128, verbose_name=_('password'), help_text=_("""Use '[algo]$[iterations]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.""")) is_staff = fields.BooleanField( default=False, verbose_name=_('staff status'), help_text=_("""Designates whether the user can log into this admin site.""")) is_active = fields.BooleanField( default=True, verbose_name=_('active'), help_text=_("""Designates whether this user should be treated as active. Unselect this instead of deleting accounts.""")) is_superuser = fields.BooleanField( default=False, verbose_name=_('superuser status'), help_text=_("""Designates that this user has all permissions without explicitly assigning them.""")) last_login = fields.DateTimeField(default=datetime.datetime.now, verbose_name=_('last login')) date_joined = fields.DateTimeField(default=datetime.datetime.now, verbose_name=_('date joined')) meta = { 'allow_inheritance': True, 'indexes': [{ 'fields': ['username'], 'unique': True }] } def __unicode__(self): return self.username def get_full_name(self): """Returns the users first and last names, separated by a space. """ full_name = u'%s %s' % (self.first_name or '', self.last_name or '') return full_name.strip() def is_anonymous(self): return False def is_authenticated(self): return True def set_password(self, raw_password): """Sets the user's password - always use this rather than directly assigning to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ self.password = make_password(raw_password) self.save() return self def check_password(self, raw_password): """Checks the user's password against a provided password - always use this rather than directly comparing to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ return check_password(raw_password, self.password) @classmethod def create_user(cls, username, email, password): """Create (and save) a new user with the given username, password and email address. """ now = datetime.datetime.now() # Normalize the address by lowercasing the domain part of the email # address. if email is not None: try: email_name, domain_part = email.strip().split('@', 1) except ValueError: pass else: email = '@'.join([email_name, domain_part.lower()]) user = cls(username=username, email=email, date_joined=now) user.set_password(password) user.save() return user @classmethod def create_superuser(cls, username, email, password): u = cls.create_user(username, email, password) u.update(set__is_staff=True, set__is_active=True, set__is_superuser=True) return u def get_and_delete_messages(self): return [] def has_perm(self, perm, obj=None): return True def has_perms(self, perm_list, obj=None): return True def has_module_perms(self, app_label): return True
class ForgotPassword(Document): email_id = fields.EmailField(required=True)
class AbstractUser(BaseUser, document.Document): """A User document that aims to mirror most of the API specified by Django at http://docs.djangoproject.com/en/dev/topics/auth/#users """ username = fields.StringField( max_length=150, verbose_name=_("username"), help_text= _("Required. 150 characters or fewer. Letters, numbers and @/./+/-/_ characters" ), ) first_name = fields.StringField(max_length=30, blank=True, verbose_name=_("first name")) last_name = fields.StringField(max_length=30, blank=True, verbose_name=_("last name")) email = fields.EmailField(verbose_name=_("e-mail address"), blank=True) password = fields.StringField( max_length=128, verbose_name=_("password"), help_text= _("Use '[algo]$[iterations]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>." ), ) is_staff = fields.BooleanField( default=False, verbose_name=_("staff status"), help_text=_( "Designates whether the user can log into this admin site."), ) is_active = fields.BooleanField( default=True, verbose_name=_("active"), help_text= _("Designates whether this user should be treated as active. Unselect this instead of deleting accounts." ), ) is_superuser = fields.BooleanField( default=False, verbose_name=_("superuser status"), help_text= _("Designates that this user has all permissions without explicitly assigning them." ), ) last_login = fields.DateTimeField(default=timezone.now, verbose_name=_("last login")) date_joined = fields.DateTimeField(default=timezone.now, verbose_name=_("date joined")) user_permissions = fields.ListField( fields.ReferenceField(Permission), verbose_name=_("user permissions"), blank=True, help_text=_("Permissions for the user."), ) USERNAME_FIELD = getattr(settings, "MONGOENGINE_USERNAME_FIELDS", "username") REQUIRED_FIELDS = getattr(settings, "MONGOENGINE_USER_REQUIRED_FIELDS", ["email"]) meta = { "abstract": True, "indexes": [{ "fields": ["username"], "unique": True, "sparse": True }], } def __unicode__(self): return self.username def get_full_name(self): """Returns the users first and last names, separated by a space. """ full_name = u"%s %s" % (self.first_name or "", self.last_name or "") return full_name.strip() def set_password(self, raw_password): """Sets the user's password - always use this rather than directly assigning to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ self.password = make_password(raw_password) self.save() return self def check_password(self, raw_password): """Checks the user's password against a provided password - always use this rather than directly comparing to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ return check_password(raw_password, self.password) @classmethod def _create_user(cls, username, password, email=None, create_superuser=False): """Create (and save) a new user with the given username, password and email address. """ now = timezone.now() # Normalize the address by lowercasing the domain part of the email # address. if email is not None: try: email_name, domain_part = email.strip().split("@", 1) except ValueError: pass else: email = "@".join([email_name, domain_part.lower()]) user = cls(username=username, email=email, date_joined=now) user.set_password(password) if create_superuser: user.is_staff = True user.is_superuser = True user.save() return user @classmethod def create_user(cls, username, password, email=None): return cls._create_user(username, password, email) @classmethod def create_superuser(cls, username, password, email=None): return cls._create_user(username, password, email, create_superuser=True) def get_group_permissions(self, obj=None): """ Returns a list of permission strings that this user has through his/her groups. This method queries all available auth backends. If an object is passed in, only permissions matching this object are returned. """ permissions = set() for backend in auth.get_backends(): if hasattr(backend, "get_group_permissions"): permissions.update(backend.get_group_permissions(self, obj)) return permissions def get_all_permissions(self, obj=None): return _user_get_all_permissions(self, obj) def has_perm(self, perm, obj=None): """ Returns True if the user has the specified permission. This method queries all available auth backends, but returns immediately if any backend returns True. Thus, a user who has permission from a single auth backend is assumed to have permission in general. If an object is provided, permissions for this specific object are checked. """ # Active superusers have all permissions. if self.is_active and self.is_superuser: return True # Otherwise we need to check the backends. return _user_has_perm(self, perm, obj) def has_perms(self, perm_list, obj=None): """ Returns True if the user has each of the specified permissions. If object is passed, it checks if the user has all required perms for this object. """ for perm in perm_list: if not self.has_perm(perm, obj): return False return True def has_module_perms(self, app_label): """ Returns True if the user has any permissions in the given app label. Uses pretty much the same logic as has_perm, above. """ # Active superusers have all permissions. if self.is_active and self.is_superuser: return True return _user_has_module_perms(self, app_label) def email_user(self, subject, message, from_email=None): "Sends an e-mail to this User." from django.core.mail import send_mail send_mail(subject, message, from_email, [self.email]) def get_profile(self): """ Returns site-specific profile for this user. Raises SiteProfileNotAvailable if this site does not allow profiles. """ if not hasattr(self, "_profile_cache"): if not getattr(settings, "AUTH_PROFILE_MODULE", False): raise SiteProfileNotAvailable("You need to set AUTH_PROFILE_MO" "DULE in your project settings") try: app_label, model_name = settings.AUTH_PROFILE_MODULE.split(".") except ValueError: raise SiteProfileNotAvailable( "app_label and model_name should" " be separated by a dot in the AUTH_PROFILE_MODULE set" "ting") try: model = models.get_model(app_label, model_name) if model is None: raise SiteProfileNotAvailable( "Unable to load the profile " "model, check AUTH_PROFILE_MODULE in your project sett" "ings") self._profile_cache = model._default_manager.using( self._state.db).get(user__id__exact=self.id) self._profile_cache.user = self except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable return self._profile_cache
class User(document.Document): SEXO_HOMBRE = 'masculino' SEXO_MUJER = 'femenino' SEXOS = ((None, 'No definido'), (SEXO_HOMBRE, 'Masculino'), (SEXO_MUJER, 'Femenino')) """A User document that aims to mirror most of the API specified by Django at http://docs.djangoproject.com/en/dev/topics/auth/#users """ username = fields.StringField( max_length=250, verbose_name=('username'), help_text= ("Required. 250 characters or fewer. Letters, numbers and @/./+/-/_ characters" ), required=False) first_name = fields.StringField( max_length=250, blank=True, verbose_name=('first name'), ) last_name = fields.StringField(max_length=250, blank=True, verbose_name=('last name')) email = fields.EmailField(verbose_name=('e-mail address'), blank=False) password = fields.StringField( blank=True, max_length=128, verbose_name=('password'), help_text= ("Use '[algo]$[iterations]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>." )) is_staff = fields.BooleanField( default=False, verbose_name=('staff status'), help_text=( "Designates whether the user can log into this admin site.")) is_active = fields.BooleanField( default=True, verbose_name=('active'), help_text= ("Designates whether this user should be treated as active. Unselect this instead of deleting accounts." )) is_superuser = fields.BooleanField( default=False, verbose_name=('superuser status'), help_text= ("Designates that this user has all permissions without explicitly assigning them." )) last_login = fields.DateTimeField(default=timezone.now, verbose_name=('last login')) date_joined = fields.DateTimeField(default=timezone.now, verbose_name=('date joined')) user_permissions = fields.ListField( fields.ReferenceField(Permission), verbose_name=('user permissions'), blank=True, help_text=('Permissions for the user.')) birthdate = DateField(blank=True) # image = LocalStorageFileField(upload_to='users/') web_url = fields.URLField(blank=True) facebook_page = fields.URLField(blank=True) youtube_channel = fields.URLField(blank=True) genere = fields.StringField(choices=SEXOS, required=False, blank=True) is_complete = fields.BooleanField(default=False) providers = fields.ListField(fields.EmbeddedDocumentField('Provider'), blank=True) photo_url = fields.URLField(blank=True) uid = fields.StringField(blank=False, required=True) display_name = fields.StringField(blank=True) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['email'] meta = { 'allow_inheritance': True, 'indexes': [{ 'fields': ['username'], 'unique': True, 'sparse': True }] } def __unicode__(self): return self.username def get_full_name(self): """Returns the users first and last names, separated by a space. """ full_name = u'%s %s' % (self.first_name or '', self.last_name or '') return full_name.strip() def is_anonymous(self): return False def is_authenticated(self): return True def set_password(self, raw_password): """Sets the user's password - always use this rather than directly assigning to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ self.password = make_password(raw_password) self.save() return self def check_password(self, raw_password): """Checks the user's password against a provided password - always use this rather than directly comparing to :attr:`~mongoengine.django.auth.User.password` as the password is hashed before storage. """ return check_password(raw_password, self.password) @classmethod def create_user(cls, username, password, email=None): """Create (and save) a new user with the given username, password and email address. """ now = timezone.now() # Normalize the address by lowercasing the domain part of the email # address. if email is not None: try: email_name, domain_part = email.strip().split('@', 1) except ValueError: pass else: email = '@'.join([email_name, domain_part.lower()]) user = cls(username=username, email=email, date_joined=now) user.set_password(password) user.save() return user def get_group_permissions(self, obj=None): """ Returns a list of permission strings that this user has through his/her groups. This method queries all available auth backends. If an object is passed in, only permissions matching this object are returned. """ permissions = set() for backend in auth.get_backends(): if hasattr(backend, "get_group_permissions"): permissions.update(backend.get_group_permissions(self, obj)) return permissions def get_all_permissions(self, obj=None): return _user_get_all_permissions(self, obj) def has_perm(self, perm, obj=None): """ Returns True if the user has the specified permission. This method queries all available auth backends, but returns immediately if any backend returns True. Thus, a user who has permission from a single auth backend is assumed to have permission in general. If an object is provided, permissions for this specific object are checked. """ # Active superusers have all permissions. if self.is_active and self.is_superuser: return True # Otherwise we need to check the backends. return _user_has_perm(self, perm, obj) def has_module_perms(self, app_label): """ Returns True if the user has any permissions in the given app label. Uses pretty much the same logic as has_perm, above. """ # Active superusers have all permissions. if self.is_active and self.is_superuser: return True return _user_has_module_perms(self, app_label) def email_user(self, subject, message, from_email=None): "Sends an e-mail to this User." from django.core.mail import send_mail send_mail(subject, message, from_email, [self.email])
class Provider(document.EmbeddedDocument): uid = fields.StringField() display_name = fields.StringField(blank=True) photo_url = fields.URLField(blank=True) email = fields.EmailField(blank=False) provider_id = fields.StringField(blank=False)