Skip to content

Commit

Permalink
Feat: Login but fake
Browse files Browse the repository at this point in the history
  • Loading branch information
loforsteph committed Jul 13, 2023
1 parent 21b765d commit 6e39df4
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 9 deletions.
16 changes: 16 additions & 0 deletions codes/menu/migrations/0004_delete_person.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.3 on 2023-07-13 01:25

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('menu', '0003_person'),
]

operations = [
migrations.DeleteModel(
name='Person',
),
]
3 changes: 0 additions & 3 deletions codes/menu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@ class Teacher(models.Model):
experience=models.CharField(max_length=50)
def __str__(self) -> str:
return ' '.join([self.name, self.edu, self.subjects])
class Person(models.Model):
username=models.CharField(max_length=20,default="")
password=models.CharField(max_length=20,default="")
3 changes: 2 additions & 1 deletion codes/menu/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django.urls import include, path
from django.contrib.auth.views import LoginView
from . import views
urlpatterns = [
path('form/',views.form),
Expand All @@ -13,7 +14,7 @@
path('selfForm/',views.selfFrom),
path('sumbit/',views.submit, name = 'submit'),
path('registerParse/', views.registerParse, name = 'registerParse'),
path('loginParse/',views.loginParse,name='loginParse'),
path('loginParse/',views.loginParse, name='loginParse'),
path('stuIndex/',views.std,name='std'),
path('teaIndex/',views.tea,name='tea'),
path('register/',views.register,name='register'),
Expand Down
25 changes: 21 additions & 4 deletions codes/menu/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from django.http import Http404
from .models import Teacher
from .models import Student
from .models import Person
from random import shuffle
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
# Create your views here.
def form(request):
template=loader.get_template('form.html')
Expand Down Expand Up @@ -93,10 +94,26 @@ def registerParse(request):
except Exception as e:
return render(request,'fail.html')
else:
person=Person(username=username1,password=password1)
person=User(username=username1,password=password1)
person.save()
return render(request,'success.html')

def loginParse(request):
return render(request,'none.html')
username1=request.POST['username']
password1=request.POST['password']
# print(username1)
# print(password1)
# user=authenticate(request,username='zx',password='123')
# if user is not None:
return index_teacher(request)
# else:
# return render(request,'fail.html')

def register(request):
return render(request,'register.html')
return render(request,'register.html')

def index_teacher(request):
return render(request,'index_Teacher.html')

def index_Student(request):
return render(request,'index_Student.html')
115 changes: 114 additions & 1 deletion codes/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,115 @@
<!-- 登录页面 -->
<!-- 要有Post形式的表单 类似selfFrom -->0
<!-- 传入参数 stu_list (list) 学生的列表
利用
{% for stu in stu_list %}
<html内容> (每次循环html内容都会被重复一次,可以配合智能间距或者自己设置)
{% endfor %}
来访问 (关于stu的属性见message.html)
链接设置为 href = '/message/{{ stu.id }}/'
-->

<!DOCTYPE html>
<html lang="zh">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block caption %} 苏州教到 {% endblock %}</title>
<!-- bootstrap cdn -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- axios cdn -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- jquery cdn -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"
integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>
{% block header %}{% endblock %}
</head>

<body>
{% block page %}
<div class="container pt-5">
<h1 style="text-align: center">{% block title %}{% endblock %}</h1>
<hr>
<div class="row align-items-center justify-content-center">
<div class="col-8">
<form action="{% url 'loginParse' %}" method="post">
{% csrf_token %}
<div class="login-form">
<h2>用户注册</h2>
<div class="form-group">
<label for="username" class="form-label">用户名</label>
<input type="text" class="form-control" id="username" placeholder="请输入用户名" name="username">
</div>
<div class="form-group">
<label for="password" class="form-label">密码</label>
<input type="password" class="form-control" id="password" placeholder="请输入密码" name="password">
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember"> 记住密码
</label>
</div>
<button type="submit" class="btn btn-primary">提交</button>
</div>
</form>
</div>
</div>
</div>
<!-- TODO: 在对应的bolck里完善基底页面,基底页面可以包含一些最基本的 比如上选择框和底部,这个讨论设计 -->
{% endblock %}
<style>
@import url('https://fonts.googleapis.com/css2?family=Fangsong&display=swap');

.login-form {
max-width: 60%;
margin: 0 auto;
padding: 20px;
background-color: #f8f9fa;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
font-family: 'Fangsong', Arial, sans-serif;
}

.login-form h2 {
text-align: center;
margin-bottom: 20px;
}

.login-form .form-group {
margin-bottom: 20px;
}

.login-form .form-label {
font-weight: bold;
}

.login-form .form-control {
height: 40px;
}

.login-form .form-check {
margin-top: 20px;
margin-bottom: 20px;
}

.login-form .btn {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</body>

</html>

0 comments on commit 6e39df4

Please sign in to comment.