Revision 27e26a41
b/snf-astakos-app/astakos/im/functions.py | ||
---|---|---|
38 | 38 |
from django.template.loader import render_to_string |
39 | 39 |
from django.core.mail import send_mail |
40 | 40 |
from django.core.urlresolvers import reverse |
41 |
from django.core.exceptions import ValidationError |
|
42 |
|
|
41 | 43 |
from urllib import quote |
42 | 44 |
from urlparse import urljoin |
43 | 45 |
from smtplib import SMTPException |
... | ... | |
158 | 160 |
""" |
159 | 161 |
Activates the specific user and sends email. |
160 | 162 |
|
161 |
Raises SendGreetingError |
|
163 |
Raises SendGreetingError, ValidationError
|
|
162 | 164 |
""" |
163 | 165 |
user.is_active = True |
164 | 166 |
user.save() |
... | ... | |
183 | 185 |
user.save() |
184 | 186 |
except AstakosUser.DoesNotExist, e: |
185 | 187 |
logger.exception(e) |
188 |
except ValidationError, e: |
|
189 |
logger.exception(e) |
|
186 | 190 |
|
187 | 191 |
class SendMailError(Exception): |
188 | 192 |
pass |
b/snf-astakos-app/astakos/im/management/commands/createuser.py | ||
---|---|---|
101 | 101 |
user.save() |
102 | 102 |
except socket.error, e: |
103 | 103 |
raise CommandError(e) |
104 |
except ValidationError, e: |
|
105 |
raise CommandError(e) |
|
104 | 106 |
else: |
105 | 107 |
msg = "Created user id %d" % (user.id,) |
106 | 108 |
if options['password'] is None: |
b/snf-astakos-app/astakos/im/management/commands/modifyuser.py | ||
---|---|---|
147 | 147 |
try: |
148 | 148 |
user.save() |
149 | 149 |
except ValidationError, e: |
150 |
raise CommandError(e.message_dict) |
|
150 |
raise CommandError(e) |
b/snf-astakos-app/astakos/im/target/redirect.py | ||
---|---|---|
38 | 38 |
from django.utils.http import urlencode |
39 | 39 |
from django.contrib.auth import login as auth_login, authenticate, logout |
40 | 40 |
from django.http import HttpResponse, HttpResponseBadRequest |
41 |
from django.core.exceptions import ValidationError |
|
41 | 42 |
|
42 | 43 |
from urllib import quote |
43 | 44 |
from urlparse import urlunsplit, urlsplit, urlparse, parse_qsl |
... | ... | |
88 | 89 |
renew = request.GET.get('renew', None) |
89 | 90 |
if renew == '': |
90 | 91 |
request.user.renew_token() |
91 |
request.user.save() |
|
92 |
|
|
92 |
try: |
|
93 |
request.user.save() |
|
94 |
except ValidationError, e: |
|
95 |
return HttpResponseBadRequest(e) |
|
93 | 96 |
# authenticate before login |
94 | 97 |
user = authenticate(email=request.user.email, auth_token=request.user.auth_token) |
95 | 98 |
auth_login(request, user) |
b/snf-astakos-app/astakos/im/util.py | ||
---|---|---|
40 | 40 |
from functools import wraps |
41 | 41 |
|
42 | 42 |
from datetime import tzinfo, timedelta |
43 |
from django.http import HttpResponse, urlencode |
|
43 |
from django.http import HttpResponse, HttpResponseBadRequest, urlencode
|
|
44 | 44 |
from django.template import RequestContext |
45 | 45 |
from django.contrib.sites.models import Site |
46 | 46 |
from django.utils.translation import ugettext as _ |
47 | 47 |
from django.contrib.auth import login, authenticate |
48 | 48 |
from django.core.urlresolvers import reverse |
49 |
from django.core.exceptions import ValidationError |
|
49 | 50 |
|
50 | 51 |
from astakos.im.models import AstakosUser, Invitation, ApprovalTerms |
51 | 52 |
from astakos.im.settings import INVITATIONS_PER_LEVEL, COOKIE_NAME, COOKIE_DOMAIN, COOKIE_SECURE, FORCE_PROFILE_UPDATE |
... | ... | |
70 | 71 |
def epoch(datetime): |
71 | 72 |
return int(time.mktime(datetime.timetuple())*1000) |
72 | 73 |
|
73 |
def get_or_create_user(email, realname='', first_name='', last_name='', affiliation='', level=0, provider='local', password=''): |
|
74 |
"""Find or register a user into the internal database |
|
75 |
and issue a token for subsequent requests. |
|
76 |
""" |
|
77 |
user, created = AstakosUser.objects.get_or_create(email=email, |
|
78 |
defaults={ |
|
79 |
'password':password, |
|
80 |
'affiliation':affiliation, |
|
81 |
'level':level, |
|
82 |
'invitations':INVITATIONS_PER_LEVEL.get(level, 0), |
|
83 |
'provider':provider, |
|
84 |
'realname':realname, |
|
85 |
'first_name':first_name, |
|
86 |
'last_name':last_name |
|
87 |
}) |
|
88 |
if created: |
|
89 |
user.renew_token() |
|
90 |
user.save() |
|
91 |
logger.info('Created user %s', user) |
|
92 |
|
|
93 |
return user |
|
94 |
|
|
95 | 74 |
def get_context(request, extra_context={}, **kwargs): |
96 | 75 |
if not extra_context: |
97 | 76 |
extra_context = {} |
... | ... | |
131 | 110 |
renew = renew or (user.auth_token_expires and user.auth_token_expires < datetime.datetime.now()) |
132 | 111 |
if renew: |
133 | 112 |
user.renew_token() |
134 |
user.save() |
|
113 |
try: |
|
114 |
user.save() |
|
115 |
except ValidationError, e: |
|
116 |
return HttpResponseBadRequest(e) |
|
135 | 117 |
|
136 | 118 |
if FORCE_PROFILE_UPDATE and not user.is_verified and not user.is_superuser: |
137 | 119 |
params = '' |
b/snf-astakos-app/astakos/im/views.py | ||
---|---|---|
39 | 39 |
from functools import wraps |
40 | 40 |
|
41 | 41 |
from django.core.mail import send_mail |
42 |
from django.http import HttpResponse |
|
42 |
from django.http import HttpResponse, HttpResponseBadRequest
|
|
43 | 43 |
from django.shortcuts import redirect |
44 | 44 |
from django.template.loader import render_to_string |
45 | 45 |
from django.utils.translation import ugettext as _ |
... | ... | |
52 | 52 |
from django.http import HttpResponseRedirect, HttpResponseBadRequest |
53 | 53 |
from django.db.utils import IntegrityError |
54 | 54 |
from django.contrib.auth.views import password_change |
55 |
from django.core.exceptions import ValidationError |
|
55 | 56 |
|
56 | 57 |
from astakos.im.models import AstakosUser, Invitation, ApprovalTerms |
57 | 58 |
from astakos.im.activation_backends import get_backend, SimpleBackend |
... | ... | |
440 | 441 |
except AstakosUser.DoesNotExist: |
441 | 442 |
user.is_active = True |
442 | 443 |
user.email_verified = True |
443 |
user.save() |
|
444 |
try: |
|
445 |
user.save() |
|
446 |
except ValidationError, e: |
|
447 |
return HttpResponseBadRequest(e) |
|
448 |
|
|
444 | 449 |
else: |
445 | 450 |
# switch the local account to shibboleth one |
446 | 451 |
local_user.provider = 'shibboleth' |
447 | 452 |
local_user.set_unusable_password() |
448 | 453 |
local_user.third_party_identifier = user.third_party_identifier |
449 |
local_user.save() |
|
454 |
try: |
|
455 |
local_user.save() |
|
456 |
except ValidationError, e: |
|
457 |
return HttpResponseBadRequest(e) |
|
450 | 458 |
user.delete() |
451 | 459 |
user = local_user |
452 | 460 |
|
Also available in: Unified diff