def do_c(self, request, token=''): if not token: # TODO: show a form where they can paste in their token? raise Http404 token = token.rstrip('/').encode('utf8') try: value = signed.unsign( token, key=(self.confirm_link_secret or settings.SECRET_KEY) + self.confirm_link_salt) except signed.BadSignature: return self.show_message(request, self.invalid_token_message, self.invalid_token_message + ': ' + token) # Only line change compared with django-openid user_id = value user = self.lookup_user_by_id(user_id) if not user: # Maybe the user was deleted? return self.show_error(request, self.r_user_not_found_message) # Check user is NOT active but IS in the correct group if self.user_is_unconfirmed(user): # Confirm them try: user = User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=user.username, include_docs=True).first() except ResourceNotFound: user = None if user: self.mark_user_confirmed(user) self.log_in_user(request, user) return self.on_registration_complete(request) else: return self.show_error(request, self.c_already_confirmed_message)
def do_c(self, request, token = ''): if not token: # TODO: show a form where they can paste in their token? raise Http404 token = token.rstrip('/').encode('utf8') try: value = signed.unsign(token, key = ( self.confirm_link_secret or settings.SECRET_KEY ) + self.confirm_link_salt) except signed.BadSignature: return self.show_message( request, self.invalid_token_message, self.invalid_token_message + ': ' + token ) # Only line change compared with django-openid user_id = value user = self.lookup_user_by_id(user_id) if not user: # Maybe the user was deleted? return self.show_error(request, self.r_user_not_found_message) # Check user is NOT active but IS in the correct group if self.user_is_unconfirmed(user): # Confirm them try: user = User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=user.username, include_docs=True).first() except ResourceNotFound: user = None if user: self.mark_user_confirmed(user) self.log_in_user(request, user) return self.on_registration_complete(request) else: return self.show_error(request, self.c_already_confirmed_message)
def lookup_openid(self, request, identity_url): openid = UserOpenidAssociation.view('%s/openid_view' % UserOpenidAssociation._meta.app_label, key=identity_url, include_docs=True).first() if openid: return User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=openid['user_id'], include_docs=True).all()
def clean_email(self): email = self.cleaned_data.get('email', '') try: email_count = User.view('%s/users_by_email' % User._meta.app_label, key = email).count() except ResourceNotFound: email_count = 0 if self.no_duplicate_emails and email_count > 0: raise forms.ValidationError, self.duplicate_email_error return email
def lookup_openid(self, request, identity_url): openid = UserOpenidAssociation.view( '%s/openid_view' % UserOpenidAssociation._meta.app_label, key=identity_url, include_docs=True).first() if openid: return User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=openid['user_id'], include_docs=True).all()
def user_is_unconfirmed(self, user): count = 0 try: count = User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=user.username, include_docs=True).count() except ResourceNotFound: return False if count: return True return False
def suggest_nickname(self, nickname): "Return a suggested nickname that has not yet been taken" if not nickname: return '' original_nickname = nickname suffix = None username_exists = True while username_exists: try: username_exists = User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=nickname, include_docs=True).count() except ResourceNotFound: username_exists = False if not username_exists: break if suffix is None: suffix = 1 else: suffix += 1 nickname = original_nickname + str(suffix) return nickname
def lookup_user_by_username(self, username): return User.view('%s/users_by_username' % User._meta.app_label, reduce=False, key=username, include_docs=True).first()
def lookup_users_by_email(self, email): return User.view('%s/users_by_email' % User._meta.app_label, key=email, include_docs=True).first()