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 @@
# or implied, of GRNET S.A.
import logging
import uuid
from datetime import datetime
......@@ -57,11 +56,11 @@ def login(request):
invitation.save()
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,
affiliation = 'Invitation',
level = invitation.inviter.level + 1,
email = invitation.uniq)
provider = 'invitation',
level = invitation.inviter.level + 1)
# in order to login the user we must call authenticate first
authenticate(email=user.email, auth_token=user.auth_token)
......
......@@ -47,9 +47,9 @@ from urllib import unquote
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)
if not form.is_valid():
......
......@@ -38,8 +38,6 @@ 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
SHIB_EPPN = "HTTP_EPPN" # eduPersonPrincipalName
......@@ -70,8 +68,7 @@ def login(request):
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
username = uuid.uuid4().hex[:30]
user = get_or_create_user(username, realname=realname, affiliation=affiliation, level=0, email=eppn)
user = get_or_create_user(eppn, realname=realname, affiliation=affiliation, provider='shibboleth', level=0)
# in order to login the user we must call authenticate first
user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request,
......
......@@ -35,7 +35,6 @@
import oauth2 as oauth
import urlparse
import uuid
from django.conf import settings
from django.http import HttpResponse
......@@ -117,8 +116,8 @@ def authenticated(request):
# should never be used.
email = '%s@twitter.com' % 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
user = authenticate(email=user.email, auth_token=user.auth_token)
return prepare_response(request,
......
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.
import logging
import uuid
from datetime import tzinfo, timedelta
from django.conf import settings
......@@ -55,15 +56,15 @@ def isoformat(d):
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
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={
'is_active': False,
'password':password,
'email':email,
'username':uuid.uuid4().hex[:30],
'affiliation':affiliation,
'level':level,
'invitations':settings.INVITATIONS_PER_LEVEL[level],
......
......@@ -91,14 +91,14 @@ def index(request, login_template_name='login.html', profile_template_name='prof
``profile_template_name``
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``
An dictionary of variables to add to the template context.
**Template:**
index.html or ``template_name`` keyword argument.
profile.html or login.html or ``template_name`` keyword argument.
"""
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