-
Notifications
You must be signed in to change notification settings - Fork 3
电脑重装,重新初始化仓库,在之前代码的基础上增加提交表单改用ajax实现,hash存储使用了sha512算算法 #4
base: master
Are you sure you want to change the base?
Conversation
TheMasterOfMagic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
除了缺失下载文件部分的代码以外,暂时都是一些小问题。
app.py
Outdated
| file.file_list() | ||
| pass | ||
| filelist = file.file_list() | ||
| return file.download_file(filelist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file.py里好像没有这个函数?
| from models import User | ||
| db.create_all() | ||
| db.session.merge(User(id=0,username="lycheng", email='anjing@cuc.edu.cn', password='aB8')) | ||
| db.session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几行是不是可以去掉?好像没有必要在每次启动的时候都固定添加这么一个测试用户?
file.py
Outdated
|
|
||
| ALLOWED_EXTENSIONS = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'rtf', 'txt', | ||
| 'pdf', 'png', 'bmp', 'jpg'] # 允许上传的文件格式 | ||
| ALLOWED_FILE_SIZE = 10 * 1024 * 1024 # 允许上传的文件大小MB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用常量式命名可以给个好评。如果能把这两项放进config.py里就更好了。
file.py
Outdated
| def file_list(): # 文件下载 | ||
| for parent, dirname, filenames in os.walk(upload_dir): | ||
| filelist = filenames | ||
| return filelist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果上传目录中有子目录,那么最后返回的filelist的值将是最后一个子目录的文件列表。这里显然是明确希望获取上传目录本身的文件列表的(不论是否有子目录),所以直接filelist = next(os.walk(upload_dir))[-1]就可以了,没必要用上多余的变量。
forms/signin_form.py
Outdated
| # 密码必须包含大写、小写、数字,且至少出现一次 | ||
| password = PasswordField('password', validators=[DataRequired(), Length(min=8, max=32), | ||
| Regexp('^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$', 0, | ||
| "密码长度限制在3~36之间且密码不能为弱密码"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里所用到的正则对密码长度的限制是至少8位,不是3~36位。说明与实现请保持一致。
| class User(db.Model, UserMixin): | ||
| __tablename__ = 'Users' | ||
|
|
||
| id = db.Column(db.INT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python内建关键字请尽量避免直接使用。有一种做法是在结尾加下划线,如id_,in_,class_等等,可以参考一下。
| id = db.Column(db.INT) | ||
| username = db.Column(db.String(45)) | ||
| email = db.Column(db.String(128), primary_key=True) | ||
| password = db.Column(db.String(512)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量名应体现出实际含义。如果存的是哈希值请不要使用password这样的变量名。
signinup.py
Outdated
|
|
||
| # #使用sha512进行hash | ||
| hash = hashlib.sha512() | ||
| hash.update(form.password.data.encode('utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果不涉及ascii码范围以外的字符的编解码请不要显示指定编码格式。虽然这个参数默认就是utf8,但从代码角度这两种方式意义不同。建议去掉。
|
1.实现了使用对称密钥加密文件的功能,对称密钥使用RSA进行了加密存储。但因为文件上传这部分代码不是我写的,之后还得再结合之前写好的代码进行整合 |
No description provided.