diff options
author | coderick14 | 2017-05-17 15:40:18 +0530 |
---|---|---|
committer | coderick14 | 2017-05-17 15:41:00 +0530 |
commit | a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055 (patch) | |
tree | 20181e6b1936f50ad48d8e35720d64a37566f558 /sbhs_server/account | |
parent | 6f4a84c1e58ff4d54aab94cbee26e995328b05b8 (diff) | |
download | SBHS-2018-Rpi-a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055.tar.gz SBHS-2018-Rpi-a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055.tar.bz2 SBHS-2018-Rpi-a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055.zip |
Upgrade to Django 1.11
- Database integration yet to be tested
Diffstat (limited to 'sbhs_server/account')
-rw-r--r-- | sbhs_server/account/__init__.py | 0 | ||||
-rw-r--r-- | sbhs_server/account/admin.py | 3 | ||||
-rw-r--r-- | sbhs_server/account/models.py | 3 | ||||
-rw-r--r-- | sbhs_server/account/tests.py | 3 | ||||
-rw-r--r-- | sbhs_server/account/views.py | 111 |
5 files changed, 0 insertions, 120 deletions
diff --git a/sbhs_server/account/__init__.py b/sbhs_server/account/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/sbhs_server/account/__init__.py +++ /dev/null diff --git a/sbhs_server/account/admin.py b/sbhs_server/account/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/sbhs_server/account/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/sbhs_server/account/models.py b/sbhs_server/account/models.py deleted file mode 100644 index 71a8362..0000000 --- a/sbhs_server/account/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/sbhs_server/account/tests.py b/sbhs_server/account/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/sbhs_server/account/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/sbhs_server/account/views.py b/sbhs_server/account/views.py deleted file mode 100644 index 306b318..0000000 --- a/sbhs_server/account/views.py +++ /dev/null @@ -1,111 +0,0 @@ -from django.shortcuts import render, redirect -from sbhs_server.tables.models import Account, Board -from django.core.exceptions import ValidationError -from django.core.validators import validate_email -from django.contrib import messages -from sbhs_server.helpers import simple_encrypt -from django.contrib.auth import authenticate -from django.contrib.auth import login as LOGIN -from django.contrib.auth import logout as LOGOUT -from django.contrib.auth.decorators import login_required -# Create your views here. - -def index(req): - if req.user.is_authenticated(): - return redirect(home) - return render(req, "account/index.html") - -def new(): - pass - -def create(req): - error = [] - - name = req.POST.get("name").strip() - email = req.POST.get("email").strip() - username = req.POST.get("username").strip() - roll_number = req.POST.get("roll_number").strip() - password = req.POST.get("password") - confirm = req.POST.get("confirm") - institute = req.POST.get("institute").strip() - department = req.POST.get("department").strip() - position = req.POST.get("position").strip() - - error = error + (["Please enter a name."] if name == "" else []) - error = error + (["Please enter an email."] if email == "" else []) - error = error + (["Please enter an username."] if username == "" else []) - error = error + (["Please enter a roll_number."] if roll_number == "" else []) - - error = error + (["Please enter a password."] if password == "" else []) - error = error + (["Password confirmation does not match."] if password != confirm else []) - - error = error + (["Please enter an institute."] if institute == "" else []) - error = error + (["Please enter a department."] if department == "" else []) - error = error + (["Please enter a position."] if position == "" else []) - - try: - validate_email(email) - except ValidationError: - error = error + ["Please enter a valid email."] - - email_exists = Account.objects.filter(email=email).count() - error = error + (["Account with given email already exists."] if email_exists > 0 else []) - - username_exists = Account.objects.filter(username=username).count() - error = error + (["Account with given username already exists."] if username_exists > 0 else []) - - if error != []: - messages.add_message(req, messages.ERROR, "<br>".join(error)) - return redirect(index) - - # try: - account = Account( - name=name, - username=username, - email=email, - board_id=Board.allot_board() - ) - account.set_password(password) - account.save() - account.send_confirmation() - print "Done" - messages.add_message(req, messages.SUCCESS, "You have been registered successfully. Please check your email for confirmation.") - return redirect(index) - # except: - # messages.add_message(req, messages.ERROR, "Invalid information. Please try again.") - # return redirect(index) - -def confirm(req, token): - try: - email = simple_encrypt.decrypt(token) - account = Account.objects.get(email=email) - account.is_active = True - account.save() - messages.add_message(req, messages.SUCCESS, "Your email has been confirmed. You can login now.") - except: - messages.add_message(req, messages.ERROR, "Invalid confirmation token.") - - return redirect(index) - -def login(req): - username = req.POST.get('username') - password = req.POST.get('password') - user = authenticate(username=username, password=password) - if user is not None: - if user.is_active: - LOGIN(req, user) - return redirect(index) - else: - messages.add_message(req, messages.ERROR, "Your account is not activated yet. Please check your email for activation link.") - return redirect(index) - else: - messages.add_message(req, messages.ERROR, "Invalid username or password.") - return redirect(index) - -def logout(req): - LOGOUT(req) - return redirect(index) - -@login_required(redirect_field_name=None) -def home(req): - return render(req, "account/home.html") |