def create_user(cls, username, password, email=None, analyst=None): """ Create (and save) a new user with the given username, password and email address. """ now = 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.create_api_key("default", analyst, default=True) if password and user.set_password(password): user.save(username=analyst) return user elif CRITsConfig.remote_user: user.save(username="******") return user else: return None
def create_user(cls, email, display_name, password): """Create (and save) a new user with the given email address, display name and password. """ now = datetime_now() email = cls.normalize_email(email) user = cls(email=email, display_name=display_name, date_joined=now) user.set_password(password) user.save() return user
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. """ now = datetime_now() self.password = make_password(raw_password) self.changed_pwd_at = now self.save() return self
def login(cls, username, password): """Create (and save) a new user with the given username, password and email address. """ now = datetime_now() if username: user = cls.objects(username=username).first() else: return None if not user.check_password: return None user.last_login = now user.save() return user
def create_user(cls, username, password, email=None): """Create (and save) a new user with the given username, password and email address. """ now = 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, changed_pwd_at=now) user.set_password(password) user.save() return user