mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 13:32:15 +00:00
Set up authentication system
This commit is contained in:
42
RIGS/migrations/0001_initial.py
Normal file
42
RIGS/migrations/0001_initial.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import django.core.validators
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Profile',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(max_length=30, unique=True, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username.', 'invalid')])),
|
||||
('first_name', models.CharField(max_length=30, blank=True, verbose_name='first name')),
|
||||
('last_name', models.CharField(max_length=30, blank=True, verbose_name='last name')),
|
||||
('email', models.EmailField(max_length=75, blank=True, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('initials', models.CharField(max_length=5, unique=True)),
|
||||
('phone', models.CharField(max_length=13, blank=True, null=True)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of his/her group.', verbose_name='groups', related_name='user_set', related_query_name='user', to='auth.Group')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions', related_name='user_set', related_query_name='user', to='auth.Permission')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'users',
|
||||
'verbose_name': 'user',
|
||||
'abstract': False,
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,16 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.conf import settings
|
||||
import hashlib
|
||||
|
||||
# Create your models here.
|
||||
class Profile(AbstractUser):
|
||||
initials = models.CharField(max_length=5, unique=True)
|
||||
phone = models.CharField(max_length=13, null=True, blank=True)
|
||||
|
||||
@property
|
||||
def profile_picture (self):
|
||||
url = ""
|
||||
if settings.USE_GRAVATAR or settings.USE_GRAVATAR is None:
|
||||
url = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email).hexdigest() + "?d=identicon&s=500"
|
||||
return url
|
||||
@@ -1,3 +1,11 @@
|
||||
from django.shortcuts import render
|
||||
from django.http.response import HttpResponseRedirect
|
||||
|
||||
# Create your views here.
|
||||
def login(request, **kwargs):
|
||||
if request.user.is_authenticated():
|
||||
next = request.REQUEST.get('next', '/')
|
||||
return HttpResponseRedirect(request.REQUEST.get('next', '/'))
|
||||
else:
|
||||
from django.contrib.auth.views import login
|
||||
return login(request)
|
||||
Reference in New Issue
Block a user