def login_function(): login = LoginForm() login_check = UserCheck() if request.method == 'POST': # POST if login.validate_on_submit(): # Count the User of input information user_count = User.objects( email=login.email.data.lower(), password=login_check.password_encrypt( email=login.email.data.lower(), password=login.password.data) ).count() if user_count == 1: # Login successful # Add Session this_user = User.objects( email=login.email.data, ).first() session.permanent = True session['user'] = { "username": this_user.username, "email": this_user.email, "email_md5": common.md5_encrypt(login.email.data), "status": this_user.status, "role": this_user.role, "description": this_user.description } next_page = request.args.get('next', '') if next_page == '': # Redirect to /me flash(u"欢迎回来,亲。") return redirect(url_for('sign_module.me_function')) else: # Redirect to next page return redirect(next_page) else: flash(u"用户名不存在或密码错误") return redirect(url_for('sign_module.login_function')) else: flash(u"数据提交失败,请检查输入内容") return redirect(url_for('sign_module.login_function')) return render_template('users/login.html', login=login)
def login_function(): login = LoginForm() login_check = UserCheck() if request.method == 'POST': # POST if login.validate_on_submit(): # Count the User of input information user_count = User.objects( email=login.email.data.lower(), password=login_check.password_encrypt( email=login.email.data.lower(), password=login.password.data)).count() if user_count == 1: # Login successful # Add Session this_user = User.objects(email=login.email.data, ).first() session.permanent = True session['user'] = { "username": this_user.username, "email": this_user.email, "email_md5": common.md5_encrypt(login.email.data), "status": this_user.status, "role": this_user.role, "description": this_user.description } next_page = request.args.get('next', '') if next_page == '': # Redirect to /me flash(u"欢迎回来,亲。") return redirect(url_for('sign_module.me_function')) else: # Redirect to next page return redirect(next_page) else: flash(u"用户名不存在或密码错误") return redirect(url_for('sign_module.login_function')) else: flash(u"数据提交失败,请检查输入内容") return redirect(url_for('sign_module.login_function')) return render_template('users/login.html', login=login)
def password_encrypt(self, email, password): md5_once = common.md5_encrypt(str(password) + app.config['SECRET_KEY']) md5_sec = common.md5_encrypt(md5_once + email) return md5_sec
def forgetstring_encrypt(self, email): md5_once = common.md5_encrypt( str(email) + str(random.randrange(1000000, 999999999))) md5_sec = common.md5_encrypt(md5_once + app.config['SECRET_KEY']) return md5_sec
def one_note_function(noteid): # 笔记存在性判断 if Note.objects(noteid=noteid).count() == 0: flash(u"找不到这篇文章,不要乱来了。") return redirect(url_for('note_module.note_wall_function')) # 读取该笔记 this_note = Note.objects(noteid=noteid).first() # MarkDown 渲染笔记正文 renderer = mistune.Renderer(escape=True, hard_wrap=True) markdown = mistune.Markdown(renderer=renderer) this_note.content = markdown(this_note.content) # 笔记作者邮件MD5 用于显示头像 this_note.belong.email_md5 = common.md5_encrypt(this_note.belong.email) # 笔记权限判断 if this_note.public_status == NOTECONSTANTS.PRIVATE and \ session['user']['role'] == USERCONSTANTS.USER: # 登陆 与 非登陆 跳转页面不同 if 'user' in session: if this_note.belong.email != session['user']['email']: flash(u"无权限查看他人的私有笔记。") return redirect(url_for('note_module.mynote_function')) else: flash(u"你想查看的笔记为私有笔记,无权限查看。") return redirect(url_for('note_module.note_wall_function')) # 评论功能 # 需要添加进session 保存最后一次评论的个人信息 comment = CommentForm() # POST 页面 if request.method == 'POST': # 私有笔记 权限判断 if this_note.public_status == NOTECONSTANTS.PRIVATE: flash(u"该笔记为私有笔记,无法评论。") return redirect(url_for('note_module.note_wall_function')) # 提交评论 if comment.validate_on_submit(): Comment(name=comment.name.data, email=comment.email.data.lower(), domain=comment.domain.data, content=comment.content.data, noteid=noteid,).save() return redirect(url_for('note_module.one_note_function', noteid=noteid)) else: flash(u"内容填写不完整") return redirect(url_for('note_module.one_note_function', noteid=noteid)) # 读取当前笔记的所有评论 all_comment = Comment.objects(noteid=noteid) # 评论Email添加MD5 用于头像显示 for one_comment in all_comment: one_comment.email_md5 = common.md5_encrypt(one_comment.email) return render_template('/note/one_note.html', this_note=this_note, comment=comment, all_comment=all_comment )