예제 #1
0
 def add(self, reader, password_length=BATCH_DEFAULT_PASSWORD_LENGTH):
     User = get_user_model()
     users_list = []
     generated_passwords = []
     for row in reader:
         if len(row) == 5:
             username, password, email, first_name, last_name = row
             if not username and email:
                 username = email.split('@')[0]
             username = find_available_username(username, users_list)
             user = User(username=username,
                         email=email,
                         first_name=first_name,
                         last_name=last_name)
             cleartext_delimiter = 'cleartext$'
             if not password:
                 password = get_random_string(length=password_length)
                 user.set_password(password)
                 generated_passwords.append([username, password, email])
             elif password and password.startswith(cleartext_delimiter):
                 password = password[len(cleartext_delimiter):]
                 user.set_password(password)
             else:
                 user.password = password
             user.full_clean()
             users_list.append(user)
     for u in users_list:
         u.save()
         self.users.add(u)
     for element in generated_passwords:
         username, password, user_email = element
         send_mail(BATCH_MAIL_SUBJECT,
                   BATCH_MAIL_MESSAGE.format(username, password),
                   BATCH_MAIL_SENDER, [user_email])
예제 #2
0
 def add(self, reader, password_length=BATCH_DEFAULT_PASSWORD_LENGTH):
     users_list = []
     generated_passwords = []
     for row in reader:
         if len(row) == 5:
             user, password = self.get_or_create_user(
                 row, users_list, password_length)
             users_list.append(user)
             if password:
                 generated_passwords.append(password)
     for user in users_list:
         self.save_user(user)
     for element in generated_passwords:
         username, password, user_email = element
         send_mail(BATCH_MAIL_SUBJECT,
                   BATCH_MAIL_MESSAGE.format(username, password),
                   BATCH_MAIL_SENDER, [user_email])