update:updating account model

main
= 3 years ago
parent 23b18da716
commit 6949c9cfed

@ -1,3 +1,6 @@
from django.contrib import admin
from apps.account.models import Account
# Register your models here.
admin.site.register(Account)

@ -0,0 +1,83 @@
# Generated by Django 3.2.18 on 2023-04-01 16:19
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Account',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('name', models.CharField(max_length=50, unique=True)),
('real_name', models.CharField(max_length=50, null=True)),
('password', models.CharField(max_length=50)),
('email', models.CharField(max_length=100, null=True, unique=True)),
('gender', models.IntegerField(choices=[(0, 'Unknown'), (1, 'Female'), (2, 'Male')], default=0)),
('avatar_url', models.CharField(max_length=255)),
('signature', models.CharField(default=None, max_length=255, null=True)),
('title_name', models.CharField(max_length=50, null=True)),
('is_active', models.BooleanField(default=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Auth',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('type', models.CharField(choices=[('admin', 'Admin'), ('super admin', 'Superadmin'), ('common', 'Common'), ('contest', 'Contest')], default='common', max_length=50)),
('permission', models.CharField(max_length=50)),
('is_active', models.BooleanField(default=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('role', models.CharField(choices=[('admin', 'Admin'), ('teacher', 'Teacher'), ('tourist', 'Tourist'), ('user', 'User')], default='user', max_length=50)),
('description', models.CharField(max_length=50, null=True)),
('is_active', models.BooleanField(default=True)),
('accounts', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.account')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='RoleAuthLink',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('auth_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.auth')),
('role_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.role')),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='auth',
name='roles',
field=models.ManyToManyField(through='account.RoleAuthLink', to='account.Role'),
),
]

@ -1,3 +1,86 @@
import uuid
from django.db import models
# Create your models here.
from apps.base.models import BaseModel
# class BaseModel(models.Model):
# """基础模型 Usages: abstract class for Model """
# id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
# update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
#
# class Meta:
# abstract = True
class RoleType(models.TextChoices):
ADMIN = "admin"
TEACHER = "teacher"
TOURIST = "tourist"
USER = "user"
class AuthType(models.TextChoices):
ADMIN = "admin"
SUPERADMIN = "super admin"
COMMON = "common"
contest = "contest"
class Gender(models.IntegerChoices):
UNKNOW = 0, 'Unknown'
FEMALE = 1, 'Female'
MALE = 2, 'Male'
class Account(BaseModel):
name = models.CharField(max_length=50, unique=True)
real_name = models.CharField(max_length=50, null=True)
phone = models.CharField(max_length=11,null=True)
password = models.CharField(max_length=50)
email = models.CharField(max_length=100, unique=True, null=True)
gender = models.IntegerField(choices=Gender.choices, default=Gender.UNKNOW)
avatar_url = models.CharField(max_length=255,null=True)
signature = models.CharField(max_length=255, null=True )
title_name = models.CharField(max_length=50, null=True)
is_active = models.BooleanField(default=True)
# 一个账户有一个角色,one to many
# role_id = models.ForeignKey("Role", related_name="accounts", on_delete=models.CASCADE)
def verify_password(self, password: str) -> bool:
return self.password == password
class Role(BaseModel):
role = models.CharField(choices=RoleType.choices, max_length=50, default=RoleType.USER)
description = models.CharField(max_length=50, null=True)
is_active = models.BooleanField(default=True)
# 一个角色有多个用户
accounts = models.ForeignKey(Account, on_delete=models.CASCADE)
# 一个角色有多个权限,一个权限有多个角色
# auths = models.ManyToManyField("Auth", related_name="roles")
class Auth(BaseModel):
type = models.CharField(choices=AuthType.choices, max_length=50, default=AuthType.COMMON)
permission = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
# 一个角色有多个权限,一个权限有多个角色
roles = models.ManyToManyField(Role, through="RoleAuthLink")
#
# class AccountRoleLink(BaseModel):
# account_id = models.ForeignKey(
# Account, on_delete=models.CASCADE)
# role_id = models.ForeignKey(
# Role, on_delete=models.CASCADE)
class RoleAuthLink(BaseModel):
auth_id = models.ForeignKey(
Auth, on_delete=models.CASCADE)
role_id = models.ForeignKey(
Role, on_delete=models.CASCADE)

@ -7,6 +7,19 @@
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet" href="{% static 'css/style1.css' %}">
<style>
.show-password-icon {
position: absolute;
top: 36%;
right: 10px;
transform: translateY(-50%);
width: 24px;
height: 24px;
background-image: {% static 'img/hide-password-icon.png' %};
background-size: cover;
cursor: pointer;
}
</style>
</head>
<body>
<section>
@ -16,10 +29,10 @@
<img src="{% static 'img/moon.png' %}" class="moon"/>
</div>
<div class="layer" data-depth-x="0.15">
<img src="{% static 'img/mountains01.png' %}"/>
<img src="{% static 'img/mountains02.png' %}"/>
</div>
<div class="layer" data-depth-x="0.25">
<img src="{% static 'img/mountains02.png' %}"/>
<img src="{% static 'img/mountains01.png' %}"/>
</div>
<div class="layer" data-depth-x="-0.25"><img src="{% static 'img/road.png' %}"/></div>
</div>
@ -29,9 +42,10 @@
<div class="container_form container--signup">
<form action="#" class="form" id="form1">
<h2 class="form_title">注册</h2>
<input type="text" style = "border: 3px solid #708090" placeholder="用户名" class="input"/>
<input type="email" style = "border: 3px solid #708090" placeholder="手机号" class="input"/>
<input type="password" style = "border: 3px solid #708090" placeholder="密码" class="input"/>
<input type="text" placeholder="用户名" class="input"/>
<input type="email" placeholder="手机号" class="input"/>
<input type="password" placeholder="密码" class="input"/>
<span class="show-password-icon"></span>
<button class="btn">注册</button>
</form>
</div>
@ -39,12 +53,14 @@
<div class="container_form container--signin">
<form action="#" class="form" id="form2">
<h2 class="form_title">登录</h2>
<input type="email" style="border: 3px solid #708090" placeholder="用户名" class="input"/>
<input type="password" style="border: 3px solid #708090" placeholder="密码" class="input"/>
<input type="email" placeholder="手机号" class="input"/>
<input type="password" placeholder="密码" class="input"/>
<span class="show-password-icon"></span>
<a href="#" class="link">忘记密码?</a>
<button class="btn">登录</button>
</form>
</div>
<!-- 浮层 -->
<div class="container_overlay">
<div class="overlay">
@ -58,10 +74,38 @@
</div>
</div>
</section>
<script src="{% static 'js/parallax.js' %}"></script>
<script>
var scene = document.getElementById("scene");
var parallax = new Parallax(scene);
const passwordInput = document.getElementById("password");
const showPasswordIcon = document.querySelector(".show-password-icon");
showPasswordIcon.addEventListener("click", function () {
if (passwordInput.type === "password") {
passwordInput.type = "text";
showPasswordIcon.style.backgroundImage = "url({% static 'img/show-password-icon.png' %})";
} else {
passwordInput.type = "password";
showPasswordIcon.style.backgroundImage = "url({% static 'img/hide-password-icon.png' %})";
}
});
// 添加表单提交事件
document.querySelector('form').addEventListener('submit', function (e) {
e.preventDefault(); // 阻止默认的表单提交行为
// 获取表单中的用户名和密码
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
// 在此处编写验证逻辑,此处为示例代码
if (username === '' || password === '') {
alert('请输入用户名和密码');
} else {
alert('登录成功');
}
});
</script>
<script src="{% static 'js/script.js' %}"></script>
</body>

@ -0,0 +1,10 @@
from django.urls import path
from . import views
app_name = 'account'
urlpatterns = [
path('login', views.login, name='login'),
path('login/submit', views.submit, name='submit'),
]

@ -1,5 +1,26 @@
from django.http import HttpResponse
from django.shortcuts import render
from apps.account.models import Account
# Create your views here.
def login(request):
#
return render(request, "login1.html")
def submit(request):
if request.method == 'POST':
# 从前端数据中拿去表中字段
user_name = request.POST.get('email')
user_password = request.POST.get('password')
# user_password_confirm = request.POST.get('user_password_confirm')
# 根据用户名查询数据库,并获得用户
user_obj = Account.objects.filter(user_name=user_name).first()
if user_obj.user_name == user_name and user_obj.user_password == user_password and user_obj.user_password_confirm == user_password_confirm:
return HttpResponse("登录成功")
else:
return HttpResponse("登录失败")
else:
return HttpResponse("登录失败")

@ -0,0 +1,13 @@
import uuid
from django.db import models
class BaseModel(models.Model):
"""基础模型 Usages: abstract class for Model """
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
class Meta:
abstract = True

@ -1,3 +1,13 @@
import uuid
from django.db import models
# Create your models here.
class BaseModel(models.Model):
"""基础模型 Usages: abstract class for Model """
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
class Meta:
abstract = True

@ -40,7 +40,7 @@
<button type="submit" class="btn btn-default">Submit</button>
</form> <!-- 表单提交 -->
<ul class="nav navbar-nav navbar-right">
<li><a href="/login">登录/注册</a></li> <!-- 登录选项 -->
<li><a href="/account/login">登录/注册</a></li> <!-- 登录选项 -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false"> Dropdown <span class="caret"></span></a>

@ -0,0 +1 @@
#测试

@ -14,14 +14,14 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from apps import account, base
from apps.account import apps, views
from apps.base import apps, views
urlpatterns = [
# path('admin/', admin.site.urls),
path('admin/', admin.site.urls),
path('xxm/', base.views.index),
path('login/', account.views.login),
path('account/',include('apps.account.urls')),
]

Loading…
Cancel
Save