class Subscriber(db.DynamicDocument): name = db.StringField() email = db.EmailField() document = db.StringField() phone = db.StringField() address = db.StringField() user = db.ReferenceField('User', default=get_current_user, reverse_delete_rule=db.NULLIFY) def __unicode__(self): return self.name
class User(db.DynamicDocument, UserMixin): name = db.StringField(max_length=255) email = db.EmailField(max_length=255, unique=True) password = db.StringField(max_length=255) active = db.BooleanField(default=True) confirmed_at = db.DateTimeField() roles = db.ListField( db.ReferenceField(Role, reverse_delete_rule=db.DENY), default=[] ) last_login_at = db.DateTimeField() current_login_at = db.DateTimeField() last_login_ip = db.StringField(max_length=255) current_login_ip = db.StringField(max_length=255) login_count = db.IntField() username = db.StringField(max_length=50, required=False, unique=True) def clean(self, *args, **kwargs): if not self.username: self.username = User.generate_username(self.email) try: super(User, self).clean(*args, **kwargs) except: pass @classmethod def generate_username(cls, email): username = email.lower() for item in ['@', '.', '-', '+']: username = username.replace(item, '_') return username @classmethod def createuser(cls, name, email, password, active=True, roles=None, username=None): username = username or cls.generate_username(email) return cls.objects.create( name=name, email=email, password=encrypt_password(password), active=active, roles=roles, username=username ) def __unicode__(self): return "{0} <{1}>".format(self.name or '', self.email)
class User(db.DynamicDocument, UserMixin): name = db.StringField(max_length=255) email = db.EmailField(max_length=255, unique=True) password = db.StringField(max_length=255) active = db.BooleanField(default=True) confirmed_at = db.DateTimeField() roles = db.ListField(db.ReferenceField(Role, reverse_delete_rule=db.DENY), default=[]) last_login_at = db.DateTimeField() current_login_at = db.DateTimeField() last_login_ip = db.StringField(max_length=255) current_login_ip = db.StringField(max_length=255) login_count = db.IntField() username = db.StringField(max_length=50, requied=False, unique=True) @classmethod def generate_username(cls, name, user=None): name = name or '' username = slugify(name) filters = dict(username=username) if user: filters['id__ne'] = user.id if cls.objects.filter(**filters).count(): username = '******'.format(username, random.randint(1, 1000)) return username def set_password(self, password, save=False): self.password = encrypt_password(password) if save: self.save() @classmethod def create_user(cls, name, email, password, active=True, roles=None, username=None, *args, **kwargs): username = username or cls.generate_username(name) if 'links' in kwargs: kwargs['links'] = [UserLink(**link) for link in kwargs['links']] return cls.objects.create(name=name, email=email, password=encrypt_password(password), active=active, roles=roles, username=username, *args, **kwargs) @property def connections(self): return Connection.objects(user_id=str(self.id)) def __unicode__(self): return '{0} <{1}>'.format(self.name or '', self.email)
class User(db.DynamicDocument, ThemeChanger, HasCustomValue, UserMixin, HasImages): name = db.StringField(max_length=255) email = db.EmailField(max_length=255, unique=True) password = db.StringField(max_length=255) active = db.BooleanField(default=True) confirmed_at = db.DateTimeField() roles = db.ListField(db.ReferenceField(Role, reverse_delete_rule=db.DENY), default=[]) last_login_at = db.DateTimeField() current_login_at = db.DateTimeField() last_login_ip = db.StringField(max_length=255) current_login_ip = db.StringField(max_length=255) login_count = db.IntField() username = db.StringField(max_length=50, required=False, unique=True) remember_token = db.StringField(max_length=255) authentication_token = db.StringField(max_length=255) tagline = db.StringField(max_length=255) bio = db.StringField() links = db.ListField(db.EmbeddedDocumentField(UserLink)) use_avatar_from = db.StringField(choices=(("gravatar", "gravatar"), ("url", "url"), ("upload", "upload"), ("facebook", "facebook")), default='gravatar') gravatar_email = db.EmailField(max_length=255) avatar_file_path = db.StringField() avatar_url = db.StringField(max_length=255) @property def display_name(self): rtn = None if self.name: rtn = self.name elif self.username: rtn = self.username elif self.email: rtn = self.email else: rtn = str(self) return rtn def get_avatar_url(self, *args, **kwargs): if self.use_avatar_from == 'url': return self.avatar_url elif self.use_avatar_from == 'upload': return url_for('quokka.core.media', filename=self.avatar_file_path) elif self.use_avatar_from == 'facebook': try: return Connection.objects( provider_id='facebook', user_id=self.id, ).first().image_url except Exception as e: logger.warning( '%s use_avatar_from is set to facebook but: Error: %s' % (self.display_name, str(e))) return Gravatar()(self.get_gravatar_email(), *args, **kwargs) @property def summary(self): return (self.bio or self.tagline or '')[:255] def get_gravatar_email(self): return self.gravatar_email or self.email def clean(self, *args, **kwargs): if not self.username: self.username = User.generate_username(self.name) super(User, self).clean(*args, **kwargs) @classmethod def generate_username(cls, name, user=None): name = name or '' username = slugify(name) filters = {"username": username} if user: filters["id__ne"] = user.id if cls.objects.filter(**filters).count(): username = "******".format(username, randint(1, 1000)) return username def set_password(self, password, save=False): self.password = encrypt_password(password) if save: self.save() @classmethod def createuser(cls, name, email, password, active=True, roles=None, username=None, *args, **kwargs): username = username or cls.generate_username(name) if 'links' in kwargs: kwargs['links'] = [UserLink(**link) for link in kwargs['links']] return cls.objects.create(name=name, email=email, password=encrypt_password(password), active=active, roles=roles, username=username, *args, **kwargs) @property def display_name(self): return abbreviate(self.name) or self.email def __unicode__(self): return u"{0} <{1}>".format(self.name or '', self.email) @property def connections(self): return Connection.objects(user_id=str(self.id))
class User(db.DynamicDocument, UserMixin): name = db.StringField(max_length=255) email = db.EmailField(max_length=255, unique=True) password = db.StringField(max_length=255) active = db.BooleanField(default=True) confirmed_at = db.DateTimeField() roles = db.ListField(db.ReferenceField(Role, reverse_delete_rule=db.DENY), default=[]) last_login_at = db.DateTimeField() current_login_at = db.DateTimeField() last_login_ip = db.StringField(max_length=255) current_login_ip = db.StringField(max_length=255) login_count = db.IntField() username = db.StringField(max_length=50, required=False, unique=True) remember_token = db.StringField(max_length=255) authentication_token = db.StringField(max_length=255) tagline = db.StringField(max_length=255) bio = db.StringField() links = db.ListField(db.EmbeddedDocumentField(UserLink)) gravatar_email = db.EmailField(max_length=255) def get_gravatar_email(self): return self.gravatar_email or self.email def clean(self, *args, **kwargs): if not self.username: self.username = User.generate_username(self.name) try: super(User, self).clean(*args, **kwargs) except: pass @classmethod def generate_username(cls, name): # username = email.lower() # for item in ['@', '.', '-', '+']: # username = username.replace(item, '_') # return username username = slugify(name) if cls.objects.filter(username=username).count(): username = "******".format(username, randint(1, 1000)) return username def set_password(self, password, save=False): self.password = encrypt_password(password) if save: self.save() @classmethod def createuser(cls, name, email, password, active=True, roles=None, username=None, *args, **kwargs): username = username or cls.generate_username(name) if "links" in kwargs: kwargs["links"] = [UserLink(**link) for link in kwargs['links']] return cls.objects.create(name=name, email=email, password=encrypt_password(password), active=active, roles=roles, username=username, *args, **kwargs) @property def display_name(self): return abbreviate(self.name) or self.email def __unicode__(self): return u"{0} <{1}>".format(self.name or '', self.email) @property def connections(self): return Connection.objects(user_id=str(self.id))
class User(db.DynamicDocument, UserMixin): name = db.StringField(max_length=255, verbose_name=_l('Name')) email = db.EmailField(max_length=255, unique=True, verbose_name=_l('Email')) password = db.StringField(max_length=255, verbose_name=_l('Password')) active = db.BooleanField(default=True, verbose_name=_l('Active')) confirmed_at = db.DateTimeField(verbose_name=_l('Confirmed At')) roles = db.ListField(db.ReferenceField(Role, reverse_delete_rule=db.DENY), default=[], verbose_name=_l('Roles')) last_login_at = db.DateTimeField(verbose_name=_l('Last Login At')) current_login_at = db.DateTimeField(verbose_name=_l('Current Login At')) last_login_ip = db.StringField(max_length=255, verbose_name=_l('Last Login IP')) current_login_ip = db.StringField(max_length=255, verbose_name=_l('Current Login IP')) login_count = db.IntField(verbose_name=_l('Login Count')) username = db.StringField(max_length=50, required=False, unique=True, verbose_name=_l('Username')) remember_token = db.StringField(max_length=255, verbose_name=_l('Remember Token')) authentication_token = db.StringField( max_length=255, verbose_name=_l('Authentication Tokern')) def clean(self, *args, **kwargs): if not self.username: self.username = User.generate_username(self.email) try: super(User, self).clean(*args, **kwargs) except: pass @classmethod def generate_username(cls, email): username = email.lower() for item in ['@', '.', '-', '+']: username = username.replace(item, '_') return username def set_password(self, password, save=False): self.password = encrypt_password(password) if save: self.save() @classmethod def createuser(cls, name, email, password, active=True, roles=None, username=None): username = username or cls.generate_username(email) return cls.objects.create(name=name, email=email, password=encrypt_password(password), active=active, roles=roles, username=username) @property def display_name(self): return self.name or self.email def __unicode__(self): return u"{0} <{1}>".format(self.name or '', self.email) @property def connections(self): return Connection.objects(user_id=str(self.id))