switch from first_name and last_name to name
This commit is contained in:
parent
2db1738e4a
commit
5b771da972
|
@ -105,10 +105,9 @@ data:
|
|||
email: mail # or userPrincipalName
|
||||
user_attribute_map:
|
||||
active_directory:
|
||||
sAMAccountName: username
|
||||
mail: email
|
||||
given_name: first_name
|
||||
name: last_name
|
||||
username: "%(sAMAccountName)s"
|
||||
email: "%(mail)s"
|
||||
name: "%(displayName)"
|
||||
# # Create new users in LDAP upon sign-up
|
||||
# create_users: true
|
||||
# # Reset LDAP password when user reset their password
|
||||
|
|
|
@ -11,7 +11,7 @@ class UserSerializer(ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['is_superuser', 'username', 'first_name', 'last_name', 'email', 'date_joined',
|
||||
fields = ['is_superuser', 'username', 'name', 'email', 'date_joined',
|
||||
'uuid']
|
||||
|
||||
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>{% trans 'Username' %}</th>
|
||||
<th>{% trans 'First Name' %}</th>
|
||||
<th>{% trans 'Last Name' %}</th>
|
||||
<th>{% trans 'Name' %}</th>
|
||||
<th>{% trans 'Active' %}</th>
|
||||
<th>{% trans 'Last Login' %}</th>
|
||||
<th></th>
|
||||
|
@ -22,8 +21,7 @@
|
|||
{% for user in object_list %}
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>{{ user.first_name|default:'-' }}</td>
|
||||
<td>{{ user.last_name|default:'-' }}</td>
|
||||
<td>{{ user.name|default:'-' }}</td>
|
||||
<td>{{ user.is_active }}</td>
|
||||
<td>{{ user.last_login }}</td>
|
||||
<td>
|
||||
|
|
|
@ -14,8 +14,8 @@ class OpenIDUserInfoView(ScopedResourceMixin, View):
|
|||
payload = {
|
||||
'sub': request.user.uuid.int,
|
||||
'name': request.user.get_full_name(),
|
||||
'given_name': request.user.first_name,
|
||||
'family_name': request.user.last_name,
|
||||
'given_name': request.user.name,
|
||||
'family_name': '',
|
||||
'preferred_username': request.user.username,
|
||||
'email': request.user.email,
|
||||
}
|
||||
|
|
|
@ -38,10 +38,8 @@ class SignUpForm(forms.Form):
|
|||
"""SignUp Form"""
|
||||
|
||||
title = _('Sign Up')
|
||||
first_name = forms.CharField(label=_('First Name'),
|
||||
widget=forms.TextInput(attrs={'placeholder': _('First Name')}))
|
||||
last_name = forms.CharField(label=_('Last Name'),
|
||||
widget=forms.TextInput(attrs={'placeholder': _('Last Name')}))
|
||||
name = forms.CharField(label=_('Name'),
|
||||
widget=forms.TextInput(attrs={'placeholder': _('Name')}))
|
||||
username = forms.CharField(label=_('Username'),
|
||||
widget=forms.TextInput(attrs={'placeholder': _('Username')}))
|
||||
email = forms.EmailField(label=_('E-Mail'),
|
||||
|
|
|
@ -13,7 +13,10 @@ class UserDetailForm(forms.ModelForm):
|
|||
class Meta:
|
||||
|
||||
model = User
|
||||
fields = ['username', 'first_name', 'last_name', 'email']
|
||||
fields = ['username', 'name', 'email']
|
||||
widgets = {
|
||||
'name': forms.TextInput
|
||||
}
|
||||
|
||||
class PasswordChangeForm(forms.Form):
|
||||
"""Form to update password"""
|
||||
|
|
38
passbook/core/migrations/0016_auto_20190227_1355.py
Normal file
38
passbook/core/migrations/0016_auto_20190227_1355.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 2.1.7 on 2019-02-27 13:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_names(apps, schema_editor):
|
||||
"""migrate first_name and last_name to name"""
|
||||
User = apps.get_model("passbook_core", "User")
|
||||
for user in User.objects.all():
|
||||
user.name = '%s %s' % (user.first_name, user.last_name)
|
||||
user.save()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passbook_core', '0015_passwordpolicy_error_message'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='name',
|
||||
field=models.TextField(default=''),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.RunPython(migrate_names),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='name',
|
||||
field=models.TextField(),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fieldmatcherpolicy',
|
||||
name='user_field',
|
||||
field=models.TextField(choices=[('username', 'Username'), ('name', 'Name'), ('email', 'E-Mail'), ('is_staff', 'Is staff'), ('is_active', 'Is active'), ('data_joined', 'Date joined')]),
|
||||
),
|
||||
]
|
|
@ -44,6 +44,8 @@ class User(AbstractUser):
|
|||
"""Custom User model to allow easier adding o f user-based settings"""
|
||||
|
||||
uuid = models.UUIDField(default=uuid4, editable=False)
|
||||
name = models.TextField()
|
||||
|
||||
sources = models.ManyToManyField('Source', through='UserSourceConnection')
|
||||
applications = models.ManyToManyField('Application')
|
||||
groups = models.ManyToManyField('Group')
|
||||
|
@ -253,8 +255,7 @@ class FieldMatcherPolicy(Policy):
|
|||
|
||||
USER_FIELDS = (
|
||||
('username', _('Username'),),
|
||||
('first_name', _('First Name'),),
|
||||
('last_name', _('Last Name'),),
|
||||
('name', _('Name'),),
|
||||
('email', _('E-Mail'),),
|
||||
('is_staff', _('Is staff'),),
|
||||
('is_active', _('Is active'),),
|
||||
|
|
|
@ -15,8 +15,7 @@ class TestAuthenticationViews(TestCase):
|
|||
def setUp(self):
|
||||
super().setUp()
|
||||
self.sign_up_data = {
|
||||
'first_name': 'Test',
|
||||
'last_name': 'User',
|
||||
'name': 'Test',
|
||||
'username': 'beryjuorg',
|
||||
'email': 'unittest@passbook.beryju.org',
|
||||
'password': 'B3ryju0rg!',
|
||||
|
|
|
@ -204,8 +204,7 @@ class SignUpView(UserPassesTestMixin, FormView):
|
|||
new_user = User.objects.create(
|
||||
username=data.get('username'),
|
||||
email=data.get('email'),
|
||||
first_name=data.get('first_name'),
|
||||
last_name=data.get('last_name'),
|
||||
name=data.get('name'),
|
||||
)
|
||||
new_user.is_active = True
|
||||
try:
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"""passbook core user views"""
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import logout, update_session_auth_hash
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.forms.utils import ErrorList
|
||||
from django.shortcuts import redirect, reverse
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import DeleteView, FormView, UpdateView
|
||||
|
||||
|
@ -11,12 +13,15 @@ from passbook.core.forms.users import PasswordChangeForm, UserDetailForm
|
|||
from passbook.lib.config import CONFIG
|
||||
|
||||
|
||||
class UserSettingsView(UpdateView):
|
||||
class UserSettingsView(SuccessMessageMixin, UpdateView):
|
||||
"""Update User settings"""
|
||||
|
||||
template_name = 'user/settings.html'
|
||||
form_class = UserDetailForm
|
||||
|
||||
success_message = _('Successfully updated user.')
|
||||
success_url = reverse_lazy('passbook_core:user-settings')
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class LDAPConnector:
|
|||
# Create the user data.
|
||||
field_map = {
|
||||
'username': '%(' + USERNAME_FIELD + ')s',
|
||||
'first_name': '%(givenName)s %(sn)s',
|
||||
'name': '%(givenName)s %(sn)s',
|
||||
'email': '%(mail)s',
|
||||
}
|
||||
user_fields = {}
|
||||
|
@ -224,9 +224,9 @@ class LDAPConnector:
|
|||
'cn': str(username),
|
||||
'description': str('t=' + time()),
|
||||
'sAMAccountName': str(username_trunk),
|
||||
'givenName': str(user.first_name),
|
||||
'givenName': str(user.name),
|
||||
'displayName': str(user.username),
|
||||
'name': str(user.first_name),
|
||||
'name': str(user.name),
|
||||
'mail': str(user.email),
|
||||
'userPrincipalName': str(username + '@' + self._source.domain),
|
||||
'objectClass': ['top', 'person', 'organizationalPerson', 'user'],
|
||||
|
|
|
@ -77,10 +77,9 @@ ldap:
|
|||
email: mail # or userPrincipalName
|
||||
user_attribute_map:
|
||||
active_directory:
|
||||
sAMAccountName: username
|
||||
mail: email
|
||||
given_name: first_name
|
||||
name: last_name
|
||||
username: "%(sAMAccountName)s"
|
||||
email: "%(mail)s"
|
||||
name: "%(displayName)"
|
||||
oauth_client:
|
||||
# List of python packages with sources types to load.
|
||||
types:
|
||||
|
|
|
@ -52,7 +52,7 @@ class DiscordOAuth2Callback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('username'),
|
||||
'email': info.get('email', 'None'),
|
||||
'first_name': info.get('username'),
|
||||
'name': info.get('username'),
|
||||
'password': None,
|
||||
}
|
||||
discord_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -23,7 +23,7 @@ class FacebookOAuth2Callback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('name'),
|
||||
'email': info.get('email', ''),
|
||||
'first_name': info.get('name'),
|
||||
'name': info.get('name'),
|
||||
'password': None,
|
||||
}
|
||||
fb_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -13,7 +13,7 @@ class GitHubOAuth2Callback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('login'),
|
||||
'email': info.get('email', ''),
|
||||
'first_name': info.get('name'),
|
||||
'name': info.get('name'),
|
||||
'password': None,
|
||||
}
|
||||
gh_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -22,7 +22,7 @@ class GoogleOAuth2Callback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('email'),
|
||||
'email': info.get('email', ''),
|
||||
'first_name': info.get('name'),
|
||||
'name': info.get('name'),
|
||||
'password': None,
|
||||
}
|
||||
google_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -61,7 +61,7 @@ class RedditOAuth2Callback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('name'),
|
||||
'email': None,
|
||||
'first_name': info.get('name'),
|
||||
'name': info.get('name'),
|
||||
'password': None,
|
||||
}
|
||||
reddit_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -46,7 +46,7 @@ class SupervisrOAuthCallback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('username'),
|
||||
'email': info.get('email', ''),
|
||||
'first_name': info.get('first_name'),
|
||||
'name': info.get('first_name'),
|
||||
'password': None,
|
||||
}
|
||||
sv_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -38,7 +38,7 @@ class TwitterOAuthCallback(OAuthCallback):
|
|||
user_data = {
|
||||
'username': info.get('screen_name'),
|
||||
'email': info.get('email', ''),
|
||||
'first_name': info.get('name'),
|
||||
'name': info.get('name'),
|
||||
'password': None,
|
||||
}
|
||||
tw_user = user_get_or_create(**user_data)
|
||||
|
|
|
@ -27,7 +27,7 @@ class GitHubUserView(View):
|
|||
"received_events_url": "",
|
||||
"type": "User",
|
||||
"site_admin": False,
|
||||
"name": "%s %s" % (request.user.first_name, request.user.last_name),
|
||||
"name": request.user.name,
|
||||
"company": "",
|
||||
"blog": "",
|
||||
"location": "",
|
||||
|
|
|
@ -157,7 +157,7 @@ class Processor:
|
|||
{
|
||||
'FriendlyName': 'cn',
|
||||
'Name': 'urn:oid:2.5.4.3',
|
||||
'Value': self._django_request.user.first_name,
|
||||
'Value': self._django_request.user.name,
|
||||
},
|
||||
{
|
||||
'FriendlyName': 'mail',
|
||||
|
|
Reference in a new issue