Commit 7d7f1f1b authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

login preaccepted user

Refs: #1913
parent 74f643ad
......@@ -59,7 +59,7 @@ from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.models import Site
from astakos.im.models import AstakosUser, Invitation
from astakos.im.util import isoformat, get_or_create_user, get_context
from astakos.im.util import isoformat, get_context
from astakos.im.forms import *
from astakos.im.backends import get_backend
from astakos.im.views import render_response, index
......
......@@ -37,6 +37,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.contrib.auth import authenticate, login
from django.contrib.auth.forms import UserCreationForm
from django.contrib.sites.models import Site
from django.contrib import messages
......@@ -45,7 +46,6 @@ from django.shortcuts import redirect
from smtplib import SMTPException
from urllib import quote
from astakos.im.util import get_or_create_user
from astakos.im.models import AstakosUser, Invitation
from astakos.im.forms import ExtendedUserCreationForm, InvitedExtendedUserCreationForm
......@@ -150,6 +150,10 @@ class InvitationsBackend(object):
if self._is_preaccepted(user):
user.is_active = True
user.save()
# get the raw password from the form
password = form.cleaned_data['password1']
user = authenticate(username=user.email, password=password)
login(self.request, user)
message = _('Registration completed. You can now login.')
else:
message = _('Registration completed. You will receive an email upon your account\'s activation')
......
......@@ -41,7 +41,6 @@ from django.conf import settings
from hashlib import new as newhasher
from astakos.im.models import AstakosUser
from astakos.im.util import get_or_create_user
import logging
import uuid
......
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.
import logging
import uuid
from datetime import datetime
......@@ -56,10 +57,11 @@ def login(request):
invitation.save()
logging.info('Accepted invitation %s', invitation)
user = get_or_create_user(invitation.uniq,
invitation.realname,
'Invitation',
invitation.inviter.level + 1)
user = get_or_create_user(username = uuid.uuid4().hex[:30],
realname = invitation.realname,
affiliation = 'Invitation',
level = invitation.inviter.level + 1,
email = invitation.uniq)
# in order to login the user we must call authenticate first
authenticate(email=user.email, auth_token=user.auth_token)
......
......@@ -83,4 +83,5 @@ def activate(request):
user.is_active = True
user.save()
return prepare_response(request, user, next, renew=True, skip_login=True)
user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request, user, next, renew=True)
......@@ -38,6 +38,7 @@ from django.contrib.auth import authenticate
from astakos.im.target.util import prepare_response
from astakos.im.util import get_or_create_user
import uuid
class Tokens:
# these are mapped by the Shibboleth SP software
......@@ -69,9 +70,10 @@ def login(request):
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
user = get_or_create_user(eppn, realname=realname, affiliation=affiliation, level=0, email=eppn)
username = uuid.uuid4().hex[:30]
user = get_or_create_user(username, realname=realname, affiliation=affiliation, level=0, email=eppn)
# in order to login the user we must call authenticate first
user = authenticate(username=user.username, auth_token=user.auth_token)
user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request,
user,
request.GET.get('next'),
......
......@@ -35,6 +35,7 @@
import oauth2 as oauth
import urlparse
import uuid
from django.conf import settings
from django.http import HttpResponse
......@@ -114,12 +115,12 @@ def authenticated(request):
# These two things will likely never be used. Alternatively, you
# can prompt them for their email here. Either way, the password
# should never be used.
username = '%s@twitter.com' % access_token['screen_name']
email = '%s@twitter.com' % access_token['screen_name']
realname = access_token['screen_name']
user = get_or_create_user(username, realname=realname, affiliation='Twitter', level=0, email=username)
username = uuid.uuid4().hex[:30]
user = get_or_create_user(username, realname=realname, affiliation='Twitter', level=0, email=email)
# in order to login the user we must call authenticate first
user = authenticate(username=user.username, auth_token=user.auth_token)
user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request,
user,
request_token.get('next'))
......@@ -63,7 +63,7 @@ from django.contrib.auth.forms import UserCreationForm
#from astakos.im.openid_store import PithosOpenIDStore
from astakos.im.models import AstakosUser, Invitation
from astakos.im.util import isoformat, get_or_create_user, get_context
from astakos.im.util import isoformat, get_context
from astakos.im.backends import get_backend
from astakos.im.forms import ProfileForm, FeedbackForm, LoginForm
......
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