mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-06 15:16:20 +01:00
Redone correctly , structure, its pretty
This commit is contained in:
0
authentication/__init__.py
Normal file
0
authentication/__init__.py
Normal file
3
authentication/admin.py
Normal file
3
authentication/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
authentication/forms.py
Normal file
6
authentication/forms.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django import forms
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField(max_length=32, required=True)
|
||||
password = forms.CharField(widget=forms.PasswordInput())
|
||||
59
authentication/managers.py
Normal file
59
authentication/managers.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from models import AuthServicesInfo
|
||||
|
||||
|
||||
class AuthServicesInfoManager:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def __get_or_create(user):
|
||||
if AuthServicesInfo.objects.filter(user=user).exists():
|
||||
return AuthServicesInfo.objects.get(user=user)
|
||||
else:
|
||||
# We have to create
|
||||
print 'here'
|
||||
authserviceinfo = AuthServicesInfo()
|
||||
authserviceinfo.user = user
|
||||
authserviceinfo.save()
|
||||
return authserviceinfo
|
||||
|
||||
@staticmethod
|
||||
def get_auth_service_info(user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
return AuthServicesInfoManager.__get_or_create(user)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def update_main_char_Id(char_id, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
authserviceinfo = AuthServicesInfoManager.__get_or_create(user)
|
||||
authserviceinfo.main_char_id = char_id
|
||||
authserviceinfo.save(update_fields=['main_char_id'])
|
||||
|
||||
@staticmethod
|
||||
def update_user_forum_info(username, password, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
authserviceinfo = AuthServicesInfoManager.__get_or_create(user)
|
||||
authserviceinfo.forum_username = username
|
||||
authserviceinfo.forum_password = password
|
||||
authserviceinfo.save(update_fields=['forum_username', 'forum_password'])
|
||||
|
||||
@staticmethod
|
||||
def update_user_jabber_info(username, password, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
authserviceinfo = AuthServicesInfoManager.__get_or_create(user)
|
||||
authserviceinfo.jabber_username = username
|
||||
authserviceinfo.jabber_password = password
|
||||
authserviceinfo.save(update_fields=['jabber_username', 'jabber_password'])
|
||||
|
||||
|
||||
@staticmethod
|
||||
def update_user_mumble_info(username, password, user):
|
||||
if User.objects.filter(username=user.username).exists():
|
||||
authserviceinfo = AuthServicesInfoManager.__get_or_create(user)
|
||||
authserviceinfo.mumble_username = username
|
||||
authserviceinfo.mumble_password = password
|
||||
authserviceinfo.save(update_fields=['mumble_username', 'mumble_password'])
|
||||
17
authentication/models.py
Normal file
17
authentication/models.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class AuthServicesInfo(models.Model):
|
||||
forum_username = models.CharField(max_length=254, default="")
|
||||
forum_password = models.CharField(max_length=254, default="")
|
||||
jabber_username = models.CharField(max_length=254, default="")
|
||||
jabber_password = models.CharField(max_length=254, default="")
|
||||
mumble_username = models.CharField(max_length=254, default="")
|
||||
mumble_password = models.CharField(max_length=254, default="")
|
||||
main_char_id = models.CharField(max_length=64, default="")
|
||||
|
||||
user = models.ForeignKey(User)
|
||||
|
||||
admin.site.register(AuthServicesInfo)
|
||||
3
authentication/tests.py
Normal file
3
authentication/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
31
authentication/views.py
Normal file
31
authentication/views.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.contrib.auth import login
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth import authenticate
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from forms import LoginForm
|
||||
|
||||
|
||||
def login_user(request):
|
||||
if request.method == 'POST':
|
||||
form = LoginForm(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
login(request, user)
|
||||
return HttpResponseRedirect("/dashboard")
|
||||
|
||||
return render_to_response('public/login.html', {'form': form, 'error': True},
|
||||
context_instance=RequestContext(request))
|
||||
else:
|
||||
form = LoginForm()
|
||||
|
||||
return render_to_response('public/login.html', {'form': form}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def logout_user(request):
|
||||
logout(request)
|
||||
return HttpResponseRedirect("/")
|
||||
Reference in New Issue
Block a user