def signup(request): """View that handles user registration.""" if request.user.is_authenticated(): return HttpResponseRedirect("/") if request.method == "GET": form = SignupForm() # Create an empty form if the method is GET. elif request.method == "POST": form = SignupForm(request.POST) # Populate the form with POST data. if form.is_valid(): # Get the form data. username = form.cleaned_data["username"] email = form.cleaned_data["email"] password = form.cleaned_data["password"] first_name = form.cleaned_data["first_name"] last_name = form.cleaned_data["last_name"] # Create a new user and profile. user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # Save the user. new_profile = UserProfile() new_profile.new(user, form.cleaned_data["phone"], get_remote_ip(request)) # Send an email with the confirmation link site = Site.objects.get_current() subject = "%s User Activation" % site.name body = ( "Hello, %s, and thanks for signing up for an account at %s!" "\n\nTo activate your account, click this link within 48 hours:" "\n\nhttp://%s/login/%s" % (user.username, site.domain, site.domain, new_profile.activation_key) ) send_mail(subject, body, "settings.EMAIL_HOST_USER", [user.email]) # Redirect to a confirmation page. return HttpResponseRedirect("/signup/confirmed/") # Load signup.html on GET request and POST error. return load_page(request, "signup.html", {"form": form})
def account(request): user = request.user try: profile = UserProfile.objects.get(user=request.user) except: profile = UserProfile() profile.new(user, ip_address=get_remote_ip(request)) profile.save() form = AccountForm({"phone": profile.phone, "email": user.email}) error = "" if request.method == "POST": form = AccountForm(request.POST) if form.is_valid(): # user.email = form.cleaned_data['email'] user.save() profile.phone = form.cleaned_data["phone"] profile.save() return index(request, "Your account has successfully been edited.") else: error = form.errors return load_page(request, "account.html", {"form": form, "error": error})