B站配套视频教程观看
打開/web/js/
創建account
文件夾添加set.js
文件
基於edit.js創建set.js
修改set.js符合页面就可以
; var account_set_ops = { init:function () { this.eventBind(); }, eventBind:function () { $(".wrap_account_set .save").click( function () { var btn_target = $(this); if (btn_target.hasClass("disabled")){ common_ops.alert("正在处理,请不要重复提交") return; } var nickname_target = $(".wrap_account_set input[name=nickname]"); var nickname = nickname_target.val(); var mobile_target = $(".wrap_account_set input[name=mobile]"); var mobile = mobile_target.val(); var email_target = $(".wrap_account_set input[name=email]"); var email = email_target.val(); var login_name_target = $(".wrap_account_set input[name=login_name]"); var login_name = login_name_target.val(); var login_pwd_target = $(".wrap_account_set input[name=login_pwd]"); var login_pwd = login_pwd_target.val(); if (nickname.length<1){ common_ops.tip("请输入符合规范的姓名", nickname_target); return false } if (mobile.length<1){ common_ops.tip("请输入符合规范的手机号", mobile_target); return false } if (email.length<1){ common_ops.tip("请输入符合规范的邮箱", email_target); return false } if (login_name.length<1){ common_ops.tip("请输入符合规范的登录名称", login_name_target); return false } if (login_pwd.length<6){ common_ops.tip("请输入符合规范的密码", login_pwd_target); return false } btn_target.addClass("disabled"); var data={ nickname :nickname, mobile : mobile, email : email, login_name : login_name, login_pwd : login_pwd } $.ajax({ url:common_ops.buildUrl("/account/set"), type:"POST", data:data, dataType:'json', success:function (res) { btn_target.removeClass("disabled") var callback = null; if(res.code == 200){ callback = function () { window.location.href = common_ops.buildUrl("/account/index"); } } common_ops.alert(res.msg, callback) } }) }); } } $(document).ready(function () { account_set_ops.init() })
set.html
引入js
文件
运行 成功添加:
Account.py
添加set请求的post响应
@route_account.route( "/set" ,methods = ["GET","POST"]) def set(): if request.method == "GET": return ops_render( "account/set.html" ) resp = {'code': 200, 'msg': '操作成功', 'data': {}} req = request.values nickname = req['nickname'] if 'nickname' in req else '' mobile = req['mobile'] if 'mobile' in req else '' email = req['email'] if 'email' in req else '' login_name = req['login_name'] if 'login_name' in req else '' login_pwd = req['login_pwd'] if 'login_pwd' in req else '' if nickname is None or len(nickname)<1: resp['code']=-1 resp['msg']='请输入符合规范的姓名' return jsonify(resp) if mobile is None or len(mobile)<1: resp['code']=-1 resp['msg']='请输入符合规范的手机' return jsonify(resp) if email is None or len(email)<1: resp['code']=-1 resp['msg']='请输入符合规范的邮箱' return jsonify(resp) if login_name is None or len(login_name)<1: resp['code']=-1 resp['msg']='请输入符合规范的登录名' return jsonify(resp) if login_pwd is None or len(login_pwd)<1: resp['code']=-1 resp['msg']='请输入符合规范的登录密码' return jsonify(resp) has_in = User.query.filter(User.login_name == login_name).first() if has_in: resp['code']=-1 resp['msg']='登录名已存在,更换后再试' return jsonify(resp) model_user = User() model_user.nickname = nickname model_user.mobile = mobile model_user.email = email model_user.login_name = login_name model_user.login_salt = UserService.geneSalt() model_user.login_pwd = UserService.genePwd(login_pwd, model_user.login_salt ) model_user.update_time = getCurrentDate() model_user.created_time = getCurrentDate() db.session.add(model_user) db.session.commit() return jsonify(resp)
Helper.py添加获取当前时间接口:
import datetime ''' 获取当前时间 ''' def getCurrentDate(format = "%Y-%m-%d %H:%M:%S"): return datetime.datetime.now().strftime(format)
libs/user/Userservice.py加盐方法:
import hashlib, base64,random,string @staticmethod def geneSalt(length=16): keylist = [random.choices((string.ascii_letters+string.digits)) for i in range(length)] return ("".join(keylist))