Exemplo n.º 1
0
def signup(request):
    if request.method == 'POST':
        form = EmailUserCreationForm(request.POST)
        if form.is_valid():
            message = None

            email = form.clean_email()
            password = form.clean_password2()
            form.save()

            user = authenticate(email=email, password=password)
            if (user is not None) and (user.is_active):
                login(request, user)
                message = "Registration successful"
            else:
                message = "There was an error automatically logging you in. Try <a href=\"/index/\">logging in</a> manually."

            # Since user does not have any accounts by the time they signe in,
            # we should redirect them to accounts page instead of feed page.
            return redirect('/feed/')

    else:
        form = EmailUserCreationForm()

    return render(request, 'signup.html', {'form': form})
Exemplo n.º 2
0
def register(request):
	if request.method == 'POST':
		form = EmailUserCreationForm(request.POST)
		if form.is_valid():
			new_user = form.save()
			return HttpResponseRedirect("/polls/")
	else:
		form = UserCreationForm()
	return render_to_response("registration/register.html", {
		'form': form,},
		context_instance=RequestContext(request)
		)
Exemplo n.º 3
0
def create(request):
	if request.method == 'GET':
		form = EmailUserCreationForm()
		return render_to_response('create.html', {'form':form}, context_instance=RequestContext(request))
	if request.method == 'POST':
		form = EmailUserCreationForm(request.POST)
		if form.is_valid():
			user = create_user(request.POST['email'], request.POST['password1'])
			user.save()
			messages.success(request,'New user successfully created! Go ahead and log in right here.')
			return redirect('/accounts/login')
		else:
			return render_to_response('create.html', {'form':form}, context_instance=RequestContext(request))
Exemplo n.º 4
0
def TutorApplication(request, template = 'tutors/tutor_application.html'):
    if not settings.OPEN_SIGNUP:
        return HttpResponseRedirect('/')

    if request.method == 'POST':
        user_creation_form = EmailUserCreationForm(request.POST)
        profile_creation_form = ApplicationForm(request.POST)

        if user_creation_form.is_valid() and profile_creation_form.is_valid():
            # Create the user
            user_data = user_creation_form.cleaned_data
            user = create_user(user_data[ 'email' ], user_data[ 'password1' ])

            try:
                tutors_group = Group.objects.get(name = 'Tutors')
            except Group.DoesNotExist:
                tutors_group = Group.objects.create(name = 'Tutors')

            user.is_staff = False
            user.groups.add(tutors_group)

            profile_data = profile_creation_form.cleaned_data
            user.first_name = profile_data[ 'first_name' ][ 0 ].upper() + profile_data[ 'first_name' ][ 1: ].lower()
            user.last_name = profile_data[ 'last_name' ][ 0 ].upper() + profile_data[ 'last_name' ][ 1: ].lower()
            user.save()

            # Fill the tutor profile
            tutor = Tutor.objects.get(auth=user)
            tutor.name = user.get_full_name()
            tutor.email = user.email
            tutor.phone = profile_data[ 'phone' ]
            tutor.qualifications = profile_data[ 'qualifications' ]
            tutor.rate = profile_data[ 'rate' ]

            for course in profile_data[ 'taught_courses' ]:
                tutor.taught_courses.add(course)
            tutor.save()

            messages.add_message(request, messages.INFO,
                                 'Your application has been successfully received and is pending approval. Thank you '
                                 'for applying for Skule Tutors.')
            return HttpResponseRedirect('/')
    else:
        user_creation_form = EmailUserCreationForm()
        profile_creation_form = ApplicationForm()

    return render_to_response(template,
                              dict(user_creation_form = user_creation_form,
                                   profile_creation_form = profile_creation_form),
                              context_instance = RequestContext(request))
Exemplo n.º 5
0
def signup(request):
  if request.method == 'POST':
    form = EmailUserCreationForm(request.POST)
    if form.is_valid():
      message = None

      email = form.clean_email()
      password = form.clean_password2()
      form.save()

      user = authenticate(email=email, password=password)
      if (user is not None) and (user.is_active):
        login(request, user)
        message = "Registration successful"
      else:
        message = "There was an error automatically logging you in. Try <a href=\"/index/\">logging in</a> manually."

      # Since user does not have any accounts by the time they signe in,
      # we should redirect them to accounts page instead of feed page.
      return redirect('/feed/')

  else:
    form = EmailUserCreationForm()

  return render(request, 'signup.html', {'form': form})