一百零六:CMS系统之修改邮箱功能完成
这里采用把验证码放到memcached中,所以封装一个memcached的操作
import memcache cache = memcache.Client(['127.0.0.1:11211'], debug=True) def set(key, value, timeout=60):
return cache.set(key, value, timeout) def get(key):
return cache.get(key) def delete(key):
return cache.delete(key)
form验证
from wtforms import StringField, IntegerField
from wtforms.validators import Email, InputRequired, Length, EqualTo, ValidationError
from flask import g from ..forms import BaseForm
from utils import cmscache class ResetEmailForm(BaseForm):
email = StringField(validators=[InputRequired(message='请输入邮箱'), Email(message='邮箱格式错误')])
captcha = StringField(validators=[Length(6, 6, message='验证码长度错误')]) def validate_email(self, field):
if field.data == g.cms_user.email:
raise ValidationError('要修改的邮箱为当前使用的邮箱') def validate_captcha(self, field):
captcha = field.data
email = self.email.data
captcha_cache = cmscache.get(email)
if not captcha_cache or captcha.lower() != captcha_cache.lower():
raise ValidationError('邮箱验证码错误')
js
$(function () {
$('#submit').click(function (event) {
event.preventDefault();
var emailElement = $('input[name="email"]');
var captchaElement = $('input[name="captcha"]'); var email = emailElement.val();
var captcha = captchaElement.val();
http.post({
'url': '/cms/resetemail/',
'data': {
'email': email,
'captcha': captcha
},
'success': function (data) {
if(data['code'] == 200){
xtalert.alertSuccessToast('修改邮箱成功');
emailElement.val('');
captchaElement.val('');
}else{
xtalert.alertInfo(data['message']);
}
},
'fail': function (error) {
xtalert.alertNetworkError();
}
})
});
});
视图
class ResetEmailView(views.MethodView):
decorators = [login_required] def get(self):
return render_template('cms/cms_resetemail.html') def post(self):
form = ResetEmailForm(request.form)
if form.validate():
g.cms_user.email = form.email.data
db.session.commit()
return restful.success()
else:
return restful.params_error(form.get_error())
一百零六:CMS系统之修改邮箱功能完成的更多相关文章
- 一百零四:CMS系统之修改邮箱界面
在base.css中加一个全局的css控制宽度 .form-container{ width: 300px;} 视图 class ResetEmailView(views.MethodView): d ...
- 一百:CMS系统之修改密码逻辑
定义一个基类form,用于获取错误信息 from wtforms import Form class BaseForm(Form): def get_error(self): # a = {'aaa' ...
- Java开发笔记(一百零六)Fork+Join框架实现分而治之
前面依次介绍了普通线程池和定时器线程池的用法,这两种线程池有个共同点,就是线程池的内部线程之间并无什么关联,然而某些情况下的各线程间存在着前因后果关系.譬如人口普查工作,大家都知道我国总人口为14亿左 ...
- 测开之路一百零六:bootstrap布局
可以在html的head里面加一些说明 <meta http-equiv="X-UA-Compatible" content="IE=edge">& ...
- 一百零六、SAP的OOP面向对象编程,OO-ALV的简介
面向对象编程,如图 基本概念: 1.对象(Object)是一个现实实体的抽象.一个对象可被认为是一个把数据(属性)和程序(方法)封装在一起的实体,这个程序产生该对象的动作或对它接受到的外界信号的反应. ...
- salesforce零基础学习(一百零六)Dynamic Form
本篇参考:https://trailblazer.salesforce.com/ideaview?id=08730000000BroxAAC https://help.salesforce.com/s ...
- 34、Flask实战第34天:修改邮箱
修改邮箱页面布局 新建cms/cms_resetemail.html {% extends 'cms/cms_base.html' %} {% block title %}修改邮箱-CMS管理系统{% ...
- CMS系统简介(从简介到使用)
CMS系统简介 1.简介 CMS是Content Management System的缩写,意为"内容管理系统". 在中国互联网的发展历程中,一直以来默默地为中国站长提供动力的CM ...
- JAVAEE——宜立方商城05:前台系统搭建、首页展示、Cms系统的实现
1. 学习计划 1.前台系统搭建 2.商城首页展示 3.Cms系统的实现 a) 内容分类管理 b) 内容管理 4.前台内容动态展示 2. 商城首页展示 系统架构: 页面位置: 2.1. 工程搭建 可以 ...
随机推荐
- linux安装vsftpd后无法登陆
安装完成后在主机上登陆时,不管是输入用户,还是匿名都无法登陆 经过检查,发现是因为/etc/hosts.deny禁止了所有ip访问 将hosts.deny中的all:all删除,或者在/etc/hos ...
- Swagger保姆级教学
Swagger保姆级教学 Swagger 简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样 ...
- tsung报告中Transactions Statistics缺失问题
长时间没有做性能测试,最近在使用tsung进行性能测试时,修改tsung自带的范例脚本后,运行查看结果时,发现测试报告中transactions statistics缺失,刚开始一直以为是监控中的配 ...
- 开发中少不了的Fun -- js判断设备
判断是否是移动设备 var ua = window.navigator.userAgent.toLowerCase(); if(ua.indexOf('mobile')!== -1){ return ...
- Bootstrap-Bootstrap官网卡片响应式布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- 【Wince-禁止重复启动程序】Wince 不重复启动程序
创建类Mutex.cs: using System; using System.Linq; using System.Collections.Generic; using System.Text; u ...
- playbook 实例
vim ~/.vimrc autocmd FileType yaml setlocal sw=2 ts=2 et ai 变量使用及错误处理 --- - hosts: db remote_user: r ...
- end()
end() V1.0概述 回到最近的一个"破坏性"操作之前.即,将匹配的元素列表变为前一次的状态. 如果之前没有破坏性操作,则返回一个空集.所谓的"破坏性"就是 ...
- codeforces555E
Case of Computer Network CodeForces - 555E Andrewid the Android is a galaxy-known detective. Now he ...