def create_user(self, email, password=None, first_name='', last_name='', active=False, send_email=True): """ A simple wrapper that creates a new :class:`User`. :param email: String containing the email address of the new user. :param password: String containing the password for the new user. :param first_name: String containing the first name for the new user. :param last_name: String containing the last name for the new user. :param active: Boolean that defines if the user requires activation by clicking on a link in an e-mail. Defauts to ``True``. :param send_email: Boolean that defines if the user should be send an email. You could set this to ``False`` when you want to create a user in your own code, but don't want the user to activate through email. :return: :class:`User` instance representing the new user. """ if not email: raise ValueError('Users must have an email address') user = self.model( email=UserManager.normalize_email(email), first_name=first_name, last_name=last_name, is_active=active, ) user.set_password(password) if not active: # Activation: salt, activation_key = generate_sha1(user.email) user.activation_key = activation_key user.save(using=self._db) if not active and send_email: user_send_activation_email.delay( user=user, language=translation.get_language()) return user
def create_user(self, email, password=None, first_name='', last_name='', active=False, send_email=True): """ A simple wrapper that creates a new :class:`User`. :param email: String containing the email address of the new user. :param password: String containing the password for the new user. :param first_name: String containing the first name for the new user. :param last_name: String containing the last name for the new user. :param active: Boolean that defines if the user requires activation by clicking on a link in an e-mail. Defauts to ``True``. :param send_email: Boolean that defines if the user should be send an email. You could set this to ``False`` when you want to create a user in your own code, but don't want the user to activate through email. :return: :class:`User` instance representing the new user. """ if not email: raise ValueError('Users must have an email address') user = self.model( email=UserManager.normalize_email(email), first_name=first_name, last_name=last_name, is_active=active, ) user.set_password(password) if not active: # Activation: salt, activation_key = generate_sha1(user.email) user.activation_key = activation_key user.save(using=self._db) if not active and send_email: user_send_activation_email.delay(user=user, language=translation.get_language()) return user
def change_email(self, email): """ Changes the email address for a user. A user needs to verify this new email address before it becomes active. By storing the new email address in a temporary field -- ``temporary_email`` -- we are able to set this email address after the user has verified it by clicking on the verification URI in the email. This email gets send out by ``send_verification_email``. :param email: The new email address that the user wants to use. """ self.email_unconfirmed = email salt, hash = generate_sha1(self.email) self.email_confirmation_key = hash self.email_confirmation_key_created = timezone.now() self.save() # Send email for activation self.send_confirmation_email() return self.email_unconfirmed
def set_activation_key(self): salt, activation_key = generate_sha1(self.email) self.activation_key = activation_key