Revision aab4d540
b/snf-astakos-app/astakos/im/activation_backends.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
from django.utils.importlib import import_module |
35 | 35 |
from django.core.exceptions import ImproperlyConfigured |
36 |
from django.core.mail import send_mail |
|
37 |
from django.template.loader import render_to_string |
|
38 |
from django.contrib import messages |
|
39 |
from django.core.urlresolvers import reverse |
|
40 | 36 |
from django.utils.translation import ugettext as _ |
41 |
from django.db import transaction |
|
42 | 37 |
|
43 |
from urlparse import urljoin |
|
44 |
|
|
45 |
from astakos.im.models import AstakosUser, Invitation |
|
46 |
from astakos.im.forms import * |
|
38 |
from astakos.im.models import AstakosUser |
|
47 | 39 |
from astakos.im.util import get_invitation |
48 | 40 |
from astakos.im.functions import send_verification, send_activation, \ |
49 |
send_admin_notification, activate, SendMailError |
|
50 |
from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, \ |
|
51 |
DEFAULT_FROM_EMAIL, MODERATION_ENABLED, SITENAME, DEFAULT_ADMIN_EMAIL, RE_USER_EMAIL_PATTERNS |
|
41 |
send_admin_notification, activate |
|
42 |
from astakos.im.settings import INVITATIONS_ENABLED, MODERATION_ENABLED, SITENAME, RE_USER_EMAIL_PATTERNS |
|
52 | 43 |
|
53 |
import socket |
|
54 | 44 |
import logging |
55 | 45 |
import re |
56 | 46 |
|
... | ... | |
76 | 66 |
try: |
77 | 67 |
backend_class = getattr(mod, backend_class_name) |
78 | 68 |
except AttributeError: |
79 |
raise ImproperlyConfigured('Module "%s" does not define a activation backend named "%s"' % (module, attr))
|
|
69 |
raise ImproperlyConfigured('Module "%s" does not define a activation backend named "%s"' % (module, backend_class_name))
|
|
80 | 70 |
return backend_class(request) |
81 | 71 |
|
82 | 72 |
class ActivationBackend(object): |
73 |
def __init__(self, request): |
|
74 |
self.request = request |
|
75 |
|
|
83 | 76 |
def _is_preaccepted(self, user): |
84 | 77 |
# return True if user email matches specific patterns |
85 | 78 |
for pattern in RE_USER_EMAIL_PATTERNS: |
... | ... | |
150 | 143 |
account is created and the user is going to receive an email as soon as an |
151 | 144 |
administrator activates his/her account. |
152 | 145 |
""" |
153 |
def __init__(self, request): |
|
154 |
self.request = request |
|
155 |
super(InvitationsBackend, self).__init__() |
|
156 | 146 |
|
157 | 147 |
def get_signup_form(self, provider='local', instance=None): |
158 | 148 |
""" |
... | ... | |
215 | 205 |
supplies the necessary registation information, an incative user account is |
216 | 206 |
created and receives an email in order to activate his/her account. |
217 | 207 |
""" |
218 |
def __init__(self, request): |
|
219 |
self.request = request |
|
220 |
super(SimpleBackend, self).__init__() |
|
221 |
|
|
222 | 208 |
def _is_preaccepted(self, user): |
223 | 209 |
if super(SimpleBackend, self)._is_preaccepted(user): |
224 | 210 |
return True |
b/snf-astakos-app/astakos/im/api/__init__.py | ||
---|---|---|
41 | 41 |
from django.core.urlresolvers import reverse |
42 | 42 |
|
43 | 43 |
from astakos.im.models import AstakosUser, GroupKind, Service, Resource |
44 |
from astakos.im.api.faults import Fault, ItemNotFound, InternalServerError |
|
44 |
from astakos.im.api.faults import Fault, ItemNotFound, InternalServerError, BadRequest
|
|
45 | 45 |
from astakos.im.settings import INVITATIONS_ENABLED, COOKIE_NAME, EMAILCHANGE_ENABLED |
46 | 46 |
|
47 | 47 |
import logging |
... | ... | |
83 | 83 |
def _get_user_by_username(user_id): |
84 | 84 |
try: |
85 | 85 |
user = AstakosUser.objects.get(username = user_id) |
86 |
except AstakosUser.DoesNotExist, e:
|
|
86 |
except AstakosUser.DoesNotExist: |
|
87 | 87 |
raise ItemNotFound('Invalid userid') |
88 | 88 |
else: |
89 | 89 |
response = HttpResponse() |
... | ... | |
107 | 107 |
raise BadRequest('Email missing') |
108 | 108 |
try: |
109 | 109 |
user = AstakosUser.objects.get(email = email) |
110 |
except AstakosUser.DoesNotExist, e:
|
|
110 |
except AstakosUser.DoesNotExist: |
|
111 | 111 |
raise ItemNotFound('Invalid email') |
112 | 112 |
|
113 | 113 |
if not user.is_active: |
b/snf-astakos-app/astakos/im/api/admin.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
from functools import wraps |
37 | 37 |
from time import time, mktime |
38 |
from urlparse import urlparse |
|
39 |
from collections import defaultdict |
|
40 | 38 |
|
41 | 39 |
from django.http import HttpResponse |
42 | 40 |
from django.utils import simplejson as json |
43 | 41 |
|
44 |
from astakos.im.api.faults import * |
|
45 |
from astakos.im.api import render_fault |
|
46 |
from astakos.im.models import AstakosUser, Service |
|
42 |
from astakos.im.api.faults import (Fault, Unauthorized, InternalServerError, BadRequest, |
|
43 |
Forbidden) |
|
44 |
from astakos.im.api import render_fault, _get_user_by_email, _get_user_by_username |
|
45 |
from astakos.im.models import AstakosUser |
|
47 | 46 |
from astakos.im.util import epoch |
48 |
from astakos.im.api import _get_user_by_email, _get_user_by_username |
|
49 | 47 |
|
50 | 48 |
logger = logging.getLogger(__name__) |
51 | 49 |
format = ('%a, %d %b %Y %H:%M:%S GMT') |
b/snf-astakos-app/astakos/im/api/service.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
from functools import wraps |
37 | 37 |
from time import time, mktime |
38 |
from urlparse import urlparse |
|
39 |
from collections import defaultdict |
|
40 | 38 |
|
41 | 39 |
from django.http import HttpResponse |
42 | 40 |
from django.views.decorators.csrf import csrf_exempt |
43 | 41 |
|
44 |
from astakos.im.api.faults import *
|
|
45 |
from astakos.im.api import render_fault |
|
42 |
from astakos.im.api.faults import Fault, Unauthorized, InternalServerError, BadRequest
|
|
43 |
from astakos.im.api import render_fault, _get_user_by_email, _get_user_by_username
|
|
46 | 44 |
from astakos.im.models import AstakosUser, Service |
47 |
from astakos.im.util import epoch |
|
48 | 45 |
from astakos.im.forms import FeedbackForm |
49 |
from astakos.im.functions import send_feedback as send_feedback_func, SendMailError
|
|
46 |
from astakos.im.functions import send_feedback as send_feedback_func |
|
50 | 47 |
|
51 | 48 |
logger = logging.getLogger(__name__) |
52 | 49 |
|
b/snf-astakos-app/astakos/im/context_processors.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from astakos.im.settings import IM_MODULES, INVITATIONS_ENABLED, IM_STATIC_URL, \ |
35 |
COOKIE_NAME, LOGIN_MESSAGES, SIGNUP_MESSAGES, PROFILE_MESSAGES, \
|
|
35 |
LOGIN_MESSAGES, SIGNUP_MESSAGES, PROFILE_MESSAGES, \ |
|
36 | 36 |
GLOBAL_MESSAGES, PROFILE_EXTRA_LINKS |
37 | 37 |
from astakos.im.api import get_menu |
38 | 38 |
from astakos.im.util import get_query |
39 | 39 |
from astakos.im.models import GroupKind |
40 | 40 |
|
41 |
from django.conf import settings |
|
42 |
from django.core.urlresolvers import reverse |
|
43 | 41 |
from django.utils import simplejson as json |
44 | 42 |
|
45 | 43 |
def im_modules(request): |
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
from urlparse import urljoin |
34 |
from datetime import datetime |
|
35 | 34 |
|
36 | 35 |
from django import forms |
37 | 36 |
from django.utils.translation import ugettext as _ |
38 |
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, \
|
|
37 |
from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm,
|
|
39 | 38 |
PasswordResetForm, PasswordChangeForm |
39 |
) |
|
40 | 40 |
from django.core.mail import send_mail |
41 | 41 |
from django.contrib.auth.tokens import default_token_generator |
42 | 42 |
from django.template import Context, loader |
43 | 43 |
from django.utils.http import int_to_base36 |
44 | 44 |
from django.core.urlresolvers import reverse |
45 |
from django.utils.functional import lazy |
|
46 | 45 |
from django.utils.safestring import mark_safe |
47 |
from django.contrib import messages |
|
48 | 46 |
from django.utils.encoding import smart_str |
49 | 47 |
from django.forms.extras.widgets import SelectDateWidget |
50 |
from django.db.models import Q |
|
51 |
from django.db.models.query import EmptyQuerySet |
|
52 | 48 |
|
53 |
from astakos.im.models import * |
|
54 |
from astakos.im.settings import INVITATIONS_PER_LEVEL, DEFAULT_FROM_EMAIL, \ |
|
55 |
BASEURL, SITENAME, RECAPTCHA_PRIVATE_KEY, DEFAULT_CONTACT_EMAIL, \ |
|
49 |
from astakos.im.models import (AstakosUser, EmailChange, AstakosGroup, Invitation, |
|
50 |
Membership, GroupKind, get_latest_terms |
|
51 |
) |
|
52 |
from astakos.im.settings import (INVITATIONS_PER_LEVEL, DEFAULT_FROM_EMAIL, |
|
53 |
BASEURL, SITENAME, RECAPTCHA_PRIVATE_KEY, DEFAULT_CONTACT_EMAIL, |
|
56 | 54 |
RECAPTCHA_ENABLED, LOGGING_LEVEL |
55 |
) |
|
57 | 56 |
from astakos.im.widgets import DummyWidget, RecaptchaWidget |
58 | 57 |
from astakos.im.functions import send_change_email |
59 | 58 |
|
60 |
# since Django 1.4 use django.core.urlresolvers.reverse_lazy instead |
|
61 |
from astakos.im.util import reverse_lazy, reserved_email, get_query |
|
59 |
from astakos.im.util import reserved_email, get_query |
|
62 | 60 |
|
63 | 61 |
import logging |
64 | 62 |
import hashlib |
... | ... | |
150 | 148 |
user.renew_token() |
151 | 149 |
if commit: |
152 | 150 |
user.save() |
153 |
logger._log(LOGGING_LEVEL, 'Created user %s' % user.email, [])
|
|
151 |
logger.log(LOGGING_LEVEL, 'Created user %s' % user.email)
|
|
154 | 152 |
return user |
155 | 153 |
|
156 | 154 |
class InvitedLocalUserCreationForm(LocalUserCreationForm): |
... | ... | |
231 | 229 |
user.provider = get_query(self.request).get('provider') |
232 | 230 |
if commit: |
233 | 231 |
user.save() |
234 |
logger._log(LOGGING_LEVEL, 'Created user %s' % user.email, [])
|
|
232 |
logger.log(LOGGING_LEVEL, 'Created user %s' % user.email)
|
|
235 | 233 |
return user |
236 | 234 |
|
237 | 235 |
class InvitedThirdPartyUserCreationForm(ThirdPartyUserCreationForm): |
... | ... | |
392 | 390 |
user = AstakosUser.objects.get(email=email, is_active=True) |
393 | 391 |
if not user.has_usable_password(): |
394 | 392 |
raise forms.ValidationError(_("This account has not a usable password.")) |
395 |
except AstakosUser.DoesNotExist, e:
|
|
393 |
except AstakosUser.DoesNotExist: |
|
396 | 394 |
raise forms.ValidationError(_('That e-mail address doesn\'t have an associated user account. Are you sure you\'ve registered?')) |
397 | 395 |
return email |
398 | 396 |
|
b/snf-astakos-app/astakos/im/functions.py | ||
---|---|---|
51 | 51 |
|
52 | 52 |
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, \ |
53 | 53 |
SITENAME, BASEURL, DEFAULT_ADMIN_EMAIL, LOGGING_LEVEL |
54 |
from astakos.im.models import Invitation, AstakosUser
|
|
54 |
from astakos.im.models import AstakosUser |
|
55 | 55 |
|
56 | 56 |
logger = logging.getLogger(__name__) |
57 | 57 |
|
... | ... | |
68 | 68 |
email = user.email if user and user.is_authenticated() else '' |
69 | 69 |
r = func(*args, **kwargs) |
70 | 70 |
if LOGGING_LEVEL: |
71 |
logger._log(LOGGING_LEVEL, msg % email, [])
|
|
71 |
logger.log(LOGGING_LEVEL, msg % email)
|
|
72 | 72 |
return r |
73 | 73 |
return with_logging |
74 | 74 |
|
... | ... | |
98 | 98 |
raise SendVerificationError() |
99 | 99 |
else: |
100 | 100 |
msg = 'Sent activation %s' % user.email |
101 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
101 |
logger.log(LOGGING_LEVEL, msg)
|
|
102 | 102 |
|
103 | 103 |
def send_activation(user, template_name='im/activation_email.txt'): |
104 | 104 |
send_verification(user, template_name) |
... | ... | |
106 | 106 |
user.save() |
107 | 107 |
|
108 | 108 |
def send_admin_notification(template_name, |
109 |
dictionary={},
|
|
109 |
dictionary=None,
|
|
110 | 110 |
subject='alpha2 testing notification', |
111 | 111 |
): |
112 | 112 |
""" |
... | ... | |
116 | 116 |
""" |
117 | 117 |
if not DEFAULT_ADMIN_EMAIL: |
118 | 118 |
return |
119 |
dictionary = dictionary or {} |
|
119 | 120 |
message = render_to_string(template_name, dictionary) |
120 | 121 |
sender = DEFAULT_FROM_EMAIL |
121 | 122 |
try: |
... | ... | |
125 | 126 |
raise SendNotificationError() |
126 | 127 |
else: |
127 | 128 |
msg = 'Sent admin notification for user %s' % dictionary |
128 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
129 |
logger.log(LOGGING_LEVEL, msg)
|
|
129 | 130 |
|
130 | 131 |
def send_helpdesk_notification(user, template_name='im/account_notification.txt'): |
131 | 132 |
""" |
... | ... | |
152 | 153 |
raise SendNotificationError() |
153 | 154 |
else: |
154 | 155 |
msg = 'Sent helpdesk admin notification for %s' % user.email |
155 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
156 |
logger.log(LOGGING_LEVEL, msg)
|
|
156 | 157 |
|
157 | 158 |
def send_invitation(invitation, template_name='im/invitation.txt'): |
158 | 159 |
""" |
... | ... | |
162 | 163 |
""" |
163 | 164 |
subject = _('Invitation to %s alpha2 testing' % SITENAME) |
164 | 165 |
url = '%s?code=%d' % (urljoin(BASEURL, reverse('index')), invitation.code) |
165 |
message = render_to_string('im/invitation.txt', {
|
|
166 |
message = render_to_string(template_name, {
|
|
166 | 167 |
'invitation': invitation, |
167 | 168 |
'url': url, |
168 | 169 |
'baseurl': BASEURL, |
... | ... | |
176 | 177 |
raise SendInvitationError() |
177 | 178 |
else: |
178 | 179 |
msg = 'Sent invitation %s' % invitation |
179 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
180 |
logger.log(LOGGING_LEVEL, msg)
|
|
180 | 181 |
|
181 | 182 |
def send_greeting(user, email_template_name='im/welcome_email.txt'): |
182 | 183 |
""" |
... | ... | |
199 | 200 |
raise SendGreetingError() |
200 | 201 |
else: |
201 | 202 |
msg = 'Sent greeting %s' % user.email |
202 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
203 |
logger.log(LOGGING_LEVEL, msg)
|
|
203 | 204 |
|
204 | 205 |
def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'): |
205 | 206 |
subject = _("Feedback from %s alpha2 testing" % SITENAME) |
... | ... | |
216 | 217 |
raise SendFeedbackError() |
217 | 218 |
else: |
218 | 219 |
msg = 'Sent feedback from %s' % user.email |
219 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
220 |
logger.log(LOGGING_LEVEL, msg)
|
|
220 | 221 |
|
221 | 222 |
def send_change_email(ec, request, email_template_name='registration/email_change_email.txt'): |
222 | 223 |
try: |
... | ... | |
233 | 234 |
raise ChangeEmailError() |
234 | 235 |
else: |
235 | 236 |
msg = 'Sent change email for %s' % ec.user.email |
236 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
237 |
logger.log(LOGGING_LEVEL, msg)
|
|
237 | 238 |
|
238 | 239 |
def activate(user, email_template_name='im/welcome_email.txt', |
239 | 240 |
helpdesk_email_template_name='im/helpdesk_notification.txt', verify_email=False): |
b/snf-astakos-app/astakos/im/management/commands/_common.py | ||
---|---|---|
104 | 104 |
content_type=content_type) |
105 | 105 |
user.user_permissions.remove(p) |
106 | 106 |
return 1 |
107 |
except Permission.DoesNotExist, e:
|
|
107 |
except Permission.DoesNotExist: |
|
108 | 108 |
return -1 |
109 | 109 |
|
110 | 110 |
def remove_group_permission(group, pname): |
... | ... | |
116 | 116 |
content_type=content_type) |
117 | 117 |
group.permissions.remove(p) |
118 | 118 |
return 1 |
119 |
except Permission.DoesNotExist, e:
|
|
119 |
except Permission.DoesNotExist: |
|
120 | 120 |
return -1 |
b/snf-astakos-app/astakos/im/management/commands/group_add.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from optparse import make_option |
|
35 |
from random import choice |
|
36 |
from string import digits, lowercase, uppercase |
|
37 |
from uuid import uuid4 |
|
38 |
from time import time |
|
39 |
from os.path import abspath |
|
40 |
|
|
41 | 34 |
from django.core.management.base import BaseCommand, CommandError |
42 | 35 |
|
43 | 36 |
from astakos.im.models import AstakosGroup |
b/snf-astakos-app/astakos/im/management/commands/group_list.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
from django.core.management.base import BaseCommand, CommandError |
37 | 37 |
|
38 |
from astakos.im.models import AstakosUser, AstakosGroup
|
|
38 |
from astakos.im.models import AstakosGroup |
|
39 | 39 |
|
40 | 40 |
from ._common import format_bool |
41 | 41 |
|
b/snf-astakos-app/astakos/im/management/commands/group_update.py | ||
---|---|---|
34 | 34 |
from optparse import make_option |
35 | 35 |
|
36 | 36 |
from django.core.management.base import BaseCommand, CommandError |
37 |
from django.contrib.auth.models import Permission |
|
38 |
from django.contrib.contenttypes.models import ContentType |
|
39 |
from django.core.exceptions import ValidationError |
|
40 | 37 |
|
41 |
from astakos.im.models import AstakosUser, AstakosGroup
|
|
42 |
from ._common import add_group_permission |
|
38 |
from astakos.im.models import AstakosGroup |
|
39 |
from ._common import add_group_permission, remove_group_permission
|
|
43 | 40 |
|
44 | 41 |
class Command(BaseCommand): |
45 | 42 |
args = "<groupname>" |
... | ... | |
73 | 70 |
raise CommandError("Invalid group") |
74 | 71 |
|
75 | 72 |
try: |
76 |
content_type = ContentType.objects.get(app_label='im', |
|
77 |
model='astakosuser') |
|
78 |
|
|
79 | 73 |
pname = options.get('add-permission') |
80 | 74 |
if pname: |
81 | 75 |
r, created = add_group_permission(group, pname) |
b/snf-astakos-app/astakos/im/management/commands/resource_add.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
import socket |
|
35 |
|
|
36 |
from optparse import make_option |
|
37 |
|
|
38 | 34 |
from django.core.management.base import BaseCommand, CommandError |
39 | 35 |
from django.db.utils import IntegrityError |
40 | 36 |
|
41 |
from astakos.im.models import Resource, ResourceMetadata, Service
|
|
37 |
from astakos.im.models import Resource, Service |
|
42 | 38 |
|
43 | 39 |
class Command(BaseCommand): |
44 | 40 |
args = "<service> <resource> [<key>=<value>...]" |
b/snf-astakos-app/astakos/im/management/commands/term_add.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from optparse import make_option |
|
35 |
from random import choice |
|
36 |
from string import digits, lowercase, uppercase |
|
37 |
from uuid import uuid4 |
|
38 |
from time import time |
|
39 | 34 |
from os.path import abspath |
40 | 35 |
|
41 | 36 |
from django.core.management.base import BaseCommand, CommandError |
... | ... | |
52 | 47 |
|
53 | 48 |
location = abspath(args[0].decode('utf8')) |
54 | 49 |
try: |
55 |
f = open(location, 'r')
|
|
50 |
open(location, 'r') |
|
56 | 51 |
except IOError: |
57 | 52 |
raise CommandError("Invalid location") |
58 | 53 |
|
b/snf-astakos-app/astakos/im/management/commands/user_add.py | ||
---|---|---|
34 | 34 |
import socket |
35 | 35 |
|
36 | 36 |
from optparse import make_option |
37 |
from random import choice |
|
38 |
from string import digits, lowercase, uppercase |
|
39 | 37 |
from uuid import uuid4 |
40 | 38 |
from datetime import datetime |
41 | 39 |
|
b/snf-astakos-app/astakos/im/management/commands/user_invite.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
import socket |
|
35 |
|
|
36 | 34 |
from django.core.management.base import BaseCommand, CommandError |
37 | 35 |
from django.db.utils import IntegrityError |
38 | 36 |
from django.db import transaction |
b/snf-astakos-app/astakos/im/management/commands/user_update.py | ||
---|---|---|
35 | 35 |
from datetime import datetime |
36 | 36 |
|
37 | 37 |
from django.core.management.base import BaseCommand, CommandError |
38 |
from django.contrib.auth.models import Permission |
|
39 |
from django.contrib.contenttypes.models import ContentType |
|
40 | 38 |
from django.core.exceptions import ValidationError |
41 | 39 |
from django.db.utils import IntegrityError |
42 | 40 |
|
b/snf-astakos-app/astakos/im/middleware.py | ||
---|---|---|
35 | 35 |
from django.contrib.auth import authenticate |
36 | 36 |
|
37 | 37 |
from astakos.im.settings import COOKIE_NAME |
38 |
from astakos.im.models import AstakosUser |
|
39 | 38 |
from astakos.im.functions import login |
40 | 39 |
|
41 | 40 |
class CookieAuthenticationMiddleware(object): |
b/snf-astakos-app/astakos/im/migrations/0001_initial.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0002_auto__add_field_astakosuser_third_party_identifier.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0003_auto__add_unique_invitation_username.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0004_auto__add_field_astakosuser_email_verified.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0005_auto__add_field_astakosuser_has_credits.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0006_auto__add_approvalterms__add_field_astakosuser_has_signed_terms__add_f.py | ||
---|---|---|
2 | 2 |
import datetime |
3 | 3 |
from south.db import db |
4 | 4 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 5 |
|
7 | 6 |
class Migration(SchemaMigration): |
8 | 7 |
|
b/snf-astakos-app/astakos/im/migrations/0007_auto__chg_field_astakosuser_email_verified__chg_field_astakosuser_has_.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0008_auto__add_emailchange.py | ||
---|---|---|
2 | 2 |
import datetime |
3 | 3 |
from south.db import db |
4 | 4 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 5 |
|
7 | 6 |
class Migration(SchemaMigration): |
8 | 7 |
|
b/snf-astakos-app/astakos/im/migrations/0009_auto__add_service.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0010_auto__add_field_astakosuser_activation_sent__chg_field_service_url.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0011_set_old_activation_sent.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 | 2 |
import datetime |
3 |
from south.db import db |
|
4 | 3 |
from south.v2 import DataMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(DataMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0012_auto__add_additionalmail.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0013_auto__del_unique_additionalmail_email.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0014_auto__add_unique_astakosuser_third_party_identifier_provider.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 | 2 |
from south.db import db |
4 | 3 |
from south.v2 import SchemaMigration |
5 |
from django.db import models |
|
6 | 4 |
|
7 | 5 |
class Migration(SchemaMigration): |
8 | 6 |
|
b/snf-astakos-app/astakos/im/migrations/0016_populate_group_data.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 | 2 |
import datetime |
3 |
from south.db import db |
|
4 | 3 |
from south.v2 import DataMigration |
5 |
from django.db import models |
|
6 | 4 |
from django.db.models import Count |
7 | 5 |
|
8 | 6 |
class Migration(DataMigration): |
b/snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py | ||
---|---|---|
1 | 1 |
# encoding: utf-8 |
2 |
import datetime |
|
3 |
import sys |
|
4 | 2 |
|
5 |
from south.db import db |
|
6 | 3 |
from south.v2 import DataMigration |
7 |
from django.db import models |
|
8 |
from django.db.utils import IntegrityError |
|
9 |
from collections import defaultdict |
|
10 |
from django.db.models import Q |
|
11 | 4 |
|
12 | 5 |
d = { |
13 | 6 |
'cyclades' : { 'vm' : 2 }, |
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
34 | 34 |
import hashlib |
35 | 35 |
import uuid |
36 | 36 |
import logging |
37 |
import json |
|
38 | 37 |
|
39 | 38 |
from time import asctime |
40 | 39 |
from datetime import datetime, timedelta |
41 | 40 |
from base64 import b64encode |
42 |
from urlparse import urlparse, urlunparse
|
|
41 |
from urlparse import urlparse |
|
43 | 42 |
from random import randint |
44 | 43 |
from collections import defaultdict |
45 |
from south.signals import post_migrate |
|
46 | 44 |
|
47 |
from django.db import models, IntegrityError
|
|
45 |
from django.db import models |
|
48 | 46 |
from django.contrib.auth.models import User, UserManager, Group |
49 | 47 |
from django.utils.translation import ugettext as _ |
50 | 48 |
from django.core.exceptions import ValidationError |
51 |
from django.template.loader import render_to_string |
|
52 |
from django.core.mail import send_mail |
|
53 | 49 |
from django.db import transaction |
54 | 50 |
from django.db.models.signals import post_save, post_syncdb |
55 |
from django.db.models import Q, Count
|
|
51 |
from django.db.models import Q |
|
56 | 52 |
|
57 | 53 |
from astakos.im.settings import DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL, \ |
58 |
AUTH_TOKEN_DURATION, BILLING_FIELDS, QUEUE_CONNECTION, SITENAME, \
|
|
54 |
AUTH_TOKEN_DURATION, BILLING_FIELDS, QUEUE_CONNECTION, \ |
|
59 | 55 |
EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL |
60 | 56 |
|
61 | 57 |
QUEUE_CLIENT_ID = 3 # Astakos. |
... | ... | |
294 | 290 |
username = uuid.uuid4().hex[:30] |
295 | 291 |
try: |
296 | 292 |
AstakosUser.objects.get(username = username) |
297 |
except AstakosUser.DoesNotExist, e:
|
|
293 |
except AstakosUser.DoesNotExist: |
|
298 | 294 |
self.username = username |
299 | 295 |
if not self.provider: |
300 | 296 |
self.provider = 'local' |
... | ... | |
317 | 313 |
self.auth_token_expires = self.auth_token_created + \ |
318 | 314 |
timedelta(hours=AUTH_TOKEN_DURATION) |
319 | 315 |
msg = 'Token renewed for %s' % self.email |
320 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
316 |
logger.log(LOGGING_LEVEL, msg)
|
|
321 | 317 |
|
322 | 318 |
def __unicode__(self): |
323 | 319 |
return '%s (%s)' % (self.realname, self.email) |
b/snf-astakos-app/astakos/im/queue/listener.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
import logging |
35 |
import json |
|
36 | 35 |
|
37 | 36 |
from astakos.im.functions import set_user_credibility |
38 | 37 |
|
b/snf-astakos-app/astakos/im/queue/userevent.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
from time import time |
37 | 37 |
from hashlib import sha1 |
38 |
from random import random |
|
39 | 38 |
|
40 | 39 |
class UserEvent(object): |
41 |
def __init__(self, client, user, eventType, details={}):
|
|
40 |
def __init__(self, client, user, eventType, details=None):
|
|
42 | 41 |
self.eventVersion = '1' |
43 | 42 |
self.occurredMillis = int(time() * 1000) |
44 | 43 |
self.receivedMillis = self.occurredMillis |
... | ... | |
47 | 46 |
self.isActive = user.is_active |
48 | 47 |
self.role = 'default' |
49 | 48 |
self.eventType = eventType |
50 |
self.details = details |
|
49 |
self.details = details or {}
|
|
51 | 50 |
hash = sha1() |
52 |
hash.update(json.dumps([client, self.userID, self.isActive, self.role, |
|
53 |
self.eventType, self.details, self.occurredMillis])) |
|
51 |
hash.update(json.dumps([client, |
|
52 |
self.userID, |
|
53 |
self.isActive, |
|
54 |
self.role, |
|
55 |
self.eventType, |
|
56 |
self.details, |
|
57 |
self.occurredMillis |
|
58 |
] |
|
59 |
) |
|
60 |
) |
|
54 | 61 |
self.id = hash.hexdigest() |
55 | 62 |
|
56 | 63 |
def format(self): |
b/snf-astakos-app/astakos/im/target/local.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from django.http import HttpResponseBadRequest |
|
35 | 34 |
from django.shortcuts import render_to_response |
36 | 35 |
from django.template import RequestContext |
37 |
from django.contrib.auth import authenticate |
|
38 | 36 |
from django.contrib import messages |
39 | 37 |
from django.utils.translation import ugettext as _ |
40 | 38 |
from django.views.decorators.csrf import csrf_exempt |
41 | 39 |
|
42 | 40 |
from astakos.im.util import prepare_response, get_query |
43 | 41 |
from astakos.im.views import requires_anonymous |
44 |
from astakos.im.models import AstakosUser |
|
45 | 42 |
from astakos.im.forms import LoginForm |
46 | 43 |
from astakos.im.settings import RATELIMIT_RETRIES_ALLOWED |
47 | 44 |
|
... | ... | |
58 | 55 |
on_failure: the template name to render on login failure |
59 | 56 |
""" |
60 | 57 |
was_limited = getattr(request, 'limited', False) |
61 |
form = LoginForm(data=request.POST, was_limited=was_limited, request=request) |
|
58 |
form = LoginForm(data=request.POST, |
|
59 |
was_limited=was_limited, |
|
60 |
request=request |
|
61 |
) |
|
62 | 62 |
next = get_query(request).get('next', '') |
63 | 63 |
if not form.is_valid(): |
64 | 64 |
return render_to_response(on_failure, |
b/snf-astakos-app/astakos/im/target/redirect.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from django.core.urlresolvers import reverse |
35 |
from django.shortcuts import redirect |
|
36 | 35 |
from django.utils.translation import ugettext as _ |
37 |
from django.contrib import messages |
|
38 | 36 |
from django.utils.http import urlencode |
39 | 37 |
from django.contrib.auth import authenticate |
40 | 38 |
from django.http import HttpResponse, HttpResponseBadRequest |
41 | 39 |
from django.core.exceptions import ValidationError |
42 | 40 |
|
43 |
from urllib import quote |
|
44 |
from urlparse import urlunsplit, urlsplit, urlparse, parse_qsl |
|
41 |
from urlparse import urlunsplit, urlsplit, parse_qsl |
|
45 | 42 |
|
46 | 43 |
from astakos.im.settings import COOKIE_NAME, COOKIE_DOMAIN |
47 | 44 |
from astakos.im.util import set_cookie |
... | ... | |
95 | 92 |
except ValidationError, e: |
96 | 93 |
return HttpResponseBadRequest(e) |
97 | 94 |
# authenticate before login |
98 |
user = authenticate(email=request.user.email, auth_token=request.user.auth_token) |
|
95 |
user = authenticate(email=request.user.email, |
|
96 |
auth_token=request.user.auth_token |
|
97 |
) |
|
99 | 98 |
auth_login(request, user) |
100 | 99 |
set_cookie(response, user) |
101 | 100 |
logger.info('Token reset for %s' % request.user.email) |
102 | 101 |
parts = list(urlsplit(next)) |
103 |
parts[3] = urlencode({'user': request.user.email, 'token': request.user.auth_token}) |
|
102 |
parts[3] = urlencode({'user': request.user.email, |
|
103 |
'token': request.user.auth_token |
|
104 |
} |
|
105 |
) |
|
104 | 106 |
url = urlunsplit(parts) |
105 | 107 |
response['Location'] = url |
106 | 108 |
response.status_code = 302 |
b/snf-astakos-app/astakos/im/target/shibboleth.py | ||
---|---|---|
36 | 36 |
from django.contrib import messages |
37 | 37 |
from django.template import RequestContext |
38 | 38 |
|
39 |
from astakos.im.util import prepare_response, get_context, get_invitation
|
|
39 |
from astakos.im.util import prepare_response, get_context |
|
40 | 40 |
from astakos.im.views import requires_anonymous, render_response |
41 |
from astakos.im.settings import DEFAULT_USER_LEVEL |
|
42 |
from astakos.im.models import AstakosUser, Invitation, AdditionalMail |
|
41 |
from astakos.im.models import AstakosUser |
|
43 | 42 |
from astakos.im.forms import LoginForm |
44 | 43 |
from astakos.im.activation_backends import get_backend, SimpleBackend |
45 | 44 |
|
... | ... | |
55 | 54 |
SHIB_MAIL = "HTTP_SHIB_MAIL" |
56 | 55 |
|
57 | 56 |
@requires_anonymous |
58 |
def login(request, backend=None, on_login_template='im/login.html', on_creation_template='im/third_party_registration.html', extra_context={}): |
|
57 |
def login(request, backend=None, on_login_template='im/login.html', |
|
58 |
on_creation_template='im/third_party_registration.html', |
|
59 |
extra_context=None |
|
60 |
): |
|
59 | 61 |
tokens = request.META |
60 | 62 |
|
61 | 63 |
try: |
... | ... | |
76 | 78 |
email = tokens.get(Tokens.SHIB_MAIL, None) |
77 | 79 |
|
78 | 80 |
try: |
79 |
user = AstakosUser.objects.get(provider='shibboleth', third_party_identifier=eppn) |
|
81 |
user = AstakosUser.objects.get(provider='shibboleth', |
|
82 |
third_party_identifier=eppn |
|
83 |
) |
|
80 | 84 |
if user.is_active: |
81 | 85 |
return prepare_response(request, |
82 | 86 |
user, |
... | ... | |
97 | 101 |
backend = get_backend(request) |
98 | 102 |
form = backend.get_signup_form(provider='shibboleth', instance=user) |
99 | 103 |
except Exception, e: |
100 |
form = SimpleBackend(request).get_signup_form(provider='shibboleth', instance=user) |
|
104 |
form = SimpleBackend(request).get_signup_form( |
|
105 |
provider='shibboleth', |
|
106 |
instance=user |
|
107 |
) |
|
101 | 108 |
messages.error(request, e) |
102 | 109 |
return render_response(on_creation_template, |
103 |
signup_form = form, |
|
104 |
provider = 'shibboleth', |
|
105 |
context_instance=get_context(request, extra_context)) |
|
110 |
signup_form = form, |
|
111 |
provider = 'shibboleth', |
|
112 |
context_instance=get_context( |
|
113 |
request, |
|
114 |
extra_context |
|
115 |
) |
|
116 |
) |
b/snf-astakos-app/astakos/im/urls.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from django.conf.urls.defaults import patterns, include, url |
|
35 |
from django.contrib.auth.views import password_change |
|
36 |
from django.views.generic import list_detail |
|
34 |
from django.conf.urls.defaults import patterns, url |
|
37 | 35 |
|
38 | 36 |
from astakos.im.forms import ExtendedPasswordResetForm, ExtendedPasswordChangeForm, LoginForm |
39 | 37 |
from astakos.im.settings import IM_MODULES, INVITATIONS_ENABLED, EMAILCHANGE_ENABLED |
b/snf-astakos-app/astakos/im/util.py | ||
---|---|---|
36 | 36 |
import time |
37 | 37 |
|
38 | 38 |
from urllib import quote |
39 |
from urlparse import urlsplit, urlunsplit |
|
40 | 39 |
|
41 | 40 |
from datetime import tzinfo, timedelta |
42 | 41 |
from django.http import HttpResponse, HttpResponseBadRequest, urlencode |
... | ... | |
46 | 45 |
from django.core.urlresolvers import reverse |
47 | 46 |
from django.core.exceptions import ValidationError |
48 | 47 |
|
49 |
from astakos.im.models import AstakosUser, Invitation, ApprovalTerms
|
|
50 |
from astakos.im.settings import INVITATIONS_PER_LEVEL, COOKIE_NAME, \
|
|
48 |
from astakos.im.models import AstakosUser, Invitation |
|
49 |
from astakos.im.settings import COOKIE_NAME, \ |
|
51 | 50 |
COOKIE_DOMAIN, COOKIE_SECURE, FORCE_PROFILE_UPDATE, LOGGING_LEVEL |
52 | 51 |
from astakos.im.functions import login |
53 | 52 |
|
54 | 53 |
logger = logging.getLogger(__name__) |
55 | 54 |
|
56 | 55 |
class UTC(tzinfo): |
57 |
def utcoffset(self, dt): |
|
58 |
return timedelta(0) |
|
59 |
|
|
60 |
def tzname(self, dt): |
|
61 |
return 'UTC' |
|
62 |
|
|
63 |
def dst(self, dt): |
|
64 |
return timedelta(0) |
|
56 |
def utcoffset(self, dt):
|
|
57 |
return timedelta(0)
|
|
58 |
|
|
59 |
def tzname(self, dt):
|
|
60 |
return 'UTC'
|
|
61 |
|
|
62 |
def dst(self, dt):
|
|
63 |
return timedelta(0)
|
|
65 | 64 |
|
66 | 65 |
def isoformat(d): |
67 |
"""Return an ISO8601 date string that includes a timezone.""" |
|
68 |
|
|
69 |
return d.replace(tzinfo=UTC()).isoformat() |
|
66 |
"""Return an ISO8601 date string that includes a timezone."""
|
|
67 |
|
|
68 |
return d.replace(tzinfo=UTC()).isoformat()
|
|
70 | 69 |
|
71 | 70 |
def epoch(datetime): |
72 | 71 |
return int(time.mktime(datetime.timetuple())*1000) |
73 | 72 |
|
74 |
def get_context(request, extra_context={}, **kwargs): |
|
75 |
if not extra_context: |
|
76 |
extra_context = {} |
|
73 |
def get_context(request, extra_context=None, **kwargs): |
|
74 |
extra_context = extra_context or {} |
|
77 | 75 |
extra_context.update(kwargs) |
78 | 76 |
return RequestContext(request, extra_context) |
79 | 77 |
|
... | ... | |
143 | 141 |
expires=expire_fmt, path='/', |
144 | 142 |
domain=COOKIE_DOMAIN, secure=COOKIE_SECURE) |
145 | 143 |
msg = 'Cookie [expiring %s] set for %s' % (user.auth_token_expires, user.email) |
146 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
144 |
logger.log(LOGGING_LEVEL, msg)
|
|
147 | 145 |
|
148 | 146 |
class lazy_string(object): |
149 | 147 |
def __init__(self, function, *args, **kwargs): |
b/snf-astakos-app/astakos/im/views.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
import logging |
35 |
import socket |
|
36 | 35 |
|
37 |
from smtplib import SMTPException |
|
38 | 36 |
from urllib import quote |
39 | 37 |
from functools import wraps |
38 |
from datetime import datetime, timedelta |
|
40 | 39 |
|
41 | 40 |
from django.contrib import messages |
42 | 41 |
from django.contrib.auth.decorators import login_required |
43 | 42 |
from django.contrib.auth.views import password_change |
44 |
from django.core.exceptions import ValidationError |
|
45 |
from django.core.mail import send_mail |
|
46 | 43 |
from django.core.urlresolvers import reverse |
47 | 44 |
from django.db import transaction |
48 | 45 |
from django.db.models import Q |
... | ... | |
51 | 48 |
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, \ |
52 | 49 |
HttpResponseRedirect, HttpResponseBadRequest |
53 | 50 |
from django.shortcuts import redirect |
54 |
from django.template.loader import render_to_string
|
|
51 |
from django.template import RequestContext, loader
|
|
55 | 52 |
from django.utils.http import urlencode |
56 | 53 |
from django.utils.translation import ugettext as _ |
57 |
from django.views.generic.create_update import * |
|
58 |
from django.views.generic.list_detail import * |
|
54 |
from django.views.generic.create_update import (create_object, delete_object, |
|
55 |
get_model_and_form_class |
|
56 |
) |
|
57 |
from django.views.generic.list_detail import object_list, object_detail |
|
59 | 58 |
|
60 |
from astakos.im.models import AstakosUser, Invitation, ApprovalTerms, AstakosGroup, Resource |
|
59 |
from astakos.im.models import (AstakosUser, ApprovalTerms, AstakosGroup, Resource, |
|
60 |
EmailChange, GroupKind, Membership) |
|
61 | 61 |
from astakos.im.activation_backends import get_backend, SimpleBackend |
62 | 62 |
from astakos.im.util import get_context, prepare_response, set_cookie, get_query |
63 |
from astakos.im.forms import * |
|
64 |
from astakos.im.functions import send_greeting, send_feedback, SendMailError, \ |
|
65 |
invite as invite_func, logout as auth_logout, activate as activate_func, \ |
|
63 |
from astakos.im.forms import (LoginForm, InvitationForm, ProfileForm, FeedbackForm, |
|
64 |
SignApprovalTermsForm, ExtendedPasswordChangeForm, EmailChangeForm, |
|
65 |
AstakosGroupCreationForm, AstakosGroupSearchForm |
|
66 |
) |
|
67 |
from astakos.im.functions import (send_feedback, SendMailError, |
|
68 |
invite as invite_func, logout as auth_logout, activate as activate_func, |
|
66 | 69 |
switch_account_to_shibboleth, send_admin_notification, SendNotificationError |
67 |
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, COOKIE_NAME, COOKIE_DOMAIN, IM_MODULES, SITENAME, LOGOUT_NEXT, LOGGING_LEVEL |
|
70 |
) |
|
71 |
from astakos.im.settings import (COOKIE_NAME, COOKIE_DOMAIN, SITENAME, LOGOUT_NEXT, |
|
72 |
LOGGING_LEVEL |
|
73 |
) |
|
68 | 74 |
|
69 | 75 |
logger = logging.getLogger(__name__) |
70 | 76 |
|
... | ... | |
77 | 83 |
if tab is None: |
78 | 84 |
tab = template.partition('_')[0].partition('.html')[0] |
79 | 85 |
kwargs.setdefault('tab', tab) |
80 |
html = render_to_string(template, kwargs, context_instance=context_instance) |
|
86 |
html = loader.render_to_string(template, kwargs, context_instance=context_instance)
|
|
81 | 87 |
response = HttpResponse(html, status=status) |
82 | 88 |
if reset_cookie: |
83 | 89 |
set_cookie(response, context_instance['request'].user) |
... | ... | |
114 | 120 |
return wrapper |
115 | 121 |
|
116 | 122 |
@signed_terms_required |
117 |
def index(request, login_template_name='im/login.html', profile_template_name='im/profile.html', extra_context={}):
|
|
123 |
def index(request, login_template_name='im/login.html', extra_context=None):
|
|
118 | 124 |
""" |
119 | 125 |
If there is logged on user renders the profile page otherwise renders login page. |
120 | 126 |
|
... | ... | |
146 | 152 |
@login_required |
147 | 153 |
@signed_terms_required |
148 | 154 |
@transaction.commit_manually |
149 |
def invite(request, template_name='im/invitations.html', extra_context={}):
|
|
155 |
def invite(request, template_name='im/invitations.html', extra_context=None):
|
|
150 | 156 |
""" |
151 | 157 |
Allows a user to invite somebody else. |
152 | 158 |
|
... | ... | |
222 | 228 |
|
223 | 229 |
@login_required |
224 | 230 |
@signed_terms_required |
225 |
def edit_profile(request, template_name='im/profile.html', extra_context={}):
|
|
231 |
def edit_profile(request, template_name='im/profile.html', extra_context=None):
|
|
226 | 232 |
""" |
227 | 233 |
Allows a user to edit his/her profile. |
228 | 234 |
|
... | ... | |
251 | 257 |
|
252 | 258 |
* LOGIN_URL: login uri |
253 | 259 |
""" |
260 |
extra_context = extra_context or {} |
|
254 | 261 |
form = ProfileForm(instance=request.user) |
255 | 262 |
extra_context['next'] = request.GET.get('next') |
256 | 263 |
reset_cookie = False |
... | ... | |
279 | 286 |
context_instance = get_context(request, |
280 | 287 |
extra_context)) |
281 | 288 |
|
282 |
def signup(request, template_name='im/signup.html', on_success='im/signup_complete.html', extra_context={}, backend=None):
|
|
289 |
def signup(request, template_name='im/signup.html', on_success='im/signup_complete.html', extra_context=None, backend=None):
|
|
283 | 290 |
""" |
284 | 291 |
Allows a user to create a local account. |
285 | 292 |
|
... | ... | |
338 | 345 |
if additional_email != user.email: |
339 | 346 |
user.additionalmail_set.create(email=additional_email) |
340 | 347 |
msg = 'Additional email: %s saved for user %s.' % (additional_email, user.email) |
341 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
348 |
logger.log(LOGGING_LEVEL, msg)
|
|
342 | 349 |
if user and user.is_active: |
343 | 350 |
next = request.POST.get('next', '') |
344 | 351 |
return prepare_response(request, user, next=next) |
... | ... | |
359 | 366 |
|
360 | 367 |
@login_required |
361 | 368 |
@signed_terms_required |
362 |
def feedback(request, template_name='im/feedback.html', email_template_name='im/feedback_mail.txt', extra_context={}):
|
|
369 |
def feedback(request, template_name='im/feedback.html', email_template_name='im/feedback_mail.txt', extra_context=None):
|
|
363 | 370 |
""" |
364 | 371 |
Allows a user to send feedback. |
365 | 372 |
|
... | ... | |
399 | 406 |
try: |
400 | 407 |
send_feedback(msg, data, request.user, email_template_name) |
401 | 408 |
except SendMailError, e: |
402 |
status = messages.ERROR |
|
403 | 409 |
messages.error(request, message) |
404 | 410 |
else: |
405 | 411 |
message = _('Feedback successfully sent') |
406 |
messages.succeess(request, message)
|
|
412 |
messages.success(request, message) |
|
407 | 413 |
return render_response(template_name, |
408 | 414 |
feedback_form = form, |
409 | 415 |
context_instance = get_context(request, extra_context)) |
410 | 416 |
|
411 | 417 |
@signed_terms_required |
412 |
def logout(request, template='registration/logged_out.html', extra_context={}):
|
|
418 |
def logout(request, template='registration/logged_out.html', extra_context=None):
|
|
413 | 419 |
""" |
414 | 420 |
Wraps `django.contrib.auth.logout` and delete the cookie. |
415 | 421 |
""" |
... | ... | |
419 | 425 |
auth_logout(request) |
420 | 426 |
response.delete_cookie(COOKIE_NAME, path='/', domain=COOKIE_DOMAIN) |
421 | 427 |
msg = 'Cookie deleted for %s' % email |
422 |
logger._log(LOGGING_LEVEL, msg, [])
|
|
428 |
logger.log(LOGGING_LEVEL, msg)
|
|
423 | 429 |
next = request.GET.get('next') |
424 | 430 |
if next: |
425 | 431 |
response['Location'] = next |
... | ... | |
431 | 437 |
return response |
432 | 438 |
messages.success(request, _('You have successfully logged out.')) |
433 | 439 |
context = get_context(request, extra_context) |
434 |
response.write(render_to_string(template, context_instance=context)) |
|
440 |
response.write(loader.render_to_string(template, context_instance=context))
|
|
435 | 441 |
return response |
436 | 442 |
|
437 | 443 |
@transaction.commit_manually |
... | ... | |
505 | 511 |
transaction.rollback() |
506 | 512 |
return index(request) |
507 | 513 |
|
508 |
def approval_terms(request, term_id=None, template_name='im/approval_terms.html', extra_context={}):
|
|
514 |
def approval_terms(request, term_id=None, template_name='im/approval_terms.html', extra_context=None):
|
|
509 | 515 |
term = None |
510 | 516 |
terms = None |
511 | 517 |
if not term_id: |
... | ... | |
515 | 521 |
pass |
516 | 522 |
else: |
517 | 523 |
try: |
518 |
term = ApprovalTerms.objects.get(id=term_id)
|
|
519 |
except ApprovalTermDoesNotExist, e: |
|
524 |
term = ApprovalTerms.objects.get(id=term_id) |
|
525 |
except ApprovalTerms.DoesNotExist, e:
|
|
520 | 526 |
pass |
521 | 527 |
|
522 | 528 |
if not term: |
... | ... | |
558 | 564 |
email_template_name='registration/email_change_email.txt', |
559 | 565 |
form_template_name='registration/email_change_form.html', |
560 | 566 |
confirm_template_name='registration/email_change_done.html', |
561 |
extra_context={}):
|
|
567 |
extra_context=None):
|
|
562 | 568 |
if activation_key: |
563 | 569 |
try: |
564 | 570 |
user = EmailChange.objects.change_email(activation_key) |
... | ... | |
657 | 663 |
) |
658 | 664 |
except SendNotificationError, e: |
659 | 665 |
messages.error(request, e, fail_silently=True) |
660 |
return redirect(post_save_redirect, new_object)
|
|
666 |
return HttpResponseRedirect(post_save_redirect % new_object.__dict__)
|
|
661 | 667 |
else: |
662 | 668 |
now = datetime.now() |
663 | 669 |
data = { |
b/snf-astakos-app/astakos/im/widgets.py | ||
---|---|---|
36 | 36 |
from django import forms |
37 | 37 |
from django.utils.safestring import mark_safe |
38 | 38 |
from django.utils import simplejson as json |
39 |
from django.utils.translation import ugettext as _ |
|
40 | 39 |
from django.template.loader import render_to_string |
41 | 40 |
|
42 | 41 |
from astakos.im.settings import RECAPTCHA_PUBLIC_KEY, RECAPTCHA_OPTIONS, \ |
Also available in: Unified diff