Exemplo n.º 1
0
def sign_up(request):
    title = "Sign Up"
    #if reached via POST
    if request.method == 'POST':
        # make the SignUpForm
        form = SignupForm(data = request.POST)
        # if the form is valid
        if form.is_valid():
            # check that the input is correct(Passwords match)
            if request.POST['password'] != request.POST['password2']:
                message = "Passwords did not match. Please try again"
            # if passwords do match, (we do not need to check for double 
            # users because django does that 
            else:
                # Save the user's form data to the database.
                user = form.save()
                # Hash Password
                user.set_password(user.password)
                user.save()
                user = authenticate(username=request.POST['username'], password=request.POST['password'])
                login(request, user)
                return redirect('/profile')

        # Print problems to terminal
        else:
            print(form.errors)
            message = form.errors

    # Not POST , redirect to needed page
    else:
        message = "If not already a Member."
    return render(request, "signup.html", {"message": message, "title": title})
Exemplo n.º 2
0
 def test_invalid_less_password(self):
     form_data = {
         'first_name': 'user',
         'last_name': 'test',
         'user_name': 'guest',
         'email': '*****@*****.**',
         'password': '******'}
     form = SignupForm(data=form_data)
     self.assertFalse(form.is_valid())
Exemplo n.º 3
0
 def test_signup_success(self):
     form_data = {
         'first_name': 'user',
         'last_name': 'test',
         'user_name': 'guest',
         'email': '*****@*****.**',
         'password': '******'}
     form = SignupForm(data=form_data)
     self.assertTrue(form.is_valid())
Exemplo n.º 4
0
 def test_invalid_format_email(self):
     form_data = {
         'first_name': 'user',
         'last_name': 'test',
         'user_name': 'guest',
         'email': 'test',
         'password': '******'}
     form = SignupForm(data=form_data)
     self.assertFalse(form.is_valid())
Exemplo n.º 5
0
 def test_required_last_name(self):
     form_data = {
         'first_name': 'user',
         'last_name': None,
         'user_name': 'guest',
         'email': '*****@*****.**',
         'password': '******'}
     form = SignupForm(data=form_data)
     self.assertFalse(form.is_valid())
Exemplo n.º 6
0
def register(request):
    try:
        tutor = Tutor.objects.get(email=request.user.email)
        return render(request, 'main/alreadyRegistered.html', {})
    except Tutor.DoesNotExist:
        pass
    try:
        student = Student.objects.get(email=request.user.email)
        return render(request, 'main/alreadyRegistered.html', {})
    except Student.DoesNotExist:
        pass
    message = ""
    messageType = "danger"
    try:
        registration = Registration.objects.get(email=request.user.email)
        registerSubmitText = "Update Registration"
        message = "Registration Status: " + registration.status + ". Do some stuff."
        # TODO: Handle what happens if status isn't just pending, like they have to do something
        messageType = "info"
    except Registration.DoesNotExist:
        registration = None
        registerSubmitText = "Request Registration"

    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            print("Register good form")
            # Get hidden information from form
            fullName = str(form.cleaned_data['fullName'])
            email = request.user.email
            phone = str(form.cleaned_data['phone'])
            registrationType = str(form.cleaned_data['registrationType'])
            if registrationType == "Tutor":
                # TODO: tutor registration
                status = "Pending"
                message = "Your Tutor registration is being reviewed for approval. Please look over your registration information and make any needed corrections."
                messageType = "info"
                updated_at = datetime.datetime.now()
                registration = Registration(fullName=fullName, email=email, phone=phone, registrationType=registrationType, status=status, message=message, updated_at=updated_at)
                # TODO: make sure registration actually saves
                registration.save()
                pass
            elif registrationType == "Student":
                # TODO: student registration
                # TODO: make sure email is unique
                student = Student(fullName=fullName, email=email, phone=phone, status="active")
                student.save()
                # TODO: Successfully registered for students page
                return HttpResponseRedirect('/home/')
            else:
                pass
                # TODO: bad registration
    return render(request, 'main/register.html', {'message': message, 'messageType': messageType, 'registration': registration, 'registerSubmitText': registerSubmitText})
Exemplo n.º 7
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = True
            user.save()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = SignupForm()
    return render(request, 'signup.html', {'form': form})
Exemplo n.º 8
0
def url_signup(request):
    '''用户通过浏览器将表单内容post到/signup/post后来到这里'''
    uf = SignupForm()
    language = act_getlanguage(request)
    msg = request.method + language
    if request.method == 'POST':
        uf = SignupForm(request.POST)
        if uf.is_valid():
            nickname = uf.cleaned_data['nickname']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']
            result = act_signup(password=password, nickname=nickname, email=email,
                http_language=language)
            msg = result + language
    info = act_getinfo(request)
    return render(request, "main/signup.html", {'info':info, 'form':uf, 'msg':msg})
Exemplo n.º 9
0
def signup(request):
    """signup
    to register users
    """
    if request.method == "POST":
        signupform = SignupForm(request.POST)
        if signupform.is_valid():
            user = signupform.save(commit=False)
            user.save()

            return HttpResponseRedirect(reverse("signup_ok"))
    elif request.method == "GET":
        signupform = SignupForm()

    return render(request, "registration/signup.html",
                  {'signupform': signupform})
Exemplo n.º 10
0
def register(request):
    if request.method == 'POST':
        signup = SignupForm(request.POST)
        if signup.is_valid():
            p = Users(
                name=signup.cleaned_data.get('name'),
                email=signup.cleaned_data.get('email'),
                pwd=signup.cleaned_data.get('pwd'),
                age=signup.cleaned_data.get('age'),
                sex=signup.cleaned_data.get('sex'),
                address=signup.cleaned_data.get('address'),
                blood=signup.cleaned_data.get('blood').upper(),
                blood_type=signup.cleaned_data.get('blood_type').upper(),
                phone=signup.cleaned_data.get('phone'),
            )
            p.save()
            request.session['user_id'] = p.id
    return HttpResponseRedirect(reverse('main:index'))
Exemplo n.º 11
0
def signup(request):
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    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)
            subject = 'Activate your blog account.'
            message = render_to_string(
                'main/acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            # user.email_user(subject, message)
            toemail = form.cleaned_data.get('email')
            email = EmailMessage(subject, message, to=[toemail])
            email.send()
            return render(
                request, 'main/signup.html', {
                    'sections':
                    sections,
                    'post_num':
                    post_num,
                    'user_num':
                    user_num,
                    'msg':
                    'Please confirm your email address to complete the registration'
                })
    else:
        form = SignupForm()
    return render(
        request, 'main/signup.html', {
            'form': form,
            'sections': sections,
            'post_num': post_num,
            'user_num': user_num,
        })
Exemplo n.º 12
0
def signup(request, backend, success_url=None, extra_context=None):
    disallowed_url = 'registration_disallowed'
    backend = get_backend(backend)

    if not backend.registration_allowed(request):
        return redirect(disallowed_url)

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        signup_form = SignupForm(request.POST)

        if user_form.is_valid() and signup_form.is_valid():
            new_user = backend.register(request, **user_form.cleaned_data)
            profile = signup_form.save(commit=False)
            profile.user = new_user
            profile.save()
            if success_url is None:
                to, args, kwargs = backend.post_registration_redirect(request, new_user)
                return redirect(to, *args, **kwargs)
            else:
                return redirect(success_url)
    else:
        user_form = UserForm()
        signup_form = SignupForm()
    
    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    return render_to_response(
        'signup.html',
        {
            'user_form': user_form,
            'signup_form': signup_form
        },
        context_instance=context)
Exemplo n.º 13
0
def signup(request):
	body_class = 'signup-page'
	if request.method == 'POST':
		form = SignupForm(request.POST)
		if form.is_valid():
			is_buddy = form.cleaned_data['is_buddy']
			newsletter = form.cleaned_data['newsletter']
			user = User.objects.create_user(
				username=form.cleaned_data['first_name'] + '_' + form.cleaned_data['last_name'],
				email=form.cleaned_data['email'],
				password=form.cleaned_data['password']
			)
			user.first_name = form.cleaned_data['first_name']
			user.last_name = form.cleaned_data['last_name']
			user.save()
			if (is_buddy):
				mygroup, created = Group.objects.get_or_create(name='Buddies')				
				user.groups.add(mygroup)
			new_user = authenticate(username=request.POST['email'], password=request.POST['password'])
			auth_login(request, new_user)
			return redirect(index)
	else:
		form = SignupForm()
	return render(request, 'main/signup.html', {'body_class' : body_class, 'form': form})