def signup(request): if request.method == 'POST': f = CustomUserCreationForm(request.POST) if f.is_valid(): # send email verification now activation_key = helpers.generate_activation_key( username=request.POST['username']) subject = "Account Verification" message = '''\n Please visit the following link to verify your account \n\n{0}://{1}/cadmin/activate/account/?key={2} '''.format(request.scheme, request.get_host(), activation_key) error = False try: send_mail(subject, message, settings.SERVER_EMAIL, [request.POST['email']]) messages.add_message( request, messages.INFO, _('Account created! Click on the link sent to your email to activate the account' )) except: error = True messages.add_message( request, messages.INFO, _('Unable to sent email verification. Please try again')) if not error: u = User.objects.create_user(request.POST['username'], request.POST['email'], request.POST['password1'], is_active=0, is_staff=True) author = Author() author.activation_key = activation_key author.user = u author.save() return redirect('signup') else: f = CustomUserCreationForm() return render(request, 'cadmin/signup.html', {'form': f})
def register(request): if request.method == 'POST': f = CustomUserCreationForm(request.POST) if f.is_valid(): # send email verification now activation_key = helpers.generate_activation_key( username=request.POST['username']) subject = "TheGreatDjangoBlog Account Verification" ## [[ String literals can span multiple lines using triple quotes ]] message = ( '''\nPlease visit the following link to verify your account \n\n{0}://{1}/cadmin/activate/account/?key={2}'''. format(request.scheme, request.get_host(), activation_key)) error = False try: send_mail(subject, message, settings.SERVER_EMAIL, [request.POST['email']]) messages.add_message( request, messages.INFO, '''Account created! Click on the link sent to your email to activate the account''') except: error = True messages.add_message( request, messages.INFO, 'Unable to send email verification. Please try again') if not error: u = User.objects.create_user(request.POST['username'], request.POST['email'], request.POST['password1'], is_active=0) author = Author() author.activation_key = activation_key author.user = u author.save() return redirect('register') else: f = CustomUserCreationForm() return render(request, 'cadmin/register.html', {'form': f})