def resend_activation_key(request, user_id): user = get_object_or_404(User, pk=user_id) activation = get_object_or_None(ActivationKey, user=user) if not activation == None: # Cleaning database from unused objects activation.delete() if request.method == 'POST': form = ResendActivationKeyForm(request.POST) if not form.cleaned_data['email'] == user.email: messages.error(request, "E-mail address sent by you doesn't match \ with address used to register this account.") return redirect(reverse('home')) if form.is_valid(): t = loader.get_template('accounts/email/email_activation.html') ak = ActivationKey(user=user) ak.save() webmaster_email = get_config('WEBMASTER_EMAIL', '*****@*****.**') site_name = get_config('SITE_NAME', 'Trinitee application') c = Context({'new_user': user, 'activation_key': ak.key, 'webmaster_email': webmaster_email, 'site_name': site_name, 'server_name': request.get_host()}) send_mail("E-mail activation at %s" % site_name, t.render(c), get_config('MAILER_ADDRESS', '*****@*****.**'), [email], fail_silently=False) messages.success(request, "An email has been sent \ to the specified address with instructions on how to activate \ your new account. If it doesn't arrive you can contact the forum \ administrator at %s" % webmaster_email) return redirect(reverse('home')) else: form = ResendActivationKeyForm() return {'form': form}
def register(request): # ref: comment to accounts.views.login_ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] email = form.cleaned_data['email'] user = User(username=username, email=email, is_active=False) user.set_password(password) if not get_config('ACTIVATION_REQUIRED', False): user.is_active = True user.save() messages.success(request, "Thank you for registering." " You can now log in.") else: if not get_config('EMAIL_HOST', False) \ or not get_config('EMAIL_PORT', False) \ or not get_config('EMAIL_HOST_USER', False) \ or not get_config('EMAIL_HOST_PASSWORD', False): raise ImproperlyConfigured("You must configure mailer.") user.save() ak = ActivationKey(user=user) ak.save() t = loader.get_template('accounts/email/email_activation.html') webmaster_email = get_config('WEBMASTER_EMAIL', '*****@*****.**') site_name = get_config('SITE_NAME', 'Trinitee application') c = Context({'new_user': user, 'activation_key': ak.key, 'webmaster_email': webmaster_email, 'site_name': site_name, 'server_name': request.get_host()}) send_mail("E-mail activation at %s" % site_name, t.render(c), get_config('MAILER_ADDRESS', '*****@*****.**'), [email]) messages.success(request, "Thank you for registering." " An email has been sent to the specified address with" " instructions on how to activate your new account." " If it doesn't arrive you can contact the forum" " administrator at %s" % webmaster_email) return redirect(reverse('accounts.views.login')) else: form = RegistrationForm() return {'form': form}