Init
This commit is contained in:
commit
a5b7dfc60c
100 changed files with 21307 additions and 0 deletions
0
account/__init__.py
Normal file
0
account/__init__.py
Normal file
6
account/forms.py
Normal file
6
account/forms.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django import forms
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField(max_length=255)
|
||||
password = forms.CharField(max_length=255, widget=forms.PasswordInput)
|
||||
43
account/models.py
Normal file
43
account/models.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import signals
|
||||
from account.signals import create_profile, delete_profile
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(User, editable=False)
|
||||
uid = models.CharField("User-ID",
|
||||
max_length=8,
|
||||
null=True,
|
||||
default=None)
|
||||
sippin = models.CharField("SIP PIN",
|
||||
max_length=255,
|
||||
null=True,
|
||||
blank=True,
|
||||
default=None)
|
||||
gastropin = models.CharField("Gastro PIN",
|
||||
max_length=255,
|
||||
null=True,
|
||||
blank=True,
|
||||
default=None)
|
||||
rfid = models.CharField("RFID",
|
||||
max_length=255,
|
||||
null=True,
|
||||
blank=True,
|
||||
default=None)
|
||||
macaddress = models.CharField("MAC-Address",
|
||||
max_length=255,
|
||||
null=True,
|
||||
blank=True,
|
||||
default=None)
|
||||
clabpin = models.CharField("c-lab PIN",
|
||||
max_length=255,
|
||||
null=True,
|
||||
blank=True,
|
||||
default=None)
|
||||
|
||||
def __unicode__(self):
|
||||
return 'Profile: %s' % self.user.username
|
||||
|
||||
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
|
||||
signals.post_save.connect(create_profile, sender=User)
|
||||
signals.pre_delete.connect(delete_profile, sender=User)
|
||||
9
account/signals.py
Normal file
9
account/signals.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def create_profile(sender, instance, signal, created, **kwargs):
|
||||
from account.models import UserProfile
|
||||
|
||||
if created:
|
||||
UserProfile(user=instance).save()
|
||||
|
||||
def delete_profile(sender, instance, signal, **kwargs):
|
||||
from account.models import UserProfile
|
||||
UserProfile(user=instance).delete()
|
||||
32
account/templates/dashboard.html
Normal file
32
account/templates/dashboard.html
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<h2>{{ request.user.username }}</h2>
|
||||
{% for g in request.user.groups.all %}
|
||||
{% if g.name == "ceymaster" %}
|
||||
<a href="/groups/{{ g }}">
|
||||
<label class="label label-important">{{ g }}</label>
|
||||
</a>
|
||||
{% elif "cey" in g.name %}
|
||||
<a href="/groups/{{ g }}">
|
||||
<label class="label label-warning">{{ g }}</label>
|
||||
</a>
|
||||
{% elif g.name == "ldap_admins" %}
|
||||
<a href="/groups/{{ g }}">
|
||||
<label class="label label-success">{{ g }}</label>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="/groups/{{ g }}">
|
||||
<label class="label">{{ g }}</label>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% empty %}
|
||||
no groups...
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock body %}
|
||||
19
account/templates/login.html
Normal file
19
account/templates/login.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="span">
|
||||
<form class="form" action="/account/login/?next={{ redirect_to }}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input class="btn" type="submit" value="login"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock body %}
|
||||
16
account/tests.py
Normal file
16
account/tests.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
||||
8
account/urls.py
Normal file
8
account/urls.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^login/$', 'account.views.auth_login'),
|
||||
url(r'^logout/$', 'account.views.auth_logout'),
|
||||
)
|
||||
37
account/views.py
Normal file
37
account/views.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template.context import RequestContext
|
||||
from django.contrib.auth import login, logout, authenticate
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from account.forms import LoginForm
|
||||
|
||||
|
||||
def auth_login(request):
|
||||
redirect_to = request.REQUEST.get('next', '') or '/'
|
||||
if request.method == 'POST':
|
||||
form = LoginForm(request.POST)
|
||||
if form.is_valid():
|
||||
username = form.cleaned_data['username']
|
||||
password = form.cleaned_data['password']
|
||||
user = authenticate(username=username, password=password)
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
login(request, user)
|
||||
member, created = User.objects.get_or_create(
|
||||
username=username)
|
||||
if created:
|
||||
member.save()
|
||||
return HttpResponseRedirect(redirect_to)
|
||||
else:
|
||||
print 'user is none'
|
||||
else:
|
||||
form = LoginForm()
|
||||
return render_to_response('login.html',
|
||||
RequestContext(request, locals()))
|
||||
|
||||
|
||||
def auth_logout(request):
|
||||
redirect_to = request.REQUEST.get('next', '') or '/'
|
||||
logout(request)
|
||||
return HttpResponseRedirect(redirect_to)
|
||||
Loading…
Add table
Add a link
Reference in a new issue