Commit f4a8e7a1 authored by root's avatar root
Browse files

Usefull stuff

parent a2767b9f
......@@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, LDAP
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, UID_RANGES, LDAP
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......
......@@ -15,6 +15,7 @@ class UserAdmin(admin.ModelAdmin):
'email',
'shell',
'state'
'uid_number',
)
search_fields = ('name','surname','pseudo')
......@@ -49,11 +50,11 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = ('pseudo', 'name', 'surname', 'email', 'is_admin', 'shell')
list_display = ('pseudo', 'name', 'surname', 'email', 'is_admin', 'shell', 'uid_number')
list_filter = ()
fieldsets = (
(None, {'fields': ('pseudo', 'password')}),
('Personal info', {'fields': ('name', 'surname', 'email', 'shell')}),
('Personal info', {'fields': ('name', 'surname', 'email', 'shell', 'uid_number')}),
('Permissions', {'fields': ('is_admin', )}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
......
......@@ -2,10 +2,10 @@
from __future__ import unicode_literals
from django.db import migrations, models
import users.models
import ldapdb.models.fields
import django.db.models.deletion
from django.conf import settings
import users.models
import ldapdb.models.fields
class Migration(migrations.Migration):
......@@ -17,16 +17,17 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(verbose_name='last login', null=True, blank=True)),
('last_login', models.DateTimeField(blank=True, verbose_name='last login', null=True)),
('name', models.CharField(max_length=255)),
('surname', models.CharField(max_length=255)),
('pseudo', models.CharField(max_length=32, unique=True, validators=[users.models.linux_user_validator], help_text='Doit contenir uniquement des lettres, chiffres, ou tirets')),
('pseudo', models.CharField(max_length=32, help_text='Doit contenir uniquement des lettres, chiffres, ou tirets', unique=True, validators=[users.models.linux_user_validator])),
('email', models.EmailField(max_length=254)),
('comment', models.CharField(max_length=255, help_text='Commentaire, promo', blank=True)),
('state', models.IntegerField(default=0, choices=[(0, 'STATE_ACTIVE'), (1, 'STATE_DEACTIVATED'), (2, 'STATE_ARCHIVED')])),
('registered', models.DateTimeField(auto_now_add=True)),
('uid_number', models.IntegerField(unique=True, default=users.models.User.auto_uid)),
],
options={
'abstract': False,
......@@ -37,16 +38,15 @@ class Migration(migrations.Migration):
fields=[
('dn', models.CharField(max_length=200)),
('gid', ldapdb.models.fields.IntegerField(db_column='gidNumber')),
('name', ldapdb.models.fields.CharField(db_column='cn', max_length=200)),
('netfederez', ldapdb.models.fields.CharField(db_column='netFederezUID', max_length=200)),
('uid', ldapdb.models.fields.CharField(db_column='uid', max_length=200, serialize=False, primary_key=True)),
('uidNumber', ldapdb.models.fields.IntegerField(db_column='uidNumber', unique=True)),
('sn', ldapdb.models.fields.CharField(db_column='sn', max_length=200)),
('loginShell', ldapdb.models.fields.CharField(db_column='loginShell', max_length=200, null=True, blank=True)),
('mail', ldapdb.models.fields.CharField(db_column='mail', max_length=200)),
('home_directory', ldapdb.models.fields.CharField(db_column='homeDirectory', max_length=200)),
('display_name', ldapdb.models.fields.CharField(db_column='displayName', max_length=200, null=True, blank=True)),
('user_password', ldapdb.models.fields.CharField(db_column='userPassword', max_length=200, null=True, blank=True)),
('name', ldapdb.models.fields.CharField(max_length=200, db_column='cn')),
('uid', ldapdb.models.fields.CharField(primary_key=True, max_length=200, db_column='uid', serialize=False)),
('uidNumber', ldapdb.models.fields.IntegerField(unique=True, db_column='uidNumber')),
('sn', ldapdb.models.fields.CharField(max_length=200, db_column='sn')),
('loginShell', ldapdb.models.fields.CharField(max_length=200, blank=True, null=True, db_column='loginShell')),
('mail', ldapdb.models.fields.CharField(max_length=200, db_column='mail')),
('home_directory', ldapdb.models.fields.CharField(max_length=200, db_column='homeDirectory')),
('display_name', ldapdb.models.fields.CharField(max_length=200, blank=True, null=True, db_column='displayName')),
('user_password', ldapdb.models.fields.CharField(max_length=200, blank=True, null=True, db_column='userPassword')),
],
options={
'abstract': False,
......@@ -57,8 +57,8 @@ class Migration(migrations.Migration):
fields=[
('dn', models.CharField(max_length=200)),
('gid', ldapdb.models.fields.IntegerField(db_column='gidNumber')),
('members', ldapdb.models.fields.ListField(db_column='memberUid', blank=True)),
('name', ldapdb.models.fields.CharField(db_column='cn', max_length=200, serialize=False, primary_key=True)),
('members', ldapdb.models.fields.ListField(blank=True, db_column='memberUid')),
('name', ldapdb.models.fields.CharField(primary_key=True, max_length=200, db_column='cn', serialize=False)),
],
options={
'abstract': False,
......@@ -67,7 +67,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ListRight',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
('listright', models.CharField(max_length=255, unique=True)),
('gid', models.IntegerField(unique=True, null=True)),
],
......@@ -75,33 +75,33 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ListShell',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
('shell', models.CharField(max_length=255, unique=True)),
],
),
migrations.CreateModel(
name='Request',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
('type', models.CharField(max_length=2, choices=[('PW', 'Mot de passe'), ('EM', 'Email')])),
('token', models.CharField(max_length=32)),
('created_at', models.DateTimeField(auto_now_add=True)),
('expires_at', models.DateTimeField()),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=django.db.models.deletion.PROTECT)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Right',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('right', models.ForeignKey(to='users.ListRight', on_delete=django.db.models.deletion.PROTECT)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=django.db.models.deletion.PROTECT)),
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
('right', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='users.ListRight')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='user',
name='shell',
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.PROTECT, to='users.ListShell', null=True),
field=models.ForeignKey(to='users.ListShell', null=True, on_delete=django.db.models.deletion.PROTECT, blank=True),
),
migrations.AlterUniqueTogether(
name='right',
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import users.models
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='user',
name='uid_number',
field=models.IntegerField(unique=True, null=True, default=users.models.User.auto_uid),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0002_auto_20160804_0312'),
]
operations = [
migrations.RemoveField(
model_name='listright',
name='gid',
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0003_remove_listright_gid'),
]
operations = [
migrations.AddField(
model_name='listright',
name='gid',
field=models.IntegerField(unique=True, null=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import ldapdb.models.fields
class Migration(migrations.Migration):
dependencies = [
('users', '0004_listright_gid'),
]
operations = [
migrations.AddField(
model_name='ldapuser',
name='shadow_expire',
field=ldapdb.models.fields.IntegerField(max_length=200, db_column='shadowExpire', null=True, blank=True),
),
]
......@@ -8,7 +8,7 @@ from django.dispatch import receiver
import ldapdb.models
import ldapdb.models.fields
from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, LDAP
from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, UID_RANGES, LDAP
import re, uuid
import datetime
......@@ -85,6 +85,12 @@ class User(AbstractBaseUser):
(2, 'STATE_ARCHIVED'),
)
def auto_uid():
uids = list(range(int(min(UID_RANGES['users'])),int(max(UID_RANGES['users']))))
used_uids = [ user.uid_number for user in User.objects.all()]
free_uids = [ id for id in uids if id not in used_uids]
return min(free_uids)
name = models.CharField(max_length=255)
surname = models.CharField(max_length=255)
pseudo = models.CharField(max_length=32, unique=True, help_text="Doit contenir uniquement des lettres, chiffres, ou tirets", validators=[linux_user_validator])
......@@ -93,6 +99,7 @@ class User(AbstractBaseUser):
comment = models.CharField(help_text="Commentaire, promo", max_length=255, blank=True)
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
registered = models.DateTimeField(auto_now_add=True)
uid_number = models.IntegerField(default=auto_uid, unique=True, null=True)
USERNAME_FIELD = 'pseudo'
REQUIRED_FIELDS = ['name', 'surname', 'email']
......@@ -166,25 +173,29 @@ class User(AbstractBaseUser):
user_right.delete()
def ldap_sync(self, base=True):
uid_ldap = str(self.surname).lower() + '.' + str(self.name).lower()
try:
user_ldap = LdapUser.objects.get(uid=uid_ldap)
user_ldap = LdapUser.objects.get(uidNumber=self.uid_number)
except LdapUser.DoesNotExist:
user_ldap = LdapUser(uid=uid_ldap)
user_ldap = LdapUser(uidNumber=self.uid_number)
if base:
user_ldap.uid = str(self.surname).lower() + '.' + str(self.name).lower()
user_ldap.name = (self.pseudo)
user_ldap.sn = str(self.name)
user_ldap.uidNumber = self.id
user_ldap.home_directory = '/home/' + self.pseudo
user_ldap.mail = self.email
user_ldap.display_name = str(self.surname) + ' ' + str(self.name)
user_ldap.user_password = self.password
user_ldap.loginShell = self.shell.shell
user_ldap.user_password = self.password[:6] + self.password[7:]
if self.shell:
user_ldap.loginShell = self.shell.shell
if self.has_access():
user_ldap.shadow_expire = None
else:
user_ldap.shadow_expire = 0
user_ldap.save()
def ldap_del(self):
try:
user_ldap = LdapUser.objects.get(name=self.pseudo)
user_ldap = LdapUser.objects.get(uidNumber=self.uid_number)
user_ldap.delete()
except LdapUser.DoesNotExist:
pass
......@@ -301,6 +312,7 @@ class LdapUser(ldapdb.models.Model):
home_directory = ldapdb.models.fields.CharField(db_column='homeDirectory', max_length=200)
display_name = ldapdb.models.fields.CharField(db_column='displayName', max_length=200, blank=True, null=True)
user_password = ldapdb.models.fields.CharField(db_column='userPassword', max_length=200, blank=True, null=True)
shadow_expire = ldapdb.models.fields.IntegerField(db_column='shadowExpire', blank=True, null=True)
def __str__(self):
return self.uid
......
......@@ -19,8 +19,8 @@
<th>Prénom</th>
<th>Nom</th>
<th>Pseudo</th>
<th>Fin de cotisation le</th>
<th>Connexion</th>
<th>Statut</th>
<th>Uid</th>
<th>Profil</th>
</tr>
</thead>
......@@ -29,12 +29,12 @@
<td>{{ user.name }}</td>
<td>{{ user.surname }}</td>
<td>{{ user.pseudo }}</td>
<td>{% if user.is_adherent %}{{ user.end_adhesion }}{% else %}Non adhérent{% endif %}</td>
<td>{% if user.has_access == True %}
<font color="green">Active</font>
{% else %}
<font color="red">Désactivée</font>
{% endif %}
<td>{{ user.uid_number }}</td>
</td>
<td><a href="{% url "users:profil" user.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a>
</td>
......
......@@ -30,6 +30,10 @@
<th>Date d'inscription</th>
<td>{{ user.registered }}</td>
</tr>
<th>Uid</th>
<td>{{ user.uid_number }}</td>
<th>Shell</th>
<td>{{ user.shell }}</td>
<tr>
<th>Statut</th>
{% if user.state == 0 %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment