mirror of
https://github.com/Rushilwiz/pushup-contest.git
synced 2025-04-04 02:30:16 -04:00
finished most of the work!
This commit is contained in:
parent
84fe5aa38d
commit
e8626a50ac
5
admin.py
Normal file
5
admin.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from .models import StockValue
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(StockValue)
|
|
@ -44,7 +44,8 @@ INSTALLED_APPS = [
|
|||
'django.contrib.staticfiles',
|
||||
|
||||
'django_extensions',
|
||||
'django_secrets'
|
||||
'django_secrets',
|
||||
'crispy_forms'
|
||||
#'chartjs',
|
||||
]
|
||||
|
||||
|
@ -129,4 +130,10 @@ USE_TZ = True
|
|||
STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = (
|
||||
os.path.join(BASE_DIR, 'static'),
|
||||
)
|
||||
)
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
LOGIN_URL = 'login'
|
||||
LOGOUT_URL = 'logout'
|
||||
LOGIN_REDIRECT_URL = 'home'
|
|
@ -16,13 +16,15 @@ Including another URLconf
|
|||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
from django.contrib.auth import views as auth_views
|
||||
|
||||
from pushup import views as pushup_views
|
||||
from users import views as users_views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', pushup_views.home, name="home"),
|
||||
path('login/', users_views.login, name="login"),
|
||||
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
|
||||
path('signup/', users_views.signup, name="signup"),
|
||||
path('logout/', users_views.logout, name="logout")
|
||||
]
|
||||
|
|
|
@ -2,4 +2,4 @@ from django.contrib import admin
|
|||
from .models import StockValue
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(StockValue)
|
||||
admin.site.register(StockValue)
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
<th scope="col">#</th>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Push-Ups</th>
|
||||
<th scope="col">Party</th>
|
||||
<tbody>
|
||||
{% for profile in users %}
|
||||
<tr>
|
||||
<th scope="row">{{forloop.counter}}</th>
|
||||
<td>{{profile.user.first_name}} {{profile.user.last_name}}</td>
|
||||
<td>{{profile.pushups}}</td>
|
||||
<td>{{profile.party}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
11
users/forms.py
Normal file
11
users/forms.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from .models import Profile
|
||||
|
||||
class UserRegisterForm(UserCreationForm):
|
||||
key = forms.CharField(max_length=10, help_text="Enter the one word key that Rushil gave you. If you need a key, just DM rushil or sahishnu")
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'key', 'password1', 'password2']
|
21
users/migrations/0004_auto_20201019_0359.py
Normal file
21
users/migrations/0004_auto_20201019_0359.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.1.2 on 2020-10-19 07:59
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('users', '0003_auto_20201019_0252'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='user',
|
||||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
23
users/migrations/0005_auto_20201019_0407.py
Normal file
23
users/migrations/0005_auto_20201019_0407.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.1.2 on 2020-10-19 08:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0004_auto_20201019_0359'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='first_name',
|
||||
field=models.TextField(blank=True, max_length=25, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='last_name',
|
||||
field=models.TextField(blank=True, max_length=25, null=True),
|
||||
),
|
||||
]
|
|
@ -4,11 +4,13 @@ from django.contrib.auth.models import User
|
|||
# Create your models here.
|
||||
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
user = models.OneToOneField(User, blank=True, null=True, on_delete=models.CASCADE)
|
||||
key = models.TextField(max_length=20)
|
||||
pushups = models.DecimalField(max_digits=5, decimal_places=3)
|
||||
isEnabled = models.BooleanField(default=False)
|
||||
party = models.TextField(max_length=20)
|
||||
first_name = models.TextField(blank=True, null=True, max_length=25)
|
||||
last_name = models.TextField(blank=True, null=True, max_length=25)
|
||||
|
||||
def __str__ (self):
|
||||
return f"{self.user.username}'s Profile"
|
||||
return f"A Profile"
|
31
users/templates/users/base.html
Normal file
31
users/templates/users/base.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{% load static %}
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Pushup Contest</title>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<a class="navbar-brand" href="{% url 'home' %}">Push-Up Contest</a>
|
||||
</nav>
|
||||
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
31
users/templates/users/login.html
Normal file
31
users/templates/users/login.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{% extends 'users/base.html' %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block content %}
|
||||
<div class="container p-md-3">
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{ message.tags }} alert-dismissible fade show">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4">Log In</legend>
|
||||
{{ form|crispy }}
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-outline-info" type="submit">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="border-top pt-3">
|
||||
<small class="text-muted">
|
||||
Need An Account? <a class="ml-2" href="{% url 'signup' %}">Sign Up Now</a>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
27
users/templates/users/signup.html
Normal file
27
users/templates/users/signup.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{% extends 'users/base.html' %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block content %}
|
||||
<div class="container p-md-3">
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{ message.tags }} alert-dismissible fade show">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4">Claim your Push-Up Status</legend>
|
||||
{{ form|crispy }}
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-outline-info" type="submit">Sign Up</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -1,4 +1,4 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import login as auth_login
|
||||
|
@ -6,14 +6,49 @@ from django.contrib.auth import logout as auth_logout
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from .forms import UserRegisterForm
|
||||
from .models import Profile
|
||||
|
||||
from django.contrib import messages
|
||||
|
||||
# Create your views here.
|
||||
def login(request):
|
||||
return None
|
||||
return render(request, 'users/login.html')
|
||||
|
||||
def signup(request):
|
||||
return None
|
||||
if request.POST:
|
||||
print(request.POST)
|
||||
form = UserRegisterForm(request.POST)
|
||||
if form.is_valid():
|
||||
key = form.cleaned_data.get('key')
|
||||
if Profile.objects.filter(key=key).count() == 1:
|
||||
profile = Profile.objects.get(key=key)
|
||||
if profile.isEnabled == False:
|
||||
instance = form.save(commit=False)
|
||||
instance.save()
|
||||
instance.first_name = profile.first_name
|
||||
instance.last_name = profile.last_name
|
||||
instance.save()
|
||||
profile.user = instance
|
||||
profile.isEnabled = True
|
||||
profile.save()
|
||||
messages.success(request, f'Your account has been created! You are now able to log in')
|
||||
return redirect('login')
|
||||
else:
|
||||
messages.error(request, 'This account is alr activation', extra_tags='danger')
|
||||
else:
|
||||
messages.error(request, 'Looks like your key was invalid!', extra_tags='danger')
|
||||
else:
|
||||
messages.error(request, 'Looks like there were some problems with your form!', extra_tags='danger')
|
||||
|
||||
form = UserRegisterForm()
|
||||
|
||||
return render(request, 'users/signup.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def logout(request):
|
||||
auth_logout(request)
|
||||
return render(request, 'users/logout.html')
|
||||
return redirect('/')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user