@app.route('/register',methods=['POST']) defregister(): if request.data: try: ifnot check(request.data): return"Register Failed" data = json.loads(request.data) if"username"notin data or"password"notin data: return"Register Failed" User = user() merge(data, User) Users.append(User) except Exception: return"Register Failed" return"Register Success" else: return"Register Failed"
@app.route('/login',methods=['POST']) deflogin(): if request.data: try: data = json.loads(request.data) if"username"notin data or"password"notin data: return"Login Failed" for user in Users: if user.check(data): session["username"] = data["username"] return"Login Success" except Exception: return"Login Failed" return"Login Failed"
from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from django.shortcuts import render, redirect,render_to_response from django.urls import reverse from django.views.decorators.csrf import csrf_exempt from django.conf import settings from django.shortcuts import HttpResponse name = "Django"
deflogin_view(request):
return render_to_response('app/login.html') defauth_view(request, onsuccess='/', onfail='/error'): username = request.POST["username"] password = request.POST["password"] user = authenticate(request, username=username, password=password) if user isnotNone: login(request, user) return redirect(onsuccess) else: return redirect(onfail) deferror_view(request): return render_to_response("app/error.html")
""" Django settings for openlug project. Generated by 'django-admin startproject' using Django 2.2.5. For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ """
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production non-secret! SECRET_KEY = 'p(^*@36nw13xtb23vu%x)2wp-vk)ggje^sobx+*w2zd^ae8qnn'
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = False
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', # we're going to be RESTful in the future, # to prevent inconvenience, just turn csrf off. # 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
ROOT_URLCONF = 'openlug.urls' # for database performan SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' # use PickleSerializer SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
classPickleSerializer(object): """ Simple wrapper around pickle to be used in signing.dumps and signing.loads. """ defdumps(self, obj): return pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
SECRET_KEY = 'p(^*@36nw13xtb23vu%x)2wp-vk)ggje^sobx+*w2zd^ae8qnn' salt = "django.contrib.sessions.backends.signed_cookies"
import django.core.signing
import pickle
classPickleSerializer(object): """ Simple wrapper around pickle to be used in signing.dumps and signing.loads. """ defdumps(self, obj): return pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)