Commit d0f1b064 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Improve activation view

- Use redirects instead of direct responses
- Messages update
parent cc925fef
......@@ -40,6 +40,10 @@ ACCOUNT_RESEND_ACTIVATION = 'You have not followed the activatio
INACTIVE_ACCOUNT_CHANGE_EMAIL = ''.join([ACCOUNT_RESEND_ACTIVATION, ' or <a href="%(signup_url)s">Provide new email?</a>'])
ACCOUNT_PENDING_ACTIVATION_HELP = 'If you haven\'t received activation email, be sure to check your spam folder.'
ACCOUNT_ACTIVATED = 'Congratulations. Your account has' + \
' been activated and you have been' + \
' automatically signed in to your account.'
PASSWORD_RESET_DONE = 'A mail with details on how to change your password was sent.'
PASSWORD_RESET_CONFIRM_DONE = 'Password changed. You can now login using your new password.'
......
......@@ -584,30 +584,33 @@ def activate(request, greeting_email_template_name='im/welcome_email.txt',
try:
user = AstakosUser.objects.get(auth_token=token)
except AstakosUser.DoesNotExist:
return HttpResponseBadRequest(_(astakos_messages.ACCOUNT_UNKNOWN))
messages.error(request, _(astakos_messages.ACCOUNT_UNKNOWN))
return HttpResponseRedirect(reverse('index'))
if user.is_active:
message = _(astakos_messages.ACCOUNT_ALREADY_ACTIVE)
messages.error(request, message)
return index(request)
return HttpResponseRedirect(reverse('index'))
try:
activate_func(user, greeting_email_template_name, helpdesk_email_template_name, verify_email=True)
activate_func(user, greeting_email_template_name,
helpdesk_email_template_name, verify_email=True)
response = prepare_response(request, user, next, renew=True)
transaction.commit()
return response
messages.success(request, astakos_messages.ACCOUNT_ACTIVATED)
return HttpResponseRedirect(reverse('edit_profile'))
except SendMailError, e:
message = e.message
messages.add_message(request, messages.ERROR, message)
transaction.rollback()
return index(request)
return HttpResponseRedirect(reverse('index'))
except BaseException, e:
status = messages.ERROR
message = _(astakos_messages.GENERIC_ERROR)
messages.add_message(request, messages.ERROR, message)
logger.exception(e)
transaction.rollback()
return index(request)
return HttpResponseRedirect(reverse('index'))
@require_http_methods(["GET", "POST"])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment