def setUp(self): self.instance = make_instance() self.commander = make_commander_user(self.instance, "comm") # Note unicode '⅀' is on purpose self.user1 = User(username='******', password='******', email='*****@*****.**', organization='org111', first_name='therem', last_name='⅀straven') self.user1.save_with_user(self.commander) self.user2 = User(username='******', password='******', email='*****@*****.**', first_name='genly', last_name='ai') self.user2.save_with_user(self.commander) self.user3 = User(username='******', password='******', email='*****@*****.**') self.user3.save_with_user(self.commander) self.user4 = User(username='******', password='******', email='*****@*****.**') self.user4.save_with_user(self.commander) self.factory = RequestFactory()
def handle(self, *args, **options): try: model_id = settings.SYSTEM_USER_ID except AttributeError: print('The `SYSTEM_USER_ID` settings is missing from ' 'the settings file. Set this to a specific ID ' 'before running this command.') return system_user_name = 'System User' existing_users = User.objects.filter(pk=model_id) users_with_name = User.objects.filter(username=system_user_name) if len(existing_users) == 1 and len(users_with_name) == 1: print('System user already exists') elif len(users_with_name) > 0: print('A user with username "%s" already exists but is not ' 'a super user' % system_user_name) else: user = User(is_active=False, username=system_user_name, pk=model_id) user.save_base() print('Created system user')
def create_user(request): data = json.loads(request.body) errors = {} for field in REQ_FIELDS: if field not in data: errors[field] = [_('This field is required')] for inputfield in data: if inputfield not in ALL_FIELDS: errors[inputfield] = [_('Unrecognized field')] if errors: raise ValidationError(errors) dup_username = User.objects.filter(username=data['username']) dup_email = User.objects.filter(email=data['email']) if dup_username.exists(): return _conflict_response(_('Username is already in use')) if dup_email.exists(): # BE WARNED - The iOS application relies on this error message string. # If you change this you WILL NEED TO ALTER CODE THERE AS WELL. return _conflict_response(_('Email is already in use')) user = User(**data) # Needed to properly hash the password user.set_password(data['password']) user.active = True user.save() RegistrationProfile.objects.create_profile(user) return {'status': 'success', 'id': user.pk}
def setUp(self): self.instance = make_instance() self.commander = make_commander_user(self.instance, "comm") # Note unicode '⅀' is on purpose self.user1 = User(username='******', password='******', email='*****@*****.**', organization='org111', first_name='therem', last_name='⅀straven') self.user1.save_with_user(self.commander) self.user2 = User(username='******', password='******', email='*****@*****.**', first_name='genly', last_name='ai', allow_email_contact=True) self.user2.save_with_user(self.commander) self.user3 = User(username='******', password='******', email='*****@*****.**') self.user3.save_with_user(self.commander) role = make_commander_role(self.instance) iuser1 = InstanceUser(instance=self.instance, user=self.user1, role=role) iuser1.save_with_user(self.user1) iuser2 = InstanceUser(instance=self.instance, user=self.user2, role=role) iuser2.save_with_user(self.user2) pt = Point(0, 0) self.plot = Plot(geom=pt, readonly=False, instance=self.instance, width=4) self.plot.save_with_user(self.user1) self.tree = Tree(instance=self.instance, plot=self.plot, diameter=3) self.tree.save_with_user(self.user2)
def create_mock_system_user(): try: system_user = User.objects.get(id=settings.SYSTEM_USER_ID) except Exception: system_user = User(username="******", email='*****@*****.**') system_user.id = settings.SYSTEM_USER_ID system_user.set_password('password') system_user.save_base() User._system_user = system_user
def create_user(request): data = json.loads(request.body) if 'allow_email_contact' not in data: data['allow_email_contact'] = False errors = {} for field in REQ_FIELDS: if field not in data: errors[field] = [trans('This field is required')] for inputfield in data: if inputfield not in ALL_FIELDS: errors[inputfield] = [trans('Unrecognized field')] if errors: raise ValidationError(errors) dup_username = User.objects.filter(username=data['username']) dup_email = User.objects.filter(email=data['email']) if dup_username.exists(): return _conflict_response(trans('Username is already in use')) if dup_email.exists(): return _conflict_response(trans('Email is already in use')) user = User(**data) # Needed to properly hash the password user.set_password(data['password']) user.active = True user.save() RegistrationProfile.objects.create_profile(user) return {'status': 'success', 'id': user.pk}
def make_plain_user(username, password='******'): user = User(username=username, email='*****@*****.**' % username) user.set_password(password) # hashes password, allowing authentication user.save() return user