Revision 3a72a5d4
b/snf-astakos-app/astakos/im/auth_providers.py | ||
---|---|---|
154 | 154 |
description = _('Allows you to login to your account using your academic ' |
155 | 155 |
'credentials') |
156 | 156 |
add_prompt = _('Add academic credentials to your account.') |
157 |
details_tpl = _('Shibboleth account %(identifier)s is connected with your ' |
|
158 |
' account.') |
|
159 |
user_title = _('Academic credentials (%(identifier)s)') |
|
157 | 160 |
|
158 | 161 |
@property |
159 | 162 |
def add_url(self): |
... | ... | |
169 | 172 |
description = _('Allows you to login to your account using your twitter ' |
170 | 173 |
'account') |
171 | 174 |
add_prompt = _('Connect with your Twitter account.') |
175 |
details_tpl = _('Twitter screen name: %(info_screen_name)s') |
|
176 |
user_title = _('Twitter (%(info_screen_name)s)') |
|
172 | 177 |
|
173 | 178 |
@property |
174 | 179 |
def add_url(self): |
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
34 | 34 |
import hashlib |
35 | 35 |
import uuid |
36 | 36 |
import logging |
37 |
import json |
|
37 | 38 |
|
38 | 39 |
from time import asctime |
39 | 40 |
from datetime import datetime, timedelta |
... | ... | |
623 | 624 |
**kwargs).count()) |
624 | 625 |
|
625 | 626 |
def add_auth_provider(self, provider, **kwargs): |
627 |
info_data = '' |
|
628 |
if 'provider_info' in kwargs: |
|
629 |
info_data = json.dumps(kwargs.pop('provider_info')) |
|
630 |
|
|
626 | 631 |
if self.can_add_auth_provider(provider, **kwargs): |
627 |
self.auth_providers.create(module=provider, active=True, **kwargs) |
|
632 |
self.auth_providers.create(module=provider, active=True, |
|
633 |
info_data=info_data, |
|
634 |
**kwargs) |
|
628 | 635 |
else: |
629 | 636 |
raise Exception('Cannot add provider') |
630 | 637 |
|
... | ... | |
711 | 718 |
active = models.BooleanField(default=True) |
712 | 719 |
auth_backend = models.CharField('Backend', max_length=255, blank=False, |
713 | 720 |
default='astakos') |
721 |
info_data = models.TextField(default="", null=True, blank=True) |
|
714 | 722 |
|
715 | 723 |
objects = AstakosUserAuthProviderManager() |
716 | 724 |
|
717 | 725 |
class Meta: |
718 | 726 |
unique_together = (('identifier', 'module', 'user'), ) |
719 | 727 |
|
728 |
def __init__(self, *args, **kwargs): |
|
729 |
super(AstakosUserAuthProvider, self).__init__(*args, **kwargs) |
|
730 |
try: |
|
731 |
self.info = json.loads(self.info_data) |
|
732 |
except: |
|
733 |
self.info = {} |
|
734 |
for key,value in self.info.iteritems(): |
|
735 |
setattr(self, 'info_%s' % key, value) |
|
736 |
|
|
737 |
|
|
720 | 738 |
@property |
721 | 739 |
def settings(self): |
722 | 740 |
return auth_providers.get_provider(self.module) |
723 | 741 |
|
724 | 742 |
@property |
725 | 743 |
def details_display(self): |
726 |
return self.settings.details_tpl % self.__dict__ |
|
744 |
return self.settings.get_details_tpl_display % self.__dict__ |
|
745 |
|
|
746 |
@property |
|
747 |
def title_display(self): |
|
748 |
title_tpl = self.settings.get_title_display |
|
749 |
try: |
|
750 |
if self.settings.get_user_title_display: |
|
751 |
title_tpl = self.settings.get_user_title_display |
|
752 |
except Exception, e: |
|
753 |
pass |
|
754 |
return title_tpl % self.__dict__ |
|
727 | 755 |
|
728 | 756 |
def can_remove(self): |
729 | 757 |
return self.user.can_remove_auth_provider(self.module) |
... | ... | |
745 | 773 |
return "%s:%s" % (self.module, self.auth_backend) |
746 | 774 |
return self.module |
747 | 775 |
|
776 |
def save(self, *args, **kwargs): |
|
777 |
self.info_data = json.dumps(self.info) |
|
778 |
return super(AstakosUserAuthProvider, self).save(*args, **kwargs) |
|
748 | 779 |
|
749 | 780 |
|
750 | 781 |
class Membership(models.Model): |
b/snf-astakos-app/astakos/im/target/twitter.py | ||
---|---|---|
112 | 112 |
|
113 | 113 |
access_token = dict(cgi.parse_qsl(content)) |
114 | 114 |
userid = access_token['user_id'] |
115 |
username = access_token.get('screen_name', userid) |
|
115 | 116 |
|
116 | 117 |
# an existing user accessed the view |
117 | 118 |
if request.user.is_authenticated(): |
... | ... | |
125 | 126 |
messages.error(request, 'Account already exists.') |
126 | 127 |
return HttpResponseRedirect(reverse('edit_profile')) |
127 | 128 |
|
128 |
user.add_auth_provider('twitter', identifier=userid) |
|
129 |
user.add_auth_provider('twitter', identifier=userid, |
|
130 |
provider_info={'screen_name': username}) |
|
129 | 131 |
return HttpResponseRedirect(reverse('edit_profile')) |
130 | 132 |
|
131 | 133 |
try: |
Also available in: Unified diff