예제 #1
0
    def testRegistrationNormal(self):
        ''' Correct reg for normal user [no crsid] '''

        testuser = {}
        testuser['firstname'] = "John"
        testuser['lastname'] = "Doe"
        testuser['email'] = "*****@*****.**"
        testuser['password_one'] = "helloworld"
        testuser['password_again'] = "helloworld"
        
        registerForm = RegisterForm(testuser)
        self.assert_(registerForm.is_valid())
        user, activate = registerForm.save()
        
        user.GiveDefaults()
        
        # Requires activation
        self.assert_(activate)

        self.assertEquals(user.firstname, testuser['firstname'])
        self.assertEquals(user.lastname, testuser['lastname'])
        self.assertEquals(user.email, testuser['email'])
        self.assertEquals(bool(user.activationlinkkey), True)
        self.assertEquals(bool(len(user.links.all())), True)
        self.assertEquals(user.membershipstatus, "EP")
        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(user.CheckPassword(testuser['password_one']), True)
예제 #2
0
 def testRegistrationCRSID(self):
     ''' Correct registration for Cambridge user with Raven raises activation requirement. '''
     testuser = {}
     testuser['firstname'] = "John"
     testuser['lastname'] = "Doe"
     testuser['email'] = "*****@*****.**"
     testuser['crsid'] = "jd208"
     testuser['password_one'] = "helloworld"
     testuser['password_again'] = "helloworld"
     
     registerForm = RegisterForm(testuser, crsid = testuser['crsid'])
     self.assert_(registerForm.is_valid())
     
     user, activate = registerForm.save()
     
     cambridgeform = CambridgeRegisterForm(testuser, crsid = testuser['crsid'])
     self.assert_(cambridgeform.is_valid())
     cambridgeform.pk = user.pk
     cambridgeform.save()
     # Do this after saving cambridgeform so they get a link to their college
     user.GiveDefaults()
     
     # Requires activation
     self.assert_(activate)
     
     self.assertEquals(user.firstname, testuser['firstname'])
     self.assertEquals(user.lastname, testuser['lastname'])
     self.assertEquals(user.email, testuser['email'])
     self.assertEquals(user.person_ptr.cambridgemember.crsid, testuser['crsid'])
     self.assertEquals(bool(user.activationlinkkey), True)
     self.assertEquals(bool(len(user.links.all())), True)
     self.assertEquals(user.membershipstatus, "EP")
     self.assertEquals(len(mail.outbox), 1)
     self.assertEquals(user.CheckPassword(testuser['password_one']), True)
예제 #3
0
    def testRegistrationEmailDuplicate(self):
       
        testuser = {}
        testuser['firstname'] = "John"
        testuser['lastname'] = "Doe"
        testuser['email'] = "*****@*****.**"
        testuser['crsid'] = "eat12"
        testuser['password_one'] = "helloworld"
        testuser['password_again'] = "helloworld"

        registerForm = RegisterForm(testuser)
        self.assertEquals(registerForm.is_valid(), True)
        registerForm.save()
        
        registerForm = RegisterForm(testuser)
        self.assertEquals(registerForm.is_valid(), False)
        self.assertEquals(registerForm.errors['email'], ["User with this Email address already exists."])
예제 #4
0
    def testRegistrationFull(self):
        ''' Correct reg for user who supplies all attributes '''
        

        testuser = {}
        testuser['firstname'] = "John"
        testuser['lastname'] = "Doe"
        testuser['email'] = "*****@*****.**"
        testuser['crsid'] = "eat12"
        testuser['password_one'] = "helloworld"
        testuser['password_again'] = "helloworld"
        testuser['subject'] = "FIN"
        testuser['type'] = "U1"
        testuser['interests'] = [self.eventtag.id]
        testuser['start_showflagstatus'] = True
        mycoll = Group.objects.get(official_name="Selwyn College")
        testuser['college'] = mycoll.id
        
        registerForm = RegisterForm(testuser, crsid = testuser['crsid'])
        self.assert_(registerForm.is_valid())
        user, activate = registerForm.save()
        
        cambridgeform = CambridgeRegisterForm(testuser, crsid = testuser['crsid'])
        self.assert_(cambridgeform.is_valid())
        cambridgeform.pk = user.pk
        cambridgeform.save()
        
        user.GiveDefaults()
        
        # Requires activation
        self.assert_(activate)
        
        self.assertEquals(user.firstname, testuser['firstname'])
        self.assertEquals(user.lastname, testuser['lastname'])
        self.assertEquals(user.email, testuser['email'])
        self.assertEquals(user.person_ptr.cambridgemember.type, testuser['type'])
        self.assertEquals(user.person_ptr.cambridgemember.subject, testuser['subject'])
        self.assertEquals(bool(user.activationlinkkey), True)
        self.assertEquals(user.membershipstatus, "EP")
        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(len(user.groups.all()), 1)
        self.assertEquals(bool(len(user.links.all())), True)
        self.assertEquals(user.CheckPassword(testuser['password_one']), True)
예제 #5
0
 def testRegistrationCRSIDAndEmail(self):
     ''' Correct registration for Cambridge user with Raven and @cam.ac.uk returns user with same characteristics and activated user. '''
     testuser = {}
     testuser['firstname'] = "John"
     testuser['lastname'] = "Doe"
     testuser['email'] = "*****@*****.**"
     testuser['crsid'] = "jd208"
     testuser['password_one'] = "helloworld"
     testuser['password_again'] = "helloworld"
     
     registerForm = RegisterForm(testuser, crsid=testuser['crsid'])
     self.assert_(registerForm.is_valid())
     user, activate = registerForm.save()
     
     self.assertEquals(user.firstname, testuser['firstname'])
     self.assertEquals(user.lastname, testuser['lastname'])
     self.assertEquals(user.email, testuser['email'])
     self.assertEquals(user.membershipstatus, "OK")
     self.assertEquals(len(mail.outbox), 0)
     self.assertEquals(user.CheckPassword(testuser['password_one']), True)
예제 #6
0
def RegisterDetails(request, returnurl=None):
    ''' Show form for User registration '''
    if not returnurl: returnurl = '/'
    bc = [{'title': 'Login', 'url': reverse('MyPidge.Users.views.Login', args=[returnurl])},
        {'title': 'Register'}]
        

    if request.session.get('loggedin'): return HttpResponseRedirect(returnurl)
    
    crsid = ""
    flags = {}
    initial = {}
    caminitial = {}
    person = None
    cammember = None
    
    if 'raven-crsid' in request.session:
        crsid = request.session['raven-crsid']
        initial['email'] = crsid + '@cam.ac.uk'
        
        # Do we already know anything about the user?
        try:
            cammember = CambridgeMember.objects.get(crsid = crsid)
            person = Person.objects.get(pk = cammember.pk)
            userinstance = User(**person.as_dict())
            
            # Member of a college? 
            usercolleges = person.groups.filter(category__small_name = 'COL')
            if usercolleges.count() == 1:
                caminitial['college'] = usercolleges[0].id
                
        except CambridgeMember.DoesNotExist:
            cammember = None

    formdata = None
    if request.method == "POST" and request.POST:
        formdata = request.POST

    # If person already exists, pass the Userform a User instance with person's details        
    if cammember:
        
        userform = RegisterForm(
            formdata,
            crsid = crsid,
            initial = initial,
            instance = userinstance)
        
        cambridgeform = CambridgeRegisterForm(
            formdata,
            crsid = crsid,
            initial = caminitial,
            instance = cammember)
    else:
        userform = RegisterForm(formdata, crsid = crsid, initial = initial)
        cambridgeform = CambridgeRegisterForm(formdata, crsid = crsid, initial = caminitial)

    if formdata:
        if userform.is_valid() and cambridgeform.is_valid():
            
            newuser, activate = userform.save()
            cambridgeform.pk = newuser.pk
            cambridgeform.save()
            # Do this after saving cambridgeform so they get a link to their college
            newuser.GiveDefaults()
            
            if activate:
                return HttpResponseRedirect(reverse('MyPidge.Users.views.RegisterEmailSent'))
            else:
                SendWelcomeEmail(newuser)
                return LoginUser(newuser, request, reverse('MyPidge.Users.views.ActivationSuccess'))

    if crsid:
        userform.base_fields['email'].help_text = "(required) If you leave this as your @cam.ac.uk address you will not need to confirm your email address. "
        userform.base_fields['password_one'].help_text = "(required) Please choose a password that you can use at MyPidge, in case there's a problem with logging in with Raven. It would be a good idea to choose a password that is not the same as your Raven password."
    
    return render_to_response('users-register-details', {'breadcrumb': bc, 'crsid': crsid, 'userform': userform.as_p(), 'cambridgeform': cambridgeform.as_p(), 'flags': flags})