Esempio n. 1
0
    def stest_admin_approve_account(self):
        from karaage.datastores import create_new_user

        logged_in = self.client.login(username='******', password='******')
        self.failUnlessEqual(logged_in, True)
        project = Project.objects.get(pid='TestProject1')
        p_users = project.users.count()
        
        institute = Institute.objects.get(pk=1)
        
        person_data = {
            'title' : 'Mr',
            'first_name': 'Jim',
            'last_name': 'Bob',
            'position': 'Researcher',
            'institute': institute,
            'department': 'Maths',
            'email': '*****@*****.**',
            'country': 'AU',
            'telephone': '4444444',
            'username': '******',
            'password1': 'Exaiquouxei0',
            'password2': 'Exaiquouxei0',
        }
        person = create_new_user(person_data)
        
        join_request = ProjectJoinRequest.objects.create(
            person=person,
            project=project,
            leader_approved=True,
            )
        lcon = LDAPClient()
        self.failUnlessRaises(placard_exceptions.DoesNotExistException, lcon.get_user, 'uid=jimbob')
        self.failUnlessEqual(person.is_active, False)

        response = self.client.get(reverse('kg_account_request_detail', args=[join_request.id]))
        self.failUnlessEqual(response.status_code, 200)
        self.assertEquals(len(mail.outbox), 0)
        response = self.client.post(reverse('kg_account_approve', args=[join_request.id]))
        self.failUnlessEqual(response.status_code, 302)

        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(mail.outbox[0].subject, 'TestOrg Account approval')
        self.assertEquals(mail.outbox[0].from_email, settings.ACCOUNTS_EMAIL)
        self.assertEquals(mail.outbox[0].to[0], '*****@*****.**')

        self.failUnlessRaises(ProjectJoinRequest.DoesNotExist, ProjectJoinRequest.objects.get, pk=join_request.id)
        person = Person.objects.get(user__username='******')
        self.failUnlessEqual(person.is_active, True)

        luser = lcon.get_user('uid=jimbob')
        self.assertEqual(luser.givenName, 'Jim')
Esempio n. 2
0
    def save(self, person=None):
    
        data = self.cleaned_data
                
        if person is None:
            person = create_new_user(data)
            
            # Since adding with this method is only done with admin
            person.activate()

            if data['needs_account'] and data['project']:
                add_user_to_project(person, data['project'])

        person = super(self.__class__, self).save(person)
        return person
Esempio n. 3
0
 def create_new_person_from_applicant(self, applicant):
     from karaage.datastores import create_new_user
     data = {
         'email': applicant.email,
         'username': applicant.username,
         'title': applicant.title,
         'first_name': applicant.first_name,
         'last_name': applicant.last_name,
         'institute': applicant.institute,
         'department': applicant.department,
         'position': applicant.position,
         'telephone': applicant.telephone,
         'mobile': applicant.mobile,
         'supervisor': applicant.supervisor,
         'address': applicant.address,
         'city': applicant.city,
         'postcode': applicant.postcode,
         'country': applicant.country,
         'fax': applicant.fax,
         'saml_id': applicant.saml_id,
         }
     
     return create_new_user(data, hashed_password=applicant.password)
Esempio n. 4
0
                while 1:
                    if not institute_name:
                        institute_name = raw_input('Institute Name: ')
                    try:
                        institute = Institute.objects.get(name=institute_name)
                    except Institute.DoesNotExist:
                        sys.stderr.write("Error: Institute does not exist\n")
                        institute_name = None
                        continue
                    break
                    
        except KeyboardInterrupt:
            sys.stderr.write("\nOperation cancelled.\n")
            sys.exit(1)

        data = {
            'username': username,
            'email': email,
            'password1': password,
            'first_name': first_name,
            'last_name': last_name,
            'institute': institute,
            }
        person = create_new_user(data)
        person.activate()
        person.user.is_superuser = True
        person.user.is_staff = True
        person.user.save()
        
        print "Karaage Superuser created successfully."
Esempio n. 5
0
    def handle(self, csvfile, **options):
 
        verbosity = int(options.get('verbosity', 1))
        
        try:
            data = DictReader(open(csvfile))
        except:
            sys.stderr.write("ERROR: Failed to read CSV file.\n")
            sys.exit(1)
            
        success = 0
        fail_count = 0
        skip = 0
        for user in data:
            fail = False
            try:
                username = user['username']
            except KeyError:
                sys.stderr.write("Error: Failed to find username column.\n")
                fail = True

            if verbosity >= 1:
                print "Attempting to import user '%s'" % user['username']

            try:
                username = user['password']
            except KeyError:
                sys.stderr.write("Error: Failed to find password column.\n")
                fail = True
            try:
                username = user['first_name']
            except KeyError:
                sys.stderr.write("Error: Failed to find first_name column.\n")
                fail = True
            try:
                username = user['last_name']
            except KeyError:
                sys.stderr.write("Error: Failed to find last_name column.\n")
                fail = True
            try:
                username = user['email']
            except KeyError:
                sys.stderr.write("Error: Failed to find email column.\n")
                fail = True
            try:
                username = user['institute']
            except KeyError:
                sys.stderr.write("Error: Failed to find institute column.\n")
                fail = True
            try:
                username = user['project']
            except KeyError:
                sys.stderr.write("Error: Failed to find project column.\n")
                fail = True

            if not RE_VALID_USERNAME.match(user['username']):
                sys.stderr.write("Error: Username is invalid. Use only letters, digits and underscores.\n")
                fail = True

            try:
                is_valid_email(user['email'])
            except exceptions.ValidationError:
                sys.stderr.write("Error: E-mail address '%s' is invalid.\n" % user['email'])
                fail = True

            if fail:
                sys.stderr.write("Skipping row for username '%s' due to errors\n" % user['username'])
                fail_count += 1
                continue

            try:
                User.objects.get(username=user['username'])
                sys.stderr.write("Error: Username '%s' exists. Skipping\n" % user['username'])
                skip += 1
                continue
            except User.DoesNotExist:
                pass
    
            try:
                institute = Institute.objects.get(name=user['institute'])
                user['institute'] = institute
            except Institute.DoesNotExist:
                sys.stderr.write("Error: Institute '%s' does not exist. Skipping\n" % user['institute'])
                fail_count += 1
                continue
            
            project = None
            if user['project']:
                try:
                    project = Project.objects.get(pid=user['project'])
                except Project.DoesNotExist:
                    sys.stderr.write("Error: Project '%s' does not exist. Skipping\n" % user['project'])
                    fail_count += 1
                    continue

            user['password1'] = user['password']
            person = create_new_user(user)
            person.activate()
            print "Successfully added user '%s'" % person
            if project:
                add_user_to_project(person, project)
            
            success += 1
            


        print ''
        print 'Added:   %s' % success
        print 'Skipped: %s' % skip
        print 'Failed:  %s' % fail_count

        sys.exit(0)