Add basic functionality for self-registration.
[cas.git] / src / cas / social.py
1 from django.core.exceptions import ValidationError
2 from django.utils.translation import ugettext as _
3 from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
4
5
6 class LooseSocialAccountAdapter(DefaultSocialAccountAdapter):
7     def validate_disconnect(self, account, accounts):
8         """
9         Validate whether or not the socialaccount account can be
10         safely disconnected.
11         """
12         if len(accounts) == 1:
13             # No usable password would render the local account unusable
14             if not account.user.has_usable_password():
15                 raise ValidationError(_("Your account has no password set up."))
16             # No email address, no password reset
17             if not account.user.email:
18                 raise ValidationError(_("Your account has no e-mail address."))