\n\u5bfc\u8bfb<\/td>\n | flask\u662fpython web\u5f00\u53d1\u7684\u5e38\u7528\u6846\u67b6\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u8bb2\u8ff0flask\u5982\u4f55\u5b9e\u73b0\u4fee\u6539\u5bc6\u7801\u548c\u514d\u5bc6\u767b\u5f55\u529f\u80fd<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u4fee\u6539\u5bc6\u7801\u529f\u80fd<\/strong><\/div>\n\u6570\u636e\u5e93\u90e8\u5206\uff1a<\/strong><\/span><\/div>\n\r\n#\u91cd\u7f6e\u5bc6\u7801\r\ndef reset_pass(phone,password):\r\n conn,cursor=get_conn()\r\n sql=\"update userdata set userpass='\"+password+\"' where userphone='\"+phone+\"'\"\r\n try:\r\n print(\"\u6b63\u5728\u4fee\u6539\u5bc6\u7801...\")\r\n resetflag=cursor.execute(sql)\r\n conn.commit()\r\n close_conn(conn,cursor)\r\n if(resetflag==1):\r\n print(\"\u4fee\u6539\u6210\u529f\")\r\n return 1\r\n else:\r\n print(\"\u4fee\u6539\u5931\u8d25\uff01\")\r\n return 0\r\n except:\r\n print(\"\u7cfb\u7edf\u9519\u8bef...\u4fee\u6539\u5bc6\u7801\u5931\u8d25\uff01\")\r\n return 0\r\n<\/pre>\n\u8def\u7531\u90e8\u5206\uff1a<\/strong><\/span><\/div>\n\r\n#\u7528\u6237\u4fee\u6539\u5bc6\u7801\r\n@app.route('\/resetpass',methods=['GET', 'POST'])\r\ndef resetpass():\r\n userphone=request.values.get('userphone')\r\n resetpass=request.values.get('resetpass')\r\n print(\"\u8def\u7531\u83b7\u5f97\u624b\u673a\u53f7\uff1a\"+userphone+\"\\n\")\r\n print(\"\u8def\u7531\u83b7\u5f97\u65b0\u5bc6\u7801\uff1a\" + resetpass + \"\\n\")\r\n flag=sql.reset_pass(userphone,resetpass)\r\n if(flag==1):\r\n return jsonify({\"data\":1})\r\n else:\r\n return jsonify({\"data\":0})\r\n<\/pre>\nhtml\u9875\u9762\uff1a<\/strong><\/span><\/div>\n\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\r\n <title>\u6811\u61d2\u7535\u5f71---\u91cd\u7f6e\u60a8\u7684\u5bc6\u7801<\/title>\r\n <style type=\"text\/css\">\r\n #resetform{\r\n margin-top: 350px;\r\n margin-left: 750px;\r\n }\r\n <\/style>\r\n<\/head>\r\n<body>\r\n <form method=\"post\" id=\"resetform\">\r\n <tr>\r\n <td><input type=\"text\" id=\"userphone\" value=\"\" placeholder=\"\u8f93\u5165\u60a8\u7684\u624b\u673a\u53f7\u7801\"><\/td>\r\n <\/tr><br>\r\n <tr>\r\n <td><input type=\"password\" id=\"resetpass1\" value=\"\" placeholder=\"\u8f93\u5165\u60a8\u7684\u65b0\u5bc6\u7801\"><\/td>\r\n <\/tr><br>\r\n <tr>\r\n <td><input type=\"password\" id=\"resetpass2\" value=\"\" placeholder=\"\u518d\u6b21\u8f93\u5165\u60a8\u7684\u65b0\u5bc6\u7801\"><\/td>\r\n <\/tr><br>\r\n <tr>\r\n <td><input type=\"reset\" value=\"\u6e05\u7a7a\"><\/td>\r\n <td><input type=\"button\" id=\"resetbtn\" onclick=\"resetpass()\" value=\"\u63d0\u4ea4\"><\/td>\r\n <\/tr>\r\n <\/form>\r\n<\/body>\r\n<\/html>\r\n<script src=\"..\/static\/js\/jquery.min.js\"><\/script>\r\n<script type=\"text\/javascript\">\r\n function resetpass(){\r\n var userphone=document.getElementById(\"userphone\").value\r\n var resetpass1=document.getElementById(\"resetpass1\").value\r\n var resetpass2=document.getElementById(\"resetpass2\").value\r\n var submit_flag=1\r\n \/\/\u5224\u7a7a\r\n if((userphone.length==0)||(resetpass1.length==0)||(resetpass2.length==0)){\r\n submit_flag=0\r\n alert(\"\u8bf7\u628a\u4fe1\u606f\u586b\u5199\u5b8c\u6574\uff01\")\r\n }\r\n \/\/\u5224\u65ad\u5bc6\u7801\u4e00\u81f4\u6027\r\n if(resetpass2!=resetpass1){\r\n submit_flag=0\r\n alert(\"\u4e24\u6b21\u586b\u5199\u7684\u5bc6\u7801\u4e0d\u4e00\u81f4\")\r\n document.getElementById(\"resetpass1\").focus();\r\n }\r\n \/\/\u5224\u65ad\u624b\u673a\u53f7\r\n if(userphone.length!=11){\r\n submit_flag=0\r\n alert(\"\u624b\u673a\u53f7\u7801\u5e94\u4e3a11\u4f4d\uff01\")\r\n document.getElementById(\"userphone\").focus();\r\n }\r\n var regu = \/^1[3456789]\\d{9}$\/\r\n if(!(regu.test(userphone)) ){\r\n submit_flag=0\r\n alert(\"\u624b\u673a\u53f7\u7801\u683c\u5f0f\u6709\u8bef\uff01\")\r\n document.getElementById(\"userphone\").focus();\r\n }\r\n \/\/\u5224\u65ad\u5bc6\u7801\u683c\u5f0f\r\n if(!((resetpass1.length>=6)&&resetpass1.length<=18))\r\n {\r\n submit_flag=0\r\n alert(\"\u5bc6\u7801\u957f\u5ea6\u5e94\u8be5\u4e3a6-16\u4f4d!\")\r\n document.getElementById(\"resetpass1\").focus();\r\n }\r\n var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{6,18}');\r\n part_pass=resetpass1.split(\" \")\r\n if((!(regex.test(resetpass1))) || part_pass.length!=1)\r\n {\r\n submit_flag=0\r\n alert(\"\u5bc6\u7801\u4e3a\u6570\u5b57+\u82f1\u6587\u5b57\u6bcd \u4e14\u4e0d\u53ef\u4ee5\u5305\u542b\u7a7a\u683c\uff01\")\r\n document.getElementById(\"resetpass1\").focus();\r\n }\r\n\r\n \/\/\u53d1\u8d77\u8bf7\u6c42\r\n if(submit_flag==1)\r\n {\r\n $.ajax({\r\n url:\"\/resetpass\",\r\n data:{userphone:userphone,resetpass:resetpass2},\r\n success: function (data) {\r\n if (data.data==1)\r\n {\r\n alert(\"\u5bc6\u7801\u4fee\u6539\u6210\u529f\uff01\")\r\n window.open(\"\/\",'_self')\r\n }\r\n else\r\n {\r\n alert(\"\u4fee\u6539\u5bc6\u7801\u5931\u8d25\uff01\u8bf7\u91cd\u8bd5\")\r\n }\r\n },\r\n error: function (xhr, type, errorThrown) {\r\n \/\/ print(\"ajax\u8bf7\u6c42\u5931\u8d25\uff01\")\r\n }\r\n })\r\n }\r\n \/\/ alert(submit_flag)\r\n }\r\n<\/script>\r\n<\/pre>\n\u514d\u5bc6\u767b\u5f55<\/strong><\/div>\nhtml\u4ee3\u7801\uff1a<\/strong><\/span><\/div>\n\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\r\n <link rel=\"stylesheet\" href=\"..\/static\/css\/login.css\" rel=\"external nofollow\" >\r\n <script src=\"..\/static\/js\/jquery-1.7.2.min.js\"><\/script>\r\n <script src=\"..\/static\/js\/register.js\"><\/script>\r\n <title>\u6811\u61d2\u7535\u5f71\u767b\u5f55<\/title>\r\n <script >\r\n <\/script>\r\n<\/head>\r\n<body>\r\n <div id=\"container\">\r\n <div id=\"container-child\">\r\n <div id=\"img-div\"><img src=\"..\/static\/img\/shulan.png\"><\/div>\r\n <div id=\"login-div\">\r\n <div>\r\n <p class=\"p-title\">\u767b\u5f55\u60a8\u7684\u6811\u61d2\u7535\u5f71<\/p>\r\n <form id=\"login-form\" method=\"post\">\r\n <div class=\"input-d\">\r\n <input class=\"input-text\" type=\"text\" name=\"userphone\" id=\"userphone\" placeholder=\"\u8bf7\u8f93\u5165\u60a8\u7684\u8d26\u53f7\">\r\n <\/div>\r\n <div class=\"input-d\">\r\n <input class=\"input-text\" type=\"password\" name=\"password\" id=\"password\" placeholder=\"\u8bf7\u8f93\u5165\u60a8\u7684\u5bc6\u7801\">\r\n <\/div>\r\n <div class=\"div-input\">\r\n <div>\r\n <input type=\"checkbox\" value=\u201c1\u201d class=\u201cremeber\u201d onclick=\"onClickHander(this)\">\r\n <label>\u8bb0\u4f4f\u5bc6\u7801<\/label>\r\n <\/div>\r\n <\/div>\r\n <button type=\"button\" class=\"login-button\" onclick=\"login_()\">\u767b\u2003\u5f55<\/button>\r\n <div class=\"footer\"> <a href=\"http:\/\/127.0.0.1:5000\/regis\" rel=\"external nofollow\" >\u6ce8\u518c<\/a> | <a href=\"http:\/\/127.0.0.1:5000\/reset\" rel=\"external nofollow\" >\u5fd8\u8bb0\u5bc6\u7801<\/a><\/div>\r\n <\/form>\r\n <\/div>\r\n <\/div>\r\n <\/div>\r\n <\/div>\r\n<\/body>\r\n<\/html>\r\n<script>\r\n var cb=0\r\n function onClickHander(obj) {\r\n if(obj.checked==true){\r\n cb=1\r\n \/\/ alert(cb)\r\n }else{\r\n cb=0\r\n \/\/ alert(cb)\r\n }\r\n }\r\n function login_(){\r\n var userphone=document.getElementById(\"userphone\").value\r\n var password=document.getElementById(\"password\").value\r\n \/\/ alert(cb)\r\n $.ajax({\r\n url: \"\/web_login\",\r\n data: {\r\n userphone:userphone,password:password,cb:cb\r\n },\r\n success: function (data) {\r\n \/\/\u6b63\u5e38\u9a8c\u8bc1\u5931\u8d25\u5f39\u7a97\r\n if (data.data == 0)\r\n alert(\"\u8d26\u53f7\u6216\u5bc6\u7801\u9519\u8bef\uff01\")\r\n \/\/\u9a8c\u8bc1\u6210\u529f\uff0c\u8fd4\u56deresponse\r\n if (data.data != 0)\r\n window.open(\"http:\/\/127.0.0.1:5000\/show\",\"_self\")\r\n },\r\n error: function (xhr, type, errorThrown) {\r\n print(\"\u767b\u5f55js\uff0c\u9a8c\u8bc1\u8d26\u53f7\u5bc6\u7801ajax\u8bf7\u6c42\u5931\u8d25\uff01\")\r\n }\r\n })\r\n }\r\n<\/script>\r\n<\/pre>\nPython\u8def\u7531<\/strong><\/span><\/div>\n\r\n#\u514d\u5bc6\u767b\u5f55\r\n@app.route('\/web_login\/',methods=['GET', 'POST'])\r\ndef web_login():\r\n userphone = request.values.get('userphone')\r\n password=request.values.get('password')\r\n cb=request.values.get('cb')\r\n print(\"\u662f\u5426\u8bb0\u4f4f\u5bc6\u7801\uff1a \"+cb) #cb\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u662f str \u5b57\u7b26\u4e32\r\n # print(type(cb))\r\n print(\"\u767b\u5f55\u8d26\u53f7\uff1a\"+userphone+\" \"+\"\u5bc6\u7801\uff1a\"+password)\r\n res=sql.web_login(userphone,password)\r\n if(res==True):\r\n session['userphone'] = userphone\r\n if(cb==\"1\"):\r\n print(\"\u5f00\u59cb\u5b58\u50a8cookie\u767b\u5f55\u8d26\u53f7\uff1a\" + userphone + \" \" + \"\u5bc6\u7801\uff1a\" + password)\r\n resp = make_response('\u50a8\u5b58cookie')\r\n resp.set_cookie('cookphone', userphone, max_age=3600 * 24 * 15)\r\n resp.set_cookie('cookpass', password, max_age=3600 * 24 * 15)\r\n print(\"\u767b\u5f55\u6210\u529f\u4e14\u7528\u6237\u9009\u62e9\u8bb0\u4f4f\u5bc6\u7801\uff0c\u8fd4\u56deresponse\")\r\n return resp #\u767b\u5f55\u6210\u529f\u4e14\u7528\u6237\u9009\u62e9\u8bb0\u4f4f\u5bc6\u7801\uff0c\u8fd4\u56deresponse\r\n else:\r\n print(\"\u767b\u5f55\u6210\u529f \u8fd4\u56de 1 \u72b6\u6001\u7801\")\r\n return jsonify({\"data\": 1}) # \u767b\u5f55\u6210\u529f \u8fd4\u56de 1 \u72b6\u6001\u7801\r\n else:\r\n print(\"\u767b\u5f55\u5931\u8d25 \u8fd4\u56de 0 \u72b6\u6001\u7801\")\r\n return jsonify({\"data\":0}) #\u767b\u5f55\u5931\u8d25 \u8fd4\u56de 0 \u72b6\u6001\u7801\r\n<\/pre>\n\u6570\u636e\u5e93\u9a8c\u8bc1\u767b\u5f55<\/strong><\/span><\/div>\n\r\n# \u7528\u6237\uff08web\uff09\u767b\u5f55\u9a8c\u8bc1\r\ndef web_login(userphone, password):\r\n cursor = None\r\n conn = None\r\n res=[]\r\n if(userphone==None or password==None):\r\n return False\r\n conn, cursor = get_conn()\r\n sql = \"select userphone,userpass from userdata where '\"+userphone+\"'=userphone and '\"+password+\"'=userpass \"\r\n res=query(sql)\r\n conn.commit()\r\n if(len(res)==0):\r\n print(\"\u767b\u9646\u5931\u8d25\uff08WEB\uff09\")\r\n close_conn(conn, cursor)\r\n return False\r\n else:\r\n close_conn(conn, cursor)\r\n print(\"\u767b\u9646\u6210\u529f\uff08WEB\uff09\")\r\n return True\r\n<\/pre>\n\u4ee5\u4e0a\u5c31\u662fflask\u6846\u67b6\u5b9e\u73b0\u4fee\u6539\u5bc6\u7801\u548c\u514d\u5bc6\u767b\u5f55\u529f\u80fd\u7684\u8be6\u7ec6\u5185\u5bb9<\/p>\n","protected":false},"excerpt":{"rendered":" #\u91cd\u7f6e\u5bc6\u7801 def reset_pass(phone,password): conn,cursor=get_c […]<\/p>\n","protected":false},"author":668,"featured_media":153228,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-221425","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=221425"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221425\/revisions"}],"predecessor-version":[{"id":221436,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221425\/revisions\/221436"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/153228"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=221425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=221425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=221425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} |