def test_user_authentication(self): authdata = { 'username': '******', 'password': '******', 'email': '*****@*****.**', } data = authdata.copy() data.update({ 'email': '*****@*****.**', }) user = User(**data) user.set_password(data.get('password')) user.save() user = authenticate(username=authdata.get('username'), password=authdata.get('password')) self.assertIsNotNone(user)
def create_user(self, request, data, openid=None): user = User( username = data['username'], first_name = data.get('first_name', ''), last_name = data.get('last_name', ''), email = data.get('email', ''), ) # Set OpenID, if one has been associated if openid: uoa = UserOpenidAssociation(user_id = user.username, openid = openid, created = datetime.now()) uoa.store() # Set password, if one has been specified password = data.get('password') if password: user.set_password(password) else: user.set_unusable_password() user.store() return user
def create_inactive_user(username, email, password, site, send_email=True): """ Create a new, inactive ``User``, generate a ``RegistrationProfile`` and email its activation key to the ``User``, returning the new ``User``. By default, an activation email will be sent to the new user. To disable this, pass ``send_email=False``. """ new_user = User() new_user.username = username new_user.email = email new_user.set_password(password) new_user.is_active = False create_profile(new_user) new_user.save() if send_email: new_user.send_activation_email(site) return new_user