Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
f806b46e
Commit
f806b46e
authored
Oct 09, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for changing / setting password
parent
39e4be94
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
18 deletions
+126
-18
accounts/forms.py
accounts/forms.py
+58
-0
accounts/urls.py
accounts/urls.py
+0
-12
accounts/views.py
accounts/views.py
+50
-3
weblate/html/accounts/password.html
weblate/html/accounts/password.html
+16
-0
weblate/html/profile.html
weblate/html/profile.html
+2
-3
No files found.
accounts/forms.py
View file @
f806b46e
...
...
@@ -267,3 +267,61 @@ class RegistrationForm(forms.Form):
if self.cleaned_data['
content
'] != '':
raise forms.ValidationError('
Invalid
value
')
return ''
class PasswordForm(forms.Form):
'''
Form for setting password.
'''
password1 = forms.CharField(
widget=forms.PasswordInput(render_value=False),
label=_("New password"),
help_text=_('
At
least
six
characters
long
.
'),
)
password2 = forms.CharField(
widget=forms.PasswordInput(render_value=False),
label=_("New password (again)"),
help_text=_(
'
Repeat
the
password
so
we
can
verify
'
'
you
typed
it
in
correctly
.
'
),
)
def clean_password1(self):
'''
Password validation, requires length of six chars.
'''
if len(self.cleaned_data['
password1
']) < 6:
raise forms.ValidationError(
_(u'
Password
needs
to
have
at
least
six
characters
.
')
)
return self.cleaned_data['
password1
']
def clean(self):
"""
Verify that the values entered into the two password fields
match. Note that an error here will end up in
``non_field_errors()`` because it doesn'
t
apply
to
a
single
field
.
"""
try:
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 != password2:
raise forms.ValidationError(
_('You must type the same password each time.')
)
except KeyError:
pass
return self.cleaned_data
class PasswordChangeForm(forms.Form):
password = forms.CharField(
widget=forms.PasswordInput(render_value=False),
label=_("Current password"),
)
accounts/urls.py
View file @
f806b46e
...
...
@@ -28,18 +28,6 @@ from accounts.views import RegistrationTemplateView
urlpatterns
=
patterns
(
''
,
url
(
r'^password/change/$'
,
auth_views
.
password_change
,
{
'extra_context'
:
{
'title'
:
_
(
'Change password'
)}},
name
=
'auth_password_change'
),
url
(
r'^password/change/done/$'
,
auth_views
.
password_change_done
,
{
'extra_context'
:
{
'title'
:
_
(
'Password changed'
)}},
name
=
'auth_password_change_done'
),
url
(
r'^password/reset/$'
,
auth_views
.
password_reset
,
...
...
accounts/views.py
View file @
f806b46e
...
...
@@ -31,7 +31,7 @@ from django.contrib.auth.views import login, logout
from
django.views.generic
import
TemplateView
from
urllib
import
urlencode
from
accounts.forms
import
RegistrationForm
from
accounts.forms
import
RegistrationForm
,
PasswordForm
,
PasswordChangeForm
from
social.backends.utils
import
load_backends
from
social.apps.django_app.utils
import
BACKENDS
from
social.apps.django_app.views
import
complete
...
...
@@ -282,8 +282,55 @@ def register(request):
)
@
login_required
def
password
(
request
):
'''
Password change / set form.
'''
do_change
=
False
if
request
.
user
.
has_usable_password
():
print
'US'
if
request
.
method
==
'POST'
:
change_form
=
PasswordChangeForm
(
request
.
POST
)
if
change_form
.
is_valid
():
password
=
change_form
.
cleaned_data
[
'password'
]
if
request
.
user
.
check_password
(
password
):
do_change
=
True
else
:
messages
.
error
(
request
,
_
(
'You have entered invalid password.'
)
)
else
:
change_form
=
PasswordChangeForm
()
else
:
print
'UNUS'
do_change
=
True
change_form
=
None
if
request
.
method
==
'POST'
:
form
=
PasswordForm
(
request
.
POST
)
if
form
.
is_valid
()
and
do_change
:
request
.
user
.
set_password
(
form
.
cleaned_data
[
'password1'
]
)
request
.
user
.
save
()
messages
.
info
(
request
,
_
(
'Your password has been changed.'
)
)
return
redirect
(
'profile'
)
else
:
form
=
PasswordForm
()
return
render_to_response
(
'accounts/password.html'
,
RequestContext
(
request
,
{
'title'
:
_
(
'Change password'
),
'change_form'
:
change_form
,
'form'
:
form
,
}
)
)
weblate/html/accounts/password.html
0 → 100644
View file @
f806b46e
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<p>
{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}
</p>
<form
action=
""
method=
"post"
>
{% csrf_token %}
<table>
{{ change_form.as_table }}
{{ form.as_table }}
</table>
<input
type=
"submit"
value=
"{% trans 'Change my password' %}"
class=
"button"
/>
</form>
{% endblock %}
weblate/html/profile.html
View file @
f806b46e
...
...
@@ -46,6 +46,8 @@
</div>
<div
id=
"auth"
>
<p><a
href=
"{% url 'password' %}"
class=
"button"
>
{% if request.user.has_usable_password %}{% trans "Change password" %}{% else %}{% trans "Set password" %}{% endif %}
</a></p>
<p>
{% trans "You can manage third party identities which are associated to this account." %}
</p>
<p>
{% trans "Currently associated:" %}
</p>
<table>
...
...
@@ -63,9 +65,6 @@
<td>
{{ assoc.uid }}
</th>
<td>
<a
href=
"{% url 'social:disconnect_individual' assoc.provider assoc.id %}"
class=
"disconnect button"
>
{% trans "Disconnect" %}
</a>
{% if assoc.provider == 'email' %}
<a
href=
"{% url 'django.contrib.auth.views.password_change' %}"
class=
"button"
>
{% trans "Change password" %}
</a>
{% endif %}
</td>
</tr>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment