Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Conversation

@Lyc-heng
Copy link

No description provided.

Copy link
Owner

@TheMasterOfMagic TheMasterOfMagic left a 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)
Copy link
Owner

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()
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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]就可以了,没必要用上多余的变量。

# 密码必须包含大写、小写、数字,且至少出现一次
password = PasswordField('password', validators=[DataRequired(), Length(min=8, max=32),
Regexp('^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$', 0,
"密码长度限制在3~36之间且密码不能为弱密码"),
Copy link
Owner

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)
Copy link
Owner

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))
Copy link
Owner

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'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不涉及ascii码范围以外的字符的编解码请不要显示指定编码格式。虽然这个参数默认就是utf8,但从代码角度这两种方式意义不同。建议去掉。

@Lyc-heng
Copy link
Author

1.实现了使用对称密钥加密文件的功能,对称密钥使用RSA进行了加密存储。但因为文件上传这部分代码不是我写的,之后还得再结合之前写好的代码进行整合
2.修改了之前pr提出的部分问题

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants