-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
v_dufyang
committed
Mar 29, 2020
1 parent
b26b103
commit 8e596b9
Showing
5 changed files
with
220 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,49 @@ | ||
# -*- coding: utf8 -*- | ||
|
||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, PasswordField, SubmitField | ||
from wtforms.validators import DataRequired, ValidationError | ||
from app.models import Admin # 导入数据库管理员表的那个类 | ||
import sys | ||
reload(sys) | ||
sys.setdefaultencoding('utf8') | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
"""管理员登录表单""" | ||
account = StringField( | ||
label="账号", | ||
validators=[ | ||
DataRequired("请输入账号!") | ||
], | ||
description="账号", | ||
render_kw={ | ||
"class": "form-control", | ||
"placeholder": "请输入账号!", | ||
# "required": "required" | ||
} | ||
) | ||
pwd = PasswordField( | ||
label="密码", | ||
validators=[ | ||
DataRequired("请输入密码!") | ||
], | ||
description="密码", | ||
render_kw={ | ||
"class": "form-control", | ||
"placeholder": "请输入密码!", | ||
# "required": "required" | ||
} | ||
) | ||
submit = SubmitField( | ||
'登录', | ||
render_kw={ | ||
"class": "btn btn-primary btn-block btn-flat", | ||
} | ||
) | ||
|
||
def validate_account(self, field): | ||
account = field.data | ||
admin = Admin.query.filter_by(name=account).count() | ||
if admin == 0: | ||
raise ValidationError("账号不存在!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,13 @@ | |
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from datetime import datetime | ||
from app import db | ||
|
||
|
||
app = Flask(__name__) | ||
# 连接数据库 | ||
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:[email protected]:30006/movie" | ||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True | ||
|
||
db = SQLAlchemy(app) | ||
# app = Flask(__name__) | ||
# # 连接数据库 | ||
# app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:[email protected]:3306/movie" | ||
# app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True | ||
# db = SQLAlchemy(app) | ||
|
||
|
||
# 定义数据库表 | ||
|
@@ -26,9 +25,9 @@ class User(db.Model): | |
face = db.Column(db.String(255), unique=True) | ||
addtim = db.Column(db.DateTime, index=True, default=datetime.now()) | ||
uuid = db.Column(db.String(255), unique=True) | ||
userlogs = db.relationship('Userlog', backerf='user') # 会员日志外键关系 | ||
comments = db.relationship('Comment', backerf='user') # 评论外键关系 | ||
moviecols = db.relationship('Moviecol', backerf='user') # 评论外键关系 | ||
userlogs = db.relationship('Userlog', backref='user') # 会员日志外键关系 | ||
comments = db.relationship('Comment', backref='user') # 评论外键关系 | ||
moviecols = db.relationship('Moviecol', backref='user') # 评论外键关系 | ||
|
||
def __repr__(self): | ||
return "<User %r>" % self.name | ||
|
@@ -74,8 +73,8 @@ class Movie(db.Model): | |
release_time = db.Column(db.Date) # 上映时间 | ||
length = db.Column(db.String(100)) # 播放时间 | ||
addtime = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 | ||
comments = db.relationship('Comment', backerf='movie') # 评论外键关系 | ||
moviecols = db.relationship('Moviecol', backerf='movie') # 电影收藏外键关系 | ||
comments = db.relationship('Comment', backref='movie') # 评论外键关系 | ||
moviecols = db.relationship('Moviecol', backref='movie') # 电影收藏外键关系 | ||
|
||
def __repr__(self): | ||
return "<Movie %r>" % self.title | ||
|
@@ -137,7 +136,7 @@ class Role(db.Model): | |
name = db.Column(db.String(100), unique=True) # 名称 | ||
auths = db.Column(db.String(600)) # 角色 | ||
addtime = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 | ||
admins = db.relationship('Admin', backerf='role') # 管理员外键关系 | ||
admins = db.relationship('Admin', backref='role') # 管理员外键关系 | ||
|
||
def __repr__(self): | ||
return "<Role %r>" % self.name | ||
|
@@ -152,12 +151,16 @@ class Admin(db.Model): | |
is_super = db.Column(db.SmallInteger) # 是否为超级管理员 0为超级管理员 | ||
role_id = db.Column(db.Integer, db.ForeignKey('role.id')) # 所属角色 | ||
addtime = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 | ||
Adminlogs = db.relationship('Adminlog', backerf='admin') # 管理员登陆日志外键关系 | ||
oplogs = db.relationship('Oplog', backerf='admin') # 管理员登陆日志外键关系 | ||
Adminlogs = db.relationship('Adminlog', backref='admin') # 管理员登陆日志外键关系 | ||
oplogs = db.relationship('Oplog', backref='admin') # 管理员登陆日志外键关系 | ||
|
||
def __repr__(self): | ||
return "<Admin %r>" % self.name | ||
|
||
def check_pwd(self, pwd): | ||
from werkzeug.security import check_password_hash | ||
return check_password_hash(self.pwd, pwd) | ||
|
||
|
||
# 管理员登陆日志 | ||
class Adminlog(db.Model): | ||
|
@@ -191,7 +194,7 @@ def __repr__(self): | |
# 2.插入数据 | ||
# 这里插入一条角色的数据 | ||
""" | ||
role = Role( | ||
role = Role( | ||
name="超级管理员", | ||
auths="0") | ||
db.session.add(role) | ||
|
@@ -202,7 +205,7 @@ def __repr__(self): | |
from werkzeug.security import generate_password_hash # 导入生成密码的工具 | ||
|
||
admin = Admin( | ||
namr="admin", | ||
name="admin", | ||
pwd=generate_password_hash("123456"), | ||
is_super=0, | ||
role_id=1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters