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
01aa1e40
Commit
01aa1e40
authored
Oct 10, 2013
by
Weblate
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
70d58a17
fc92470a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
18 deletions
+31
-18
accounts/auth.py
accounts/auth.py
+15
-7
accounts/forms.py
accounts/forms.py
+10
-0
accounts/views.py
accounts/views.py
+3
-1
docs/admin/auth.rst
docs/admin/auth.rst
+1
-1
weblate/html/accounts/login.html
weblate/html/accounts/login.html
+1
-8
weblate/settings_example.py
weblate/settings_example.py
+1
-1
No files found.
accounts/auth.py
View file @
01aa1e40
...
...
@@ -27,10 +27,10 @@ from django.dispatch.dispatcher import receiver
from
django.contrib.auth.backends
import
ModelBackend
class
Anonymous
UserBackend
(
ModelBackend
):
class
Weblate
UserBackend
(
ModelBackend
):
'''
Authentication backend which allows to control anonymous user
permissions.
permissions
and to login using email
.
'''
def
get_all_permissions
(
self
,
user_obj
,
obj
=
None
):
...
...
@@ -44,19 +44,27 @@ class AnonymousUserBackend(ModelBackend):
anon_user
=
User
.
objects
.
get
(
username
=
ANONYMOUS_USER_NAME
)
user_obj
.
_perm_cache
=
self
.
get_all_permissions
(
anon_user
)
return
user_obj
.
_perm_cache
return
super
(
Anonymous
UserBackend
,
self
).
get_all_permissions
(
return
super
(
Weblate
UserBackend
,
self
).
get_all_permissions
(
user_obj
,
obj
)
def
authenticate
(
self
,
username
=
None
,
password
=
None
,
**
kwargs
):
'''
Prohibits login for anonymous user.
Prohibits login for anonymous user
and allows to login by email
.
'''
if
username
==
ANONYMOUS_USER_NAME
:
return
False
return
super
(
AnonymousUserBackend
,
self
).
authenticate
(
username
,
password
,
**
kwargs
)
if
'@'
in
username
:
kwargs
=
{
'email'
:
username
}
else
:
kwargs
=
{
'username'
:
username
}
try
:
user
=
User
.
objects
.
get
(
**
kwargs
)
if
user
.
check_password
(
password
):
return
user
except
User
.
DoesNotExist
:
return
None
def
has_perm
(
self
,
user_obj
,
perm
,
obj
=
None
):
'''
...
...
accounts/forms.py
View file @
01aa1e40
...
...
@@ -20,6 +20,7 @@
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
,
get_language
from
django.contrib.auth.forms
import
AuthenticationForm
from
accounts.models
import
Profile
,
VerifiedEmail
from
lang.models
import
Language
...
...
@@ -387,3 +388,12 @@ class ResetForm(EmailForm):
_('User with this email address was not found.')
)
return users[0]
class LoginForm(AuthenticationForm):
def __init__(self, *args, **kwargs):
super(LoginForm, self).__init__(*args, **kwargs)
self.fields['username'].label = _('Username or email')
self.fields['password'].label = _('Password')
accounts/views.py
View file @
01aa1e40
...
...
@@ -32,7 +32,8 @@ from django.views.generic import TemplateView
from
urllib
import
urlencode
from
accounts.forms
import
(
RegistrationForm
,
PasswordForm
,
PasswordChangeForm
,
EmailForm
,
ResetForm
RegistrationForm
,
PasswordForm
,
PasswordChangeForm
,
EmailForm
,
ResetForm
,
LoginForm
)
from
social.backends.utils
import
load_backends
from
social.apps.django_app.utils
import
BACKENDS
...
...
@@ -257,6 +258,7 @@ def weblate_login(request):
return
login
(
request
,
template_name
=
'accounts/login.html'
,
authentication_form
=
LoginForm
,
extra_context
=
{
'login_backends'
:
[
x
for
x
in
load_backends
(
BACKENDS
).
keys
()
if
x
!=
'email'
...
...
docs/admin/auth.rst
View file @
01aa1e40
...
...
@@ -54,7 +54,7 @@ For example, enabling authentication against GitHub:
AUTHENTICATION_BACKENDS = (
'social.backends.github.GithubOAuth2',
'social.backends.email.EmailAuth',
'accounts.auth.
Anonymous
UserBackend',
'accounts.auth.
Weblate
UserBackend',
)
# Social auth backends setup
...
...
weblate/html/accounts/login.html
View file @
01aa1e40
...
...
@@ -19,14 +19,7 @@
<form
method=
"post"
action=
"{% url 'login' %}"
>
{% csrf_token %}
<table>
<tr>
<td>
{{ form.username.label_tag }}
</td>
<td>
{{ form.username }}
</td>
</tr>
<tr>
<td>
{{ form.password.label_tag }}
</td>
<td>
{{ form.password }}
</td>
</tr>
{{ form.as_table }}
</table>
<input
type=
"submit"
value=
"{% trans "
Login
"
%}"
class=
"button"
/>
...
...
weblate/settings_example.py
View file @
01aa1e40
...
...
@@ -171,7 +171,7 @@ AUTHENTICATION_BACKENDS = (
'social.backends.email.EmailAuth'
,
#'social.backends.github.GithubOAuth2',
#'social.backends.suse.OpenSUSEOpenId',
'accounts.auth.
Anonymous
UserBackend'
,
'accounts.auth.
Weblate
UserBackend'
,
)
# Social auth backends setup
...
...
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