Commit e9b69800 authored by root's avatar root

init

parents
__pycache__
.DS_Store
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AppConfig(AppConfig):
name = 'app'
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
import os
class Command(BaseCommand):
help = 'Create admin & guest user'
def handle(self, *args, **options):
def create_user(name, password=None):
user = User.objects.create_user(name,
password=os.urandom(1024) if password is None else password)
user.is_superuser = False
user.is_staff = False
user.save()
create_user("admin")
create_user("guest", "guest")
\ No newline at end of file
from django.db import models
# Create your models here.
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="content container pt-5">
{% block content %}
{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
{% extends "app/base.html" %}
{% block title %}{{ name }}{% endblock %}
{% block content %}
<h1>{{ name }}</h1>
<form method="post" action=".">
<div class="form-group">
<label>
用户名:<input type="text" class="form-control" name="username">
</label>
</div>
<div class="form-group">
<label>
密码:<input type="password" class="form-control" name="password">
</label>
</div>
<button type="submit" class="btn btn-primary">登录</button>
</form>
<br>
<p>你可以使用 guest 用户(密码为 guest)体验。</p>
{% endblock %}
\ No newline at end of file
{% extends "app/base.html" %}
{% block title %}{{ name }} - 个人信息 {% endblock %}
{% block content %}
<h1>{{ name }} - 个人信息</h1>
<h3>欢迎您,{{ username }}!</h3>
<p>{{ profile }}</p>
<p><a class="btn btn-danger" href="{% url 'logout' %}">退出账户</a></p>
<h4>Debug - Your cookie</h4>
<p id="cookie"></p>
<script>
document.getElementById("cookie").textContent = document.cookie;
</script>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('profile', views.profile, name='profile'),
path('logout', views.log_out, name='logout')
]
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
name = "Rabbit House 成员管理系统"
def index(request):
if request.method == "GET":
if request.user.is_authenticated:
return redirect(reverse("profile"))
return render(request, 'app/index.html', {
"name": name
})
elif request.method == "POST":
username = request.POST["username"]
password = request.POST["password"]
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect(reverse("profile"))
else:
return redirect(reverse("index"))
@login_required
def profile(request):
if request.user.username == "admin":
user_profile = "flag redacted. login as admin on server to get flag."
else:
user_profile = "仅 admin 用户可阅览 flag。"
return render(request, 'app/profile.html', {
"name": name,
"username": request.user,
"profile": user_profile
})
def log_out(request):
logout(request)
return redirect(reverse("index"))
from django.contrib.auth import models
def update_last_login(sender, user, **kwargs):
pass
models.update_last_login = update_last_login
File added
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openlug.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
"""
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 = 'd7um#o19q+v24!vkgzrxme41wz5#_h0#[email protected]&uwe39'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
# 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app'
]
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 performance
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
# javascript code can get document.cookie, debug
SESSION_COOKIE_HTTPONLY = False
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'openlug.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'zh-Hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
LOGIN_URL = '/'
"""openlug URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
# path('admin/', admin.site.urls),
path('', include('app.urls')),
]
"""
WSGI config for openlug project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openlug.settings')
application = get_wsgi_application()
Django==2.2.5
pytz==2019.2
sqlparse==0.3.0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment