百木园-与人分享,
就是让自己快乐。

Python---flask框架实现免密登录功能

思路总结:

 

html代码:

1 <!DOCTYPE html>
2 <html lang=\"en\">
3 <head>
4 <meta charset=\"UTF-8\">
5 <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
6 <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">
7 <link rel=\"stylesheet\" href=\"../static/css/login.css\">
8 <script src=\"../static/js/jquery-1.7.2.min.js\"></script>
9 <script src=\"../static/js/register.js\"></script>
10 <title>树懒电影登录</title>
11 <script >
12 </script>
13 </head>
14 <body>
15 <div id=\"container\">
16 <div id=\"container-child\">
17 <div id=\"img-div\"><img src=\"../static/img/shulan.png\"></div>
18 <div id=\"login-div\">
19 <div>
20 <p class=\"p-title\">登录您的树懒电影</p>
21 <form id=\"login-form\" method=\"post\">
22 <div class=\"input-d\">
23 <input class=\"input-text\" type=\"text\" name=\"userphone\" id=\"userphone\" placeholder=\"请输入您的账号\">
24 </div>
25 <div class=\"input-d\">
26 <input class=\"input-text\" type=\"password\" name=\"password\" id=\"password\" placeholder=\"请输入您的密码\">
27 </div>
28 <div class=\"div-input\">
29 <div>
30 <input type=\"checkbox\" value=“1” class=“remeber” onclick=\"onClickHander(this)\">
31 <label>记住密码</label>
32 </div>
33 </div>
34 <button type=\"button\" class=\"login-button\" onclick=\"login_()\">登&emsp;录</button>
35 <div class=\"footer\"> <a href=\"http://127.0.0.1:5000/regis\">注册</a> | <a href=\"http://127.0.0.1:5000/reset\">忘记密码</a></div>
36 </form>
37 </div>
38 </div>
39 </div>
40 </div>
41 </body>
42 </html>
43 <script>
44 var cb=0
45 function onClickHander(obj) {
46 if(obj.checked==true){
47 cb=1
48 // alert(cb)
49 }else{
50 cb=0
51 // alert(cb)
52 }
53 }
54 function login_(){
55 var userphone=document.getElementById(\"userphone\").value
56 var password=document.getElementById(\"password\").value
57 // alert(cb)
58 $.ajax({
59 url: \"/web_login\",
60 data: {
61 userphone:userphone,password:password,cb:cb
62 },
63 success: function (data) {
64 //正常验证失败弹窗
65 if (data.data == 0)
66 alert(\"账号或密码错误!\")
67 //验证成功,返回response
68 if (data.data != 0)
69 window.open(\"http://127.0.0.1:5000/show\",\"_self\")
70 },
71 error: function (xhr, type, errorThrown) {
72 print(\"登录js,验证账号密码ajax请求失败!\")
73 }
74 })
75 }
76 </script>

来源:https://www.cnblogs.com/rainbow-1/p/14800675.html
图文来源于网络,如有侵权请联系删除。

未经允许不得转载:百木园 » Python---flask框架实现免密登录功能

相关推荐

  • 暂无文章