Commits

benoitc  committed 688f1aa

remove useless code. It's better to use django-registration for legacy authentification.

TODO:
- add feature to associate multiples openid to an account.
- add signals
- add commands to cleanup session & nonces
- add decorators and view to ask for openid auth when needed.
- add classic openid auth (without using the django auth)

  • Participants
  • Parent commits c443c6c

Comments (0)

Files changed (12)

File django_authopenid/forms.py

                     account registered with that e-mail address. Please try \
                     another.')
             raise forms.ValidationError(_("This email is already \
-                registered in our database. Please choose another."))
-
-
-attrs_dict = { 'class': 'required' }
-username_re = re.compile(r'^\w+$')
-
-class RegistrationForm(forms.Form):
-    """ legacy registration form """
-
-    next = forms.CharField(max_length=255, widget=forms.HiddenInput(), 
-            required=False)
-    username = forms.CharField(max_length=30,
-            widget=forms.TextInput(attrs=attrs_dict),
-            label=u'Username')
-    email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict,
-            maxlength=200)), label=u'Email address')
-    password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict),
-            label=u'Password')
-    password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict),
-            label=u'Password (again, to catch typos)')
-
-    def clean_username(self):
-        """
-        Validates that the username is alphanumeric and is not already
-        in use.
-        
-        """
-        if 'username' in self.cleaned_data:
-            if not username_re.search(self.cleaned_data['username']):
-                raise forms.ValidationError(u'Usernames can only contain \
-                        letters, numbers and underscores')
-            try:
-                user = User.objects.get(
-                        username__exact = self.cleaned_data['username']
-                )
-
-            except User.DoesNotExist:
-                return self.cleaned_data['username']
-            except User.MultipleObjectsReturned:
-                raise forms.ValidationError(u'Somehow, that username is in \
-                    use for multiple accounts. Please contact us to get this \
-                    problem resolved.')
-            raise forms.ValidationError(u'This username is already taken. \
-                    Please choose another.')
-
-    def clean_email(self):
-        """ validate if email exist in database
-        :return: raise error if it exist """
-        if 'email' in self.cleaned_data:
-            try:
-                user = User.objects.get(email = self.cleaned_data['email'])
-            except User.DoesNotExist:
-                return self.cleaned_data['email']
-            except User.MultipleObjectsReturned:
-                raise forms.ValidationError(u'There is already more than one \
-                    account registered with that e-mail address. Please try \
-                    another.')
-            raise forms.ValidationError(u'This email is already registered \
-                    in our database. Please choose another.')
-        return self.cleaned_data['email']
-    
-    def clean_password2(self):
-        """
-        Validates that the two password inputs match.
-        
-        """
-        if 'password1' in self.cleaned_data and \
-                'password2' in self.cleaned_data and \
-                self.cleaned_data['password1'] == \
-                self.cleaned_data['password2']:
-            return self.cleaned_data['password2']
-        raise forms.ValidationError(u'You must type the same password each \
-                time')
-
-
-class ChangepwForm(forms.Form):
-    """ change password form """
-    oldpw = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict))
-    password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict))
-    password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict))
-
-    def __init__(self, data=None, user=None, *args, **kwargs):
-        if user is None:
-            raise TypeError("Keyword argument 'user' must be supplied")
-        super(ChangepwForm, self).__init__(data, *args, **kwargs)
-        self.user = user
-
-    def clean_oldpw(self):
-        """ test old password """
-        if not self.user.check_password(self.cleaned_data['oldpw']):
-            raise forms.ValidationError(_("Old password is incorrect. \
-                    Please enter the correct password."))
-        return self.cleaned_data['oldpw']
-    
-    def clean_password2(self):
-        """
-        Validates that the two password inputs match.
-        """
-        if 'password1' in self.cleaned_data and \
-                'password2' in self.cleaned_data and \
-           self.cleaned_data['password1'] == self.cleaned_data['password2']:
-            return self.cleaned_data['password2']
-        raise forms.ValidationError(_("new passwords do not match"))
-        
-        
-class ChangeemailForm(forms.Form):
-    """ change email form """
-    email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict, 
-        maxlength=200)), label=u'Email address')
-    password = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict))
-
-    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, \
-            initial=None, user=None):
-        if user is None:
-            raise TypeError("Keyword argument 'user' must be supplied")
-        super(ChangeemailForm, self).__init__(data, files, auto_id, 
-                prefix, initial)
-        self.test_openid = False
-        self.user = user
-        
-        
-    def clean_email(self):
-        """ check if email don't exist """
-        if 'email' in self.cleaned_data:
-            if self.user.email != self.cleaned_data['email']:
-                try:
-                    user = User.objects.get(email = self.cleaned_data['email'])
-                except User.DoesNotExist:
-                    return self.cleaned_data['email']
-                except User.MultipleObjectsReturned:
-                    raise forms.ValidationError(u'There is already more than one \
-                        account registered with that e-mail address. Please try \
-                        another.')
-                raise forms.ValidationError(u'This email is already registered \
-                    in our database. Please choose another.')
-        return self.cleaned_data['email']
-        
-
-    def clean_password(self):
-        """ check if we have to test a legacy account or not """
-        if 'password' in self.cleaned_data:
-            if not self.user.check_password(self.cleaned_data['password']):
-                self.test_openid = True
-        return self.cleaned_data['password']
-                
-class ChangeopenidForm(forms.Form):
-    """ change openid form """
-    openid_url = forms.CharField(max_length=255,
-            widget=forms.TextInput(attrs={'class': "required" }))
-
-    def __init__(self, data=None, user=None, *args, **kwargs):
-        if user is None:
-            raise TypeError("Keyword argument 'user' must be supplied")
-        super(ChangeopenidForm, self).__init__(data, *args, **kwargs)
-        self.user = user
-
-class DeleteForm(forms.Form):
-    """ confirm form to delete an account """
-    confirm = forms.CharField(widget=forms.CheckboxInput(attrs=attrs_dict))
-    password = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict))
-
-    def __init__(self, data=None, files=None, auto_id='id_%s',
-            prefix=None, initial=None, user=None):
-        super(DeleteForm, self).__init__(data, files, auto_id, prefix, initial)
-        self.test_openid = False
-        self.user = user
-
-    def clean_password(self):
-        """ check if we have to test a legacy account or not """
-        if 'password' in self.cleaned_data:
-            if not self.user.check_password(self.cleaned_data['password']):
-                self.test_openid = True
-        return self.cleaned_data['password']
-
-
-class EmailPasswordForm(forms.Form):
-    """ send new password form """
-    username = forms.CharField(max_length=30,
-            widget=forms.TextInput(attrs={'class': "required" }))
-
-    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, 
-            initial=None):
-        super(EmailPasswordForm, self).__init__(data, files, auto_id, 
-                prefix, initial)
-        self.user_cache = None
-
-
-    def clean_username(self):
-        """ get user for this username """
-        if 'username' in self.cleaned_data:
-            try:
-                self.user_cache = User.objects.get(
-                        username = self.cleaned_data['username'])
-            except:
-                raise forms.ValidationError(_("Incorrect username."))
-        return self.cleaned_data['username']
+                registered in our database. Please choose another."))

File django_authopenid/templates/authopenid/changeemail.html

-{% extends "base.html" %}
-{% load i18n %}
-
-
-
-
-{% block content %}
-<h4 class="headblue">{% trans "Account: change email" %}</h4>
-
-<p class="settings-descr">{% blocktrans %}This is where you can change the email address associated with your account. Please keep this email address up to date so we can send you a password-reset email if you request one.{% endblocktrans %}</p>
-{% if form.errors %}
-<p class="errors">{% trans "Please correct errors below:" %}<br />
-	{% if form.email.errors %} 
-		<span class="error">{{ form.email.errors|join:", " }}</span>
-	{% endif %}
-	{% if form.password.errors %} 
-		<span class="error">{{ form.password.errors|join:", " }}</span>
-	{% endif %}
-</p>
-{% endif %}
-
-{% if msg %}
-<p class="errors">{{ msg }}</p>
-{% endif %}
-
-<div class="aligned">
-	<form action="." method="post" accept-charset="utf-8">
-
-		<div id="form-row"><label for="id_email">{% trans "Email" %}</label>{{ form.email }}</div>
-		<div id="form-row"><label for="id_password">{% trans "Password" %}</label>{{ form.password }}</div>
-
-        <p><input type="submit" value="{% trans "Change email" %}"></p>
-
-	</form>
-	</div>
-{% endblock %}

File django_authopenid/templates/authopenid/changeopenid.html

-{% extends "base.html" %}
-{% load i18n %}
-
-{% block content %}
-<h4 class="headblue">{% trans "Account: change OpenID URL" %}</h4>
-
-<p>{% blocktrans %}This is where you can change your OpenID URL. Make sure you remember it!{% endblocktrans %}</p>
-{% if form.errors %}
-<p class="errors">{% trans "Please correct errors below:" %}<br />
-	{% if form.openid_url.errors %} 
-		<span class="error">{{ form.openid_url.errors|join:", " }}</span>
-	{% endif %}
-
-
-</p>
-{% endif %}
-{% if msg %}
-	<p class="errors">{{ msg }}</p>
-{% endif %}
-
-<div class="aligned">
-	<form action="." method="post" accept-charset="utf-8">
-
-		<div id="form-row"><label for="id_openid_url">{% trans "OpenID URL:" %}</label>{{ form.openid_url }}</div>
-        <p><input type="submit" value="{% trans "Change OpenID" %}"></p>
-
-	</form>
-	</div>
-{% endblock %}

File django_authopenid/templates/authopenid/changepw.html

-{% extends "base.html" %}
-{% load i18n %}
-
-{% block head %}
-		
-{% endblock %}
-
-
-
-{% block content %}
-<h4 class="headblue">{% trans "Account: change password" %}</h4>
-
-<p>{% blocktrans %}This is where you can change your password. Make sure you remember it!{% endblocktrans %}</p>
-{% if form.errors %}
-<p class="errors">{% trans "Please correct errors below:" %}<br />
-{{ form.errors }}
-</p>
-{% endif %}
-
-<div class="aligned">
-	<form action="." method="post" accept-charset="utf-8">
-
-		<div id="form-row"><label for="id_oldpw">{% trans "Current password" %}</label>{{ form.oldpw }}</div>
-		<div id="form-row"><label for="id_password1">{% trans "New password" %}</label>{{ form.password1 }}</div>
-		<div id="form-row"><label for="id_password2">{% trans "New password again" %}</label>{{ form.password2 }}</div>
-        <p><input type="submit" value="{% trans "Change password" %}"></p>
-
-	</form>
-	</div>
-{% endblock %}

File django_authopenid/templates/authopenid/confirm_email.txt

-Thank you for registering. 
-
-Your account details are:
-
-Username: {{ username }}
-Password: {{ password }}
-
-
-You may sign in here:
-{{ site_url }}signin/
-
-

File django_authopenid/templates/authopenid/delete.html

-{% extends "base.html" %}
-{% load i18n %}
-
-
-{% block content %}
-<h4 class="headblue">{% trans "Account: delete account" %}</h4>
-
-<p class="settings-descr">{% blocktrans %}Note: After deleting your account, anyone will be able to register this username.{% endblocktrans %}</p>
-{% if form.errors %}
-<p class="errors">{% trans "Please correct errors below:" %}<br />
-	{% if form.confirm.errors %} 
-    <span class="error">{% trans "Check confirm box, if you want delete your account." %}</span><br />
-	{% endif %}
-	{% if form.password.errors %} 
-    <span class="error">{% trans "Password:" %} {{ form.password.errors|join:", " }}</span>
-	{% endif %}
-</p>
-{% endif %}
-{% if msg %}
-<p class="errors">{% trans "Please correct errors below:" %}<br />
-    <span class="error">{{ msg }}</span>
-    </p>
-{% endif %}
-<div class="aligned">
-	<form action="." method="post" accept-charset="utf-8">
-
-        <div id="form-row"> {{ form.confirm }} {% trans "I am sure I want to delete my account." %}</div>
-        <div id="form-row"><label for="id_password">{% trans "Password/OpenID URL" %}</label>{{ form.password }} {% trans "(required for your security)" %}</div>
-
-        <p><input type="submit" value="{% trans "Delete account permanently" %}"></p>
-
-	</form>
-	</div>
-{% endblock %}

File django_authopenid/templates/authopenid/sendpw.html

-
-{% extends "base.html" %}
-{% load i18n %}
-
-
-{% block content %}
-<h4 class="headblue">{% trans "Account: Send a new password" %}</h4>
-
-<p class="settings-descr">{% blocktrans %}Lost your password ? Here you can ask to reset your password. Enter the username you use  and you will get a confirmation email with your new password. This new password will be activated only after you have clicked on the link in the email.{% endblocktrans %}</p>
-{% if form.errors %}
-<p class="errors">{% trans "Please correct errors below:" %}<br />
-	{% if form.username.errors %} 
-		<span class="error">{{ form.username.errors|join:", " }}</span>
-	{% endif %}
-</p>
-{% endif %}
-{% if msg %}
-<br /
-<span class="error">{{ msg }}</span>
-{% endif %}
-
-<div class="aligned">
-	<form action="." method="post" accept-charset="utf-8">
-		<div id="form-row"><label for="id_username">{% trans "Username" %}</label>{{ form.username }}</div>
-
-        <p><input type="submit" value="{% trans "Send new password" %}"></p>
-
-	</form>
-	</div>
-{% endblock %}

File django_authopenid/templates/authopenid/sendpw_email.txt

-Someone has requested to reset your password on {{ site_url }}.
-If this is not you, it is safe to ignore this email.
-
-Your new account details are:
-
-Username: {{ username }}
-New password: {{ password }}
-
-To confirm reset of your password go to this address:
-{{ site_url }}{{ url_confirm }}?key={{ confirm_key }}
-
-Regards,
-
-

File django_authopenid/templates/authopenid/settings.html

-{% extends "base.html" %}
-{% load i18n %}
-
-{% block head %}
-<style type="text/css" media="screen">
-	dt, dd { padding:0 0 0.35em 0; }
-	dt { float: left; width: 21ex;  }
-	dd { margin-left: 23ex;  }
-	
-	#settings-options, #settings-intro { padding: 4em 1.5em;}
-	#settings-options { min-height: 300px; border-left: 1px solid #333;}
-	
-	#settings-options h5 { font-weight: bold;}
-</style>
-{% endblock %}
-
-{% block content %}
-<div id="settings-intro">
-	
-
-
-    <h4><strong>{{ user.username }}</strong> {% trans "Settings" %}</h4>
-    {% blocktrans %}
-    <p>This is where you can make changes to your account.</p>
-
-    {% endblocktrans %}
-</div>
-
-<div id="settings-options">
-	{% if msg %}
-		<p class="error">{{ msg }}</p>
-	{% endif %}
-    <h5>{% trans "Account" %}</h5>
-	<dl>
-        <dt>» <a href="{% url user_changepw %}">{% trans "change password" %}</a></dt>
-        <dd>{% trans "Give your  account a new password." %}</dd>
-        <dt>» <a href="{% url user_changeemail %}">{% trans "change email" %}</a></dt>
-        <dd>{% trans "Add or update the email address associated with your account." %}</dd>
-        {% if is_openid %}
-        <dt>» <a href="{% url user_changeopenid %}">{% trans "change openid url" %}</a></dt>
-        <dd>{% trans "Change openid associated to your account" %}</dd>
-        {% endif %}
-        
-        <dt>» <a href="{% url user_delete %}">{% trans "delete account" %}</a></dt>
-        <dd>{% trans "Erase your username and all your data from website" %}</dd>
-	</dl>
-</div>
-{% endblock %}

File django_authopenid/templates/authopenid/signup.html

-{% extends "base.html" %}
-{% load i18n %}
-
-{% block content %}
-
-<div class="jointxt">
-    {% blocktrans %}
-    <h1>Join</h1>
-    <p>There are two ways to join: with an email + username, or with OpenID.<br />Enter information only for the type of sign up you want to do.</p>
-    {% endblocktrans %}
-	<br />
-	<br />
-    <h2 class="signup">{% trans "Regular Signup" %}</h2>
-    {% if form.errors %}
-    <p class="errors">{% trans "Please correct errors below:" %}<br />
-    {% if form.username.errors %} 
-    <span class="error">{{ form.username.errors|join:", " }}</span>
-    {% endif %}
-    {% if form.email.errors %} 
-    <span class="error">{{ form.email.errors|join:", " }}</span>
-    {% endif %}
-    {% if form.password2.errors %} 
-    <span class="error">{{ form.password2.errors|join:", " }}</span>
-    {% endif %}
-    </p>
-    {% endif %}
-</div>
-    <form action="{% url user_signup %}" method="post" accept-charset="utf-8">	
-        <div class="form-row"><label for="id_username">{% trans "Choose a Username:" %}</label><br />{{ form.username }}</div>
-
-        <div class="form-row"><label for="id_email">{% trans "Enter Your Email Address:" %}</label><br />{{ form.email }}</div>
-        <div class="form-row"><label for="id_password1">{% trans "Choose a Password:" %}</label><br />{{ form.password1 }}</div>
-        <div class="form-row"><label for="id_password2">{% trans "Confirm Your Password:" %}</label><br />{{ form.password2 }}</div>
-
-        <div class="submit-row"><input type="submit" value="{% trans "Sign up" %}" /></div>
-        <br />
-    </form>
-<br />
-    <h2 class="signup">{% trans "OpenID Signup" %}</h2>
-    <form name="fopenid" action="{% url user_signin %}" method="post">
-        <div class="form-row">{{ form2.openid_url }}</div>
-        <div class="submit-row "><input name="bsignin" type="submit" value="{% trans "Sign in with OpenID" %}"></div>
-    </form>
-{% endblock %}

File django_authopenid/urls.py

     url(r'^%s%s$' % (_('signin/'), _('complete/')), 'complete_signin', 
         name='user_complete_signin'),
     url(r'^%s$' % _('register/'), 'register', name='user_register'),
-    url(r'^%s$' % _('signup/'), 'signup', name='user_signup'),
-    url(r'^%s$' % _('sendpw/'), 'sendpw', name='user_sendpw'),
-    url(r'^%s%s$' % (_('password/'), _('confirm/')), 'confirmchangepw', 
-        name='user_confirmchangepw'),
-
-    # manage account settings
-    url(r'^$', 'account_settings', name='user_account_settings'),
-    url(r'^%s$' % _('password/'), 'changepw', name='user_changepw'),
-    url(r'^%s$' % _('email/'), 'changeemail', name='user_changeemail'),
-    url(r'^%s$' % _('openid/'), 'changeopenid', name='user_changeopenid'),
-    url(r'^%s$' % _('delete/'), 'delete', name='user_delete'),
 )

File django_authopenid/views.py

         redirect_field_name: request.REQUEST.get(redirect_field_name, '')
     }, context_instance=RequestContext(request))
 
-@not_authenticated
-def signup(request, template_name='authopenid/signup.html'):
-    """
-    signup page. Create a legacy account
-
-    url : /signup/"
-
-    templates: authopenid/signup.html, authopenid/confirm_email.txt
-    """
-    action_signin = reverse('user_signin')
-    next = clean_next(request.GET.get('next'))
-    form = RegistrationForm(initial={'next':next})
-    form_signin = OpenidSigninForm(initial={'next':next})
-    
-    if request.POST:
-        form = RegistrationForm(request.POST)
-        if form.is_valid():
-            next = clean_next(form.cleaned_data.get('next'))
-            user_ = User.objects.create_user( form.cleaned_data['username'],
-                    form.cleaned_data['email'], form.cleaned_data['password1'])
-           
-            user_.backend = "django.contrib.auth.backends.ModelBackend"
-            login(request, user_)
-            
-            # send email
-            current_domain = Site.objects.get_current().domain
-            subject = _("Welcome")
-            message_template = loader.get_template(
-                    'authopenid/confirm_email.txt'
-            )
-            message_context = Context({ 
-                'site_url': 'http://%s/' % current_domain,
-                'username': form.cleaned_data['username'],
-                'password': form.cleaned_data['password1'] 
-            })
-            message = message_template.render(message_context)
-            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, 
-                    [user_.email])
-            
-            return HttpResponseRedirect(next)
-    
-    return render(template_name, {
-        'form': form,
-        'form2': form_signin,
-        }, context_instance=RequestContext(request))
 
 @login_required
 def signout(request):
     ]
     return render(template_name, { 
         'return_to': return_to 
-        }, context_instance=RequestContext(request))
-
-@login_required
-def account_settings(request, template_name='authopenid/settings.html'):
-    """
-    index pages to changes some basic account settings :
-     - change password
-     - change email
-     - associate a new openid
-     - delete account
-
-    url : /
-
-    template : authopenid/settings.html
-    """
-    msg = request.GET.get('msg', '')
-    is_openid = True
-
-    try:
-        uassoc = UserAssociation.objects.get(
-                user__username__exact=request.user.username
-        )
-    except:
-        is_openid = False
-
-
-    return render(template_name, {
-        'msg': msg,
-        'is_openid': is_openid
-        }, context_instance=RequestContext(request))
-
-@login_required
-def changepw(request, template_name='authopenid/changepw.html'):
-    """
-    change password view.
-
-    url : /changepw/
-    template: authopenid/changepw.html
-    """
-    
-    user_ = request.user
-    
-    if request.POST:
-        form = ChangepwForm(request.POST, user=user_)
-        if form.is_valid():
-            user_.set_password(form.cleaned_data['password1'])
-            user_.save()
-            msg = _("Password changed.") 
-            redirect = "%s?msg=%s" % (
-                    reverse('user_account_settings'),
-                    urlquote_plus(msg))
-            return HttpResponseRedirect(redirect)
-    else:
-        form = ChangepwForm(user=user_)
-
-    return render(template_name, {'form': form },
-                                context_instance=RequestContext(request))
-
-@login_required
-def changeemail(request, template_name='authopenid/changeemail.html'):
-    """ 
-    changeemail view. It require password or openid to allow change.
-
-    url: /changeemail/
-
-    template : authopenid/changeemail.html
-    """
-    msg = request.GET.get('msg', '')
-    extension_args = {}
-    user_ = request.user
-    
-    redirect_to = get_url_host(request) + reverse('user_changeemail')
-
-    if request.POST:
-        form = ChangeemailForm(request.POST, user=user_)
-        if form.is_valid():
-            if not form.test_openid:
-                user_.email = form.cleaned_data['email']
-                user_.save()
-                msg = _("Email changed.") 
-                redirect = "%s?msg=%s" % (reverse('user_account_settings'),
-                        urlquote_plus(msg))
-                return HttpResponseRedirect(redirect)
-            else:
-                request.session['new_email'] = form.cleaned_data['email']
-                return ask_openid(request, form.cleaned_data['password'], 
-                        redirect_to, on_failure=emailopenid_failure)    
-    elif not request.POST and 'openid.mode' in request.GET:
-        return complete(request, emailopenid_success, 
-                emailopenid_failure, redirect_to) 
-    else:
-        form = ChangeemailForm(initial={'email': user_.email},
-                user=user_)
-    
-    return render(template_name, {
-        'form': form,
-        'msg': msg 
-        }, context_instance=RequestContext(request))
-
-
-def emailopenid_success(request, identity_url, openid_response):
-    openid_ = from_openid_response(openid_response)
-
-    user_ = request.user
-    try:
-        uassoc = UserAssociation.objects.get(
-                openid_url__exact=identity_url
-        )
-    except:
-        return emailopenid_failure(request, 
-                _("No OpenID %s found associated in our database" % identity_url))
-
-    if uassoc.user.username != request.user.username:
-        return emailopenid_failure(request, 
-                _("The OpenID %s isn't associated to current user logged in" % 
-                    identity_url))
-    
-    new_email = request.session.get('new_email', '')
-    if new_email:
-        user_.email = new_email
-        user_.save()
-        del request.session['new_email']
-    msg = _("Email Changed.")
-
-    redirect = "%s?msg=%s" % (reverse('user_account_settings'),
-            urlquote_plus(msg))
-    return HttpResponseRedirect(redirect)
-    
-
-def emailopenid_failure(request, message):
-    redirect_to = "%s?msg=%s" % (
-            reverse('user_changeemail'), urlquote_plus(message))
-    return HttpResponseRedirect(redirect_to)
- 
-@login_required
-def changeopenid(request, template_name='authopenid/changeopenid.html'):
-    """
-    change openid view. Allow user to change openid 
-    associated to its username.
-
-    url : /changeopenid/
-
-    template: authopenid/changeopenid.html
-    """
-
-    extension_args = {}
-    openid_url = ''
-    has_openid = True
-    msg = request.GET.get('msg', '')
-        
-    user_ = request.user
-
-    try:
-        uopenid = UserAssociation.objects.get(user=user_)
-        openid_url = uopenid.openid_url
-    except:
-        has_openid = False
-    
-    redirect_to = get_url_host(request) + reverse('user_changeopenid')
-    if request.POST and has_openid:
-        form = ChangeopenidForm(request.POST, user=user_)
-        if form.is_valid():
-            return ask_openid(request, form.cleaned_data['openid_url'],
-                    redirect_to, on_failure=changeopenid_failure)
-    elif not request.POST and has_openid:
-        if 'openid.mode' in request.GET:
-            return complete(request, changeopenid_success,
-                    changeopenid_failure, redirect_to)    
-
-    form = ChangeopenidForm(initial={'openid_url': openid_url }, user=user_)
-    return render(template_name, {
-        'form': form,
-        'has_openid': has_openid, 
-        'msg': msg 
-        }, context_instance=RequestContext(request))
-
-def changeopenid_success(request, identity_url, openid_response):
-    openid_ = from_openid_response(openid_response)
-    is_exist = True
-    try:
-        uassoc = UserAssociation.objects.get(openid_url__exact=identity_url)
-    except:
-        is_exist = False
-        
-    if not is_exist:
-        try:
-            uassoc = UserAssociation.objects.get(
-                    user__username__exact=request.user.username
-            )
-            uassoc.openid_url = identity_url
-            uassoc.save()
-        except:
-            uassoc = UserAssociation(user=request.user, 
-                    openid_url=identity_url)
-            uassoc.save()
-    elif uassoc.user.username != request.user.username:
-        return changeopenid_failure(request, 
-                _('This OpenID is already associated with another account.'))
-
-    request.session['openids'] = []
-    request.session['openids'].append(openid_)
-
-    msg = _("OpenID %s is now associated with your account." % identity_url) 
-    redirect = "%s?msg=%s" % (
-            reverse('user_account_settings'), 
-            urlquote_plus(msg))
-    return HttpResponseRedirect(redirect)
-    
-
-def changeopenid_failure(request, message):
-    redirect_to = "%s?msg=%s" % (
-            reverse('user_changeopenid'), 
-            urlquote_plus(message))
-    return HttpResponseRedirect(redirect_to)
-  
-@login_required
-def delete(request, template_name='authopenid/delete.html'):
-    """
-    delete view. Allow user to delete its account. Password/openid are required to 
-    confirm it. He should also check the confirm checkbox.
-
-    url : /delete
-
-    template : authopenid/delete.html
-    """
-
-    extension_args = {}
-    
-    user_ = request.user
-
-    redirect_to = get_url_host(request) + reverse('user_delete') 
-    if request.POST:
-        form = DeleteForm(request.POST, user=user_)
-        if form.is_valid():
-            if not form.test_openid:
-                user_.delete() 
-                return signout(request)
-            else:
-                return ask_openid(request, form.cleaned_data['password'],
-                        redirect_to, on_failure=deleteopenid_failure)
-    elif not request.POST and 'openid.mode' in request.GET:
-        return complete(request, deleteopenid_success, deleteopenid_failure,
-                redirect_to) 
-    
-    form = DeleteForm(user=user_)
-
-    msg = request.GET.get('msg','')
-    return render(template_name, {
-        'form': form, 
-        'msg': msg, 
-        }, context_instance=RequestContext(request))
-
-def deleteopenid_success(request, identity_url, openid_response):
-    openid_ = from_openid_response(openid_response)
-
-    user_ = request.user
-    try:
-        uassoc = UserAssociation.objects.get(
-                openid_url__exact=identity_url
-        )
-    except:
-        return deleteopenid_failure(request,
-                _("No OpenID %s found associated in our database" % identity_url))
-
-    if uassoc.user.username == user_.username:
-        user_.delete()
-        return signout(request)
-    else:
-        return deleteopenid_failure(request,
-                _("The OpenID %s isn't associated to current user logged in" % 
-                    identity_url))
-    
-    msg = _("Account deleted.") 
-    redirect = "/?msg=%s" % (urlquote_plus(msg))
-    return HttpResponseRedirect(redirect)
-    
-
-def deleteopenid_failure(request, message):
-    redirect_to = "%s?msg=%s" % (reverse('user_delete'), urlquote_plus(message))
-    return HttpResponseRedirect(redirect_to)
-
-
-def sendpw(request, template_name='authopenid/sendpw.html'):
-    """
-    send a new password to the user. It return a mail with 
-    a new pasword and a confirm link in. To activate the 
-    new password, the user should click on confirm link.
-
-    url : /sendpw/
-
-    templates :  authopenid/sendpw_email.txt, authopenid/sendpw.html
-    """
-
-    msg = request.GET.get('msg','')
-    if request.POST:
-        form = EmailPasswordForm(request.POST)
-        if form.is_valid():
-            new_pw = User.objects.make_random_password()
-            confirm_key = UserPasswordQueue.objects.get_new_confirm_key()
-            try:
-                uqueue = UserPasswordQueue.objects.get(
-                        user=form.user_cache
-                )
-            except:
-                uqueue = UserPasswordQueue(
-                        user=form.user_cache
-                )
-            uqueue.new_password = new_pw
-            uqueue.confirm_key = confirm_key
-            uqueue.save()
-            # send email 
-            current_domain = Site.objects.get_current().domain
-            subject = _("Request for new password")
-            message_template = loader.get_template(
-                    'authopenid/sendpw_email.txt')
-            message_context = Context({ 
-                'site_url': 'http://%s' % current_domain,
-                'confirm_key': confirm_key,
-                'username': form.user_cache.username,
-                'password': new_pw,
-                'url_confirm': reverse('user_confirmchangepw'),
-            })
-            message = message_template.render(message_context)
-            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, 
-                    [form.user_cache.email])
-            msg = _("A new password has been sent to your email address.")
-    else:
-        form = EmailPasswordForm()
-        
-    return render(template_name, {
-        'form': form,
-        'msg': msg 
-        }, context_instance=RequestContext(request))
-
-
-def confirmchangepw(request):
-    """
-    view to set new password when the user click on confirm link
-    in its mail. Basically it check if the confirm key exist, then
-    replace old password with new password and remove confirm
-    ley from the queue. Then it redirect the user to signin
-    page.
-
-    url : /sendpw/confirm/?key
-
-    """
-    confirm_key = request.GET.get('key', '')
-    if not confirm_key:
-        return HttpResponseRedirect('/')
-
-    try:
-        uqueue = UserPasswordQueue.objects.get(
-                confirm_key__exact=confirm_key
-        )
-    except:
-        msg = _("Could not change password. Confirmation key '%s'\
-                is not registered." % confirm_key) 
-        redirect = "%s?msg=%s" % (
-                reverse('user_sendpw'), urlquote_plus(msg))
-        return HttpResponseRedirect(redirect)
-
-    try:
-        user_ = User.objects.get(id=uqueue.user.id)
-    except:
-        msg = _("Can not change password. User don't exist anymore \
-                in our database.") 
-        redirect = "%s?msg=%s" % (reverse('user_sendpw'), 
-                urlquote_plus(msg))
-        return HttpResponseRedirect(redirect)
-
-    user_.set_password(uqueue.new_password)
-    user_.save()
-    uqueue.delete()
-    msg = _("Password changed for %s. You may now sign in." % 
-            user_.username) 
-    redirect = "%s?msg=%s" % (reverse('user_signin'), 
-                                        urlquote_plus(msg))
-
-    return HttpResponseRedirect(redirect)
+        }, context_instance=RequestContext(request))