mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-06 07:06:19 +01:00
added user login and registration
This commit is contained in:
5
authentication/forms.py
Normal file
5
authentication/forms.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django import forms
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField(max_length=16, required = True)
|
||||
password = forms.CharField(widget=forms.PasswordInput())
|
||||
@@ -24,6 +24,27 @@ class AllianceUserManager(BaseUserManager):
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_user_withapi(self, username, email, password, api_id, api_key):
|
||||
"""
|
||||
Creates and saves a User with the given email, date of
|
||||
birth and password.
|
||||
"""
|
||||
|
||||
if not username:
|
||||
raise ValueError('Users must have a username')
|
||||
|
||||
if not email:
|
||||
raise ValueError('Users must have an email address')
|
||||
|
||||
user = AllianceUser()
|
||||
user.set_username(username)
|
||||
user.set_email(email)
|
||||
user.set_password(password)
|
||||
user.set_api_id(api_id)
|
||||
user.set_api_key(api_key)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, username, email, password):
|
||||
"""
|
||||
Creates and saves a superuser with the given email, date of
|
||||
@@ -43,6 +64,8 @@ class AllianceUser(AbstractBaseUser):
|
||||
is_admin = models.BooleanField(default=False)
|
||||
is_moderator = models.BooleanField(default = False)
|
||||
is_banned = models.BooleanField(default = False)
|
||||
api_id = models.CharField(max_length = 254)
|
||||
api_key = models.CharField(max_length = 254)
|
||||
objects = AllianceUserManager()
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
|
||||
@@ -1,3 +1,27 @@
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, render
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.template import RequestContext
|
||||
from forms import LoginForm
|
||||
|
||||
# Create your views here.
|
||||
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("/")
|
||||
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