Commit b90b602c authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

change until get_or_create_user signature: remove username argument parameter...

change until get_or_create_user signature: remove username argument parameter and email should be obligatory 
parent c8727102
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
import logging import logging
import uuid
from datetime import datetime from datetime import datetime
...@@ -57,11 +56,11 @@ def login(request): ...@@ -57,11 +56,11 @@ def login(request):
invitation.save() invitation.save()
logging.info('Accepted invitation %s', invitation) logging.info('Accepted invitation %s', invitation)
user = get_or_create_user(username = uuid.uuid4().hex[:30], user = get_or_create_user(invitation.uniq,
realname = invitation.realname, realname = invitation.realname,
affiliation = 'Invitation', affiliation = 'Invitation',
level = invitation.inviter.level + 1, provider = 'invitation',
email = invitation.uniq) level = invitation.inviter.level + 1)
# in order to login the user we must call authenticate first # in order to login the user we must call authenticate first
authenticate(email=user.email, auth_token=user.auth_token) authenticate(email=user.email, auth_token=user.auth_token)
......
...@@ -47,9 +47,9 @@ from urllib import unquote ...@@ -47,9 +47,9 @@ from urllib import unquote
from hashlib import new as newhasher from hashlib import new as newhasher
def login(request, on_failure='index.html'): def login(request, on_failure='login.html'):
""" """
on_failure: whatever redirect accepts as to on_failure: the template name to render on login failure
""" """
form = LoginForm(data=request.POST) form = LoginForm(data=request.POST)
if not form.is_valid(): if not form.is_valid():
......
...@@ -38,8 +38,6 @@ from django.contrib.auth import authenticate ...@@ -38,8 +38,6 @@ from django.contrib.auth import authenticate
from astakos.im.target.util import prepare_response from astakos.im.target.util import prepare_response
from astakos.im.util import get_or_create_user from astakos.im.util import get_or_create_user
import uuid
class Tokens: class Tokens:
# these are mapped by the Shibboleth SP software # these are mapped by the Shibboleth SP software
SHIB_EPPN = "HTTP_EPPN" # eduPersonPrincipalName SHIB_EPPN = "HTTP_EPPN" # eduPersonPrincipalName
...@@ -70,8 +68,7 @@ def login(request): ...@@ -70,8 +68,7 @@ def login(request):
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '') affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
username = uuid.uuid4().hex[:30] user = get_or_create_user(eppn, realname=realname, affiliation=affiliation, provider='shibboleth', level=0)
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 # in order to login the user we must call authenticate first
user = authenticate(email=user.email, auth_token=user.auth_token) user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request, return prepare_response(request,
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
import oauth2 as oauth import oauth2 as oauth
import urlparse import urlparse
import uuid
from django.conf import settings from django.conf import settings
from django.http import HttpResponse from django.http import HttpResponse
...@@ -117,8 +116,8 @@ def authenticated(request): ...@@ -117,8 +116,8 @@ def authenticated(request):
# should never be used. # should never be used.
email = '%s@twitter.com' % access_token['screen_name'] email = '%s@twitter.com' % access_token['screen_name']
realname = access_token['screen_name'] realname = access_token['screen_name']
username = uuid.uuid4().hex[:30]
user = get_or_create_user(username, realname=realname, affiliation='Twitter', level=0, email=email) user = get_or_create_user(email, realname=realname, affiliation='Twitter', provider='twitter', level=0)
# in order to login the user we must call authenticate first # in order to login the user we must call authenticate first
user = authenticate(email=user.email, auth_token=user.auth_token) user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request, return prepare_response(request,
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
import logging import logging
import uuid
from datetime import tzinfo, timedelta from datetime import tzinfo, timedelta
from django.conf import settings from django.conf import settings
...@@ -55,15 +56,15 @@ def isoformat(d): ...@@ -55,15 +56,15 @@ def isoformat(d):
return d.replace(tzinfo=UTC()).isoformat() return d.replace(tzinfo=UTC()).isoformat()
def get_or_create_user(username, realname='', first_name='', last_name='', affiliation='', level=0, provider='local', password='', email=''): def get_or_create_user(email, realname='', first_name='', last_name='', affiliation='', level=0, provider='local', password=''):
"""Find or register a user into the internal database """Find or register a user into the internal database
and issue a token for subsequent requests. and issue a token for subsequent requests.
""" """
user, created = AstakosUser.objects.get_or_create(username=username, user, created = AstakosUser.objects.get_or_create(email=email,
defaults={ defaults={
'is_active': False, 'is_active': False,
'password':password, 'password':password,
'email':email, 'username':uuid.uuid4().hex[:30],
'affiliation':affiliation, 'affiliation':affiliation,
'level':level, 'level':level,
'invitations':settings.INVITATIONS_PER_LEVEL[level], 'invitations':settings.INVITATIONS_PER_LEVEL[level],
......
...@@ -91,14 +91,14 @@ def index(request, login_template_name='login.html', profile_template_name='prof ...@@ -91,14 +91,14 @@ def index(request, login_template_name='login.html', profile_template_name='prof
``profile_template_name`` ``profile_template_name``
A custom profile template to use. This is optional; if not specified, A custom profile template to use. This is optional; if not specified,
this will default to ``login.html``. this will default to ``profile.html``.
``extra_context`` ``extra_context``
An dictionary of variables to add to the template context. An dictionary of variables to add to the template context.
**Template:** **Template:**
index.html or ``template_name`` keyword argument. profile.html or login.html or ``template_name`` keyword argument.
""" """
template_name = login_template_name template_name = login_template_name
......
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