Commit 2126d85d authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

remove ACTIVATION_LOGIN_TARGET & SIGNUP_TARGET settings

parent 5260c39f
......@@ -241,9 +241,9 @@ class SimpleBackend(object):
def _send_verification(request, user, template_name):
site = Site.objects.get_current()
baseurl = request.build_absolute_uri('/').rstrip('/')
url = settings.ACTIVATION_LOGIN_TARGET % (baseurl,
quote(user.auth_token),
quote(baseurl))
url = '%s%s?auth=%s&next=%s' % (baseurl,
reverse('astakos.im.target.activate'),
quote(user.auth_token))
message = render_to_string(template_name, {
'user': user,
'url': url,
......
......@@ -69,16 +69,3 @@ def login(request, on_failure='login.html'):
next = request.POST.get('next')
return prepare_response(request, user, next)
def activate(request):
token = request.GET.get('auth')
next = request.GET.get('next')
try:
user = AstakosUser.objects.get(auth_token=token)
except AstakosUser.DoesNotExist:
return HttpResponseBadRequest('No such user')
user.is_active = True
user.save()
user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request, user, next, renew=True)
......@@ -43,6 +43,7 @@ urlpatterns = patterns('astakos.im.views',
url(r'^feedback/?$', 'send_feedback'),
url(r'^signup/?$', 'signup'),
url(r'^logout/?$', 'logout'),
url(r'^activate/?$', 'activate'),
url(r'^admin/', include('astakos.im.admin.urls')),
)
......@@ -57,8 +58,7 @@ urlpatterns += patterns('',
if 'local' in settings.IM_MODULES:
urlpatterns += patterns('astakos.im.target',
url(r'^local/?$', 'local.login'),
url(r'^local/activate/?$', 'local.activate'),
url(r'^local/?$', 'local.login')
)
urlpatterns += patterns('django.contrib.auth.views',
url(r'^local/password_reset/?$', 'password_reset',
......
......@@ -130,7 +130,8 @@ def _generate_invitation_code():
def _send_invitation(request, baseurl, inv):
sitename, sitedomain = get_current_site(request, use_https=request.is_secure())
subject = _('Invitation to %s' % sitename)
url = settings.SIGNUP_TARGET % (baseurl, inv.code, quote(sitedomain))
baseurl = request.build_absolute_uri('/').rstrip('/')
url = '%s%s?code=%d' % (baseurl, reverse('astakos.im.views.signup'), inv.code)
message = render_to_string('invitation.txt', {
'invitation': inv,
'url': url,
......@@ -188,17 +189,17 @@ def invite(request, template_name='invitations.html', extra_context={}):
if inviter.invitations > 0:
code = _generate_invitation_code()
invitation, created = Invitation.objects.get_or_create(
inviter=inviter,
username=username,
defaults={'code': code, 'realname': realname})
invitation = Invitation(inviter=inviter,
username=username,
code=code,
realname=realname)
invitation.save()
try:
baseurl = request.build_absolute_uri('/').rstrip('/')
_send_invitation(request, baseurl, invitation)
if created:
inviter.invitations = max(0, inviter.invitations - 1)
inviter.save()
inviter.invitations = max(0, inviter.invitations - 1)
inviter.save()
status = messages.SUCCESS
message = _('Invitation sent to %s' % username)
transaction.commit()
......@@ -403,3 +404,18 @@ def logout(request, template='registration/logged_out.html', extra_context={}):
return response
html = render_to_string(template, context_instance=get_context(request, extra_context))
return HttpResponse(html)
def activate(request):
"""
Activates the user identified by the ``auth`` request parameter
"""
token = request.GET.get('auth')
next = request.GET.get('next')
try:
user = AstakosUser.objects.get(auth_token=token)
except AstakosUser.DoesNotExist:
return HttpResponseBadRequest('No such user')
user.is_active = True
user.save()
return prepare_response(request, user, next, renew=True)
\ No newline at end of file
......@@ -26,15 +26,6 @@ INVITATIONS_PER_LEVEL = {
DEFAULT_FROM_EMAIL = '%s <no-reply@grnet.gr>'
DEFAULT_CONTACT_EMAIL = 'support@%s.grnet.gr'
# Where users should signup with their invitation code
SIGNUP_TARGET = '%s/im/signup/?code=%d&next=%s'
# Where users should activate their local account
ACTIVATION_LOGIN_TARGET = '%s/im/local/activate/?auth=%s&next=%s'
## Where users should reset their local password
#PASSWORD_RESET_TARGET = '%s/im/local/reset/?username=%s&next=%s'
# Identity Management enabled modules
IM_MODULES = ['local', 'twitter', 'shibboleth']
......
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