mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Merge branch 'development' of https://github.com/Rushilwiz/SkoolOS into development
This commit is contained in:
commit
8605cdce24
|
@ -41,6 +41,7 @@ INSTALLED_APPS = [
|
|||
'rest_framework',
|
||||
'api',
|
||||
'crispy_forms',
|
||||
'django_forms_bootstrap',
|
||||
|
||||
|
||||
]
|
||||
|
|
|
@ -14,6 +14,9 @@ router.register(r'classes', api_views.ClassesViewSet)
|
|||
# router.register(r'files', api_views.DefFilesViewSet)
|
||||
router.register(r'users', api_views.UserViewSet)
|
||||
|
||||
from users import views as user_views
|
||||
from users.forms import LoginForm
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
|
@ -21,7 +24,7 @@ urlpatterns = [
|
|||
path('api/', include(router.urls)),
|
||||
path('api-auth/', include('rest_framework.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('login/', auth_views.LoginView.as_view(template_name="users/login.html"), name='login'),
|
||||
path('login/', auth_views.LoginView.as_view(template_name='users/login.html', authentication_form=LoginForm), name='login'),
|
||||
path('register/', user_views.register, name='register'),
|
||||
path('create_account/', user_views.create_account, name='create_account'),
|
||||
path('callback/', user_views.callback, name='callback'),
|
||||
|
|
|
@ -1,19 +1,37 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
class LoginForm(AuthenticationForm):
|
||||
username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Username'}))
|
||||
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder':'Password'}))
|
||||
|
||||
class UserCreationForm(forms.ModelForm):
|
||||
|
||||
username = forms.CharField(disabled=True)
|
||||
email = forms.EmailField(disabled=True)
|
||||
first_name = forms.CharField(disabled=True)
|
||||
last_name = forms.CharField(disabled=True)
|
||||
password = forms.PasswordInput()
|
||||
confirm_password = forms.PasswordInput()
|
||||
|
||||
username = forms.CharField()
|
||||
email = forms.EmailField()
|
||||
first_name = forms.CharField()
|
||||
last_name = forms.CharField()
|
||||
isStudent = forms.BooleanField(widget = forms.HiddenInput())
|
||||
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
|
||||
confirm_password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'}))
|
||||
token = forms.CharField(widget = forms.HiddenInput())
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(UserCreationForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(UserCreationForm, self).clean()
|
||||
password = cleaned_data.get("password")
|
||||
confirm_password = cleaned_data.get("confirm_password")
|
||||
|
||||
if password != confirm_password:
|
||||
raise forms.ValidationError("Passwords do not match!")
|
||||
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'email', 'first_name', 'password', 'confirm_password']
|
||||
fields = ('username', 'email', 'first_name', 'last_name', 'password')
|
||||
|
|
|
@ -18,4 +18,4 @@ class Token(models.Model):
|
|||
return super(Token, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.username}'s Token";
|
||||
return self.token;
|
||||
|
|
22
Website/users/templates/users/create_account.html
Normal file
22
Website/users/templates/users/create_account.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
{% extends "users/base.html" %}
|
||||
{% load bootstrap_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="login-page">
|
||||
<div class="form">
|
||||
<form class="login-form" method="POST">
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
<div class="fieldWrapper">
|
||||
{{ field.errors }}
|
||||
{{ field }}
|
||||
{% if field.help_text %}
|
||||
<p class="help">{{ field.help_text|safe }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit">create</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,13 +0,0 @@
|
|||
{% extends "users/base.html" %}
|
||||
{% block content %}
|
||||
<div class="login-page">
|
||||
<div class="form">
|
||||
<form class="register-form">
|
||||
<input type="text" placeholder="name"/>
|
||||
<input type="password" placeholder="password"/>
|
||||
<input type="text" placeholder="email address"/>
|
||||
<button>create</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,16 +1,23 @@
|
|||
{% extends "users/base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load bootstrap_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="login-page">
|
||||
<div class="form">
|
||||
<form class="login-form" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
{% for field in form %}
|
||||
<div class="fieldWrapper">
|
||||
{{ field.errors }}
|
||||
{{ field }}
|
||||
{% if field.help_text %}
|
||||
<p class="help">{{ field.help_text|safe }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit">login</button>
|
||||
<p class="message">Not registered? <a href="{% url 'register' %}">Create an account with Ion</a></p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,6 +7,7 @@ from requests_oauthlib import OAuth2Session
|
|||
from django.contrib import messages
|
||||
|
||||
from .models import Token
|
||||
from .forms import UserCreationForm
|
||||
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import login as auth_login
|
||||
|
@ -53,7 +54,7 @@ def callback (request):
|
|||
|
||||
if User.objects.filter(username=username).count() != 0:
|
||||
messages.success(request, "This user already exists!")
|
||||
return redirect('register')
|
||||
return redirect('/login/')
|
||||
else:
|
||||
token = Token(username = username, email = email, first_name = first_name, last_name = last_name, isStudent = isStudent)
|
||||
token.save()
|
||||
|
@ -63,18 +64,57 @@ def callback (request):
|
|||
|
||||
|
||||
messages.warning(request, "Invalid Callback Response")
|
||||
return redirect('register')
|
||||
return redirect('/login/')
|
||||
|
||||
|
||||
def create_account (request):
|
||||
if request.method == "POST":
|
||||
print("POSTPOSTPOSTPOSTPOSTPOSTPOSTPOST")
|
||||
form = UserCreationForm(request.POST)
|
||||
print(form.is_valid())
|
||||
print(request.POST)
|
||||
if form.is_valid():
|
||||
cleaned_data = form.cleaned_data
|
||||
token = Token.objects.get(token=cleaned_data.get('token'))
|
||||
username = token.username
|
||||
email = token.email
|
||||
first_name = token.first_name
|
||||
last_name = token.last_name
|
||||
isStudent = token.isStudent
|
||||
password = cleaned_data.get('password')
|
||||
|
||||
user = User.objects.create_user(username=username,
|
||||
email=email,
|
||||
first_name=first_name,
|
||||
last_name=last_name,
|
||||
password=password)
|
||||
user.save()
|
||||
token.delete()
|
||||
print (user)
|
||||
return redirect(f'/login/?username={username}')
|
||||
else:
|
||||
print(form.errors)
|
||||
Token.objects.get(token=request.GET.get('token')).delete()
|
||||
return redirect('/register/?error=password')
|
||||
|
||||
if request.method == "GET" and Token.objects.filter(token=request.GET.get('token')).count() == 1:
|
||||
print("GETGETGETGETGETGET")
|
||||
token = Token.objects.get(token=request.GET.get('token'))
|
||||
tokenHash = request.GET.get('token')
|
||||
username = token.username
|
||||
email = token.email
|
||||
first_name = token.first_name
|
||||
last_name = token.last_name
|
||||
isStudent = token.isStudent
|
||||
initial = {
|
||||
'username': username,
|
||||
'email': email,
|
||||
'first_name': first_name,
|
||||
'last_name': last_name,
|
||||
'isStudent': isStudent,
|
||||
'token': token,
|
||||
}
|
||||
form = UserCreationForm(initial=initial)
|
||||
return render(request, 'users/create_account.html', {'form': form})
|
||||
|
||||
|
||||
else:
|
||||
return redirect('/register/')
|
||||
return redirect('/login/')
|
||||
|
|
Loading…
Reference in New Issue
Block a user