Exemple #1
0
def signup(request):
    if request.method == 'GET':
        return render(request, 'sign-up.html', {'form': SignupForm()})

    # elif request.method == 'POST'

    form = SignupForm(request.POST)

    if form.is_valid():
        user = User.objects.create_user(username=form.cleaned_data['username'], password=form.cleaned_data['password'])

        p = Person()
        p.user = user

        user.save()
        p.save()

        s = Studentity()
        s.person = p
        s.student_id = form.cleaned_data['student_id']
        s.department = Department.objects.get(name='unknown')

        s.save()

        return HttpResponseRedirect(reverse('registration_select_initial_tags', args=[user.username, p.id]))

    else:
        return render(request, 'sign-up.html', {'form': form, 'status': 'Notice errors below:'})
Exemple #2
0
 def test_SignupForm_valid(self):
     form = SignupForm(data={'username': "******",
                             'email': "*****@*****.**",
                             'password1': "yarik123456789",
                             'password2': "yarik123456789"})
     self.assertTrue(form.is_valid())
     record = form.save()
     self.assertEqual(record.username, "John")
     self.assertEqual(record.email, "*****@*****.**")
Exemple #3
0
 def test_required(self):
     form = SignupForm()
     form.process()
     self.assertFalse(form.validate())
     expected = {
         'email': [u'This field is required.'],
         'identity': [u'This field is required.'],
         'password': [u'This field is required.'],
         'terms': [u'This field is required.']
     }
     self.assertDictEqual(form.errors, expected)
Exemple #4
0
def ajax_process_sign_up_form(request):
    """ Site generic registration signup view """
    registration_id = ''
    msg = ''
    tpl_type = request.REQUEST.get('template_type')
    Template = {
        'landing': 'inc_registration_form.html',
        'popup': 'inc_popup_signup.html',
    }
    status = False
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.save(commit=False)
            if form.is_resend:
                user = User.objects.get(email=data.email)
                msg = _('Your account has been registered but not activated yet. We have resend you an activation email, please check your inbox and click the activation link.')
                
                if not user.has_usable_password(): #user is generated by system before
                    msg = _('Your account needs to be activated by email, please check your inbox and click the activation link.')
                    user.username = data.username    
                    
                user.set_password(data.password)
                
                # disable old registration objects to make sure that the user's account cannot be activated by old activation link
                Registration.objects.disable_user_registration_entries(user)
                
                # recreate a registration object for the new user
                registration = Registration.objects.create_registration_obj_for_user(user)
                
                user.save()    
            else:
                # create a new user and set user status to inactive
                new_user = User.objects.create_user(data.username, data.email, data.password)
                new_user.is_active = False
                new_user.save()
                
                # create a registration object for the new user
                registration = Registration.objects.create_registration_obj_for_user(new_user)

                msg = _('Your account needs to be activated by email, please check your inbox and click the activation link.')
                status = True
            registration_id = registration.id

        html = render_to_string(Template[tpl_type], { 'registration_form': form, 'status':status, 'msg':msg }, context_instance = RequestContext(request))
    else:
        form = SignupForm()
        html = render_to_string(Template[tpl_type], { 'registration_form': form, 'status':status, 'msg':msg  }, context_instance = RequestContext(request))
        return HttpResponse(html, mimetype="text/html")
    response = {'html': html, 'status': status, 'registration_id': registration_id}
    return HttpResponse(json.dumps(response), mimetype="application/json")
Exemple #5
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            data = form.save(commit=False)
            new_user = User.objects.create_user(data.username, data.email, data.password)
            new_user.save()
            
            return HttpResponseRedirect("/registration/accounts/login/")
    else:
        form = SignupForm()
        
    return render_to_response("signup.html", {
        'form': form,
    },context_instance=RequestContext( request ))
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'account_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = SignupForm()
    return render(request, 'signup.html', {'form': form})
Exemple #7
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.instance.username = form.instance.email
            form.save()
            raw_password = form.cleaned_data.get('password1')
            email = form.cleaned_data.get('email')
            user = authenticate(username=email, password=raw_password)
            login(request, user)
            return redirect(settings.LOGIN_REDIRECT_URL)
    else:
        form = SignupForm()
    return render(request, 'signup.html', {'form': form})
Exemple #8
0
 def test_UserForm_invalid(self):
     form = SignupForm(data={'username': '',
                             'email': "false",
                             'password1': "false",
                             'password2': 'password'})
     self.assertFalse(form.is_valid())