瀏覽代碼

完成注销功能

James Iter 9 年之前
父節點
當前提交
4bb45ac657
共有 6 個文件被更改,包括 32 次插入54 次删除
  1. 7 0
      api/user.py
  2. 1 0
      api_route_table.py
  3. 二進制
      static/avatar/Burung-Pelatuk_144x144.png
  4. 二進制
      static/avatar/Burung-Pelatuk_144x144@2x.png
  5. 23 33
      templates/layout.html
  6. 1 21
      views/misc.py

+ 7 - 0
api/user.py

@@ -68,3 +68,10 @@ def r_sign_in():
     except ji.PreviewingError, e:
         return json.loads(e.message)
 
+
+@Utils.dumps2response
+def r_sign_out():
+    for key in session.keys():
+        session.pop(key=key)
+
+

+ 1 - 0
api_route_table.py

@@ -30,6 +30,7 @@ add_rule_api(config.blueprint, '', api_func='config.r_get', methods=['GET'])
 
 # 用户管理
 add_rule_api(user.blueprint, '/_sign_in', api_func='user.r_sign_in', methods=['POST'])
+add_rule_api(user.blueprint, '/_sign_out', api_func='user.r_sign_out', methods=['GET'])
 
 # 系统启动作业配置操作
 add_rule_api(boot_job.blueprint, '', api_func='boot_job.r_create', methods=['POST'])

二進制
static/avatar/Burung-Pelatuk_144x144.png


二進制
static/avatar/Burung-Pelatuk_144x144@2x.png


+ 23 - 33
templates/layout.html

@@ -223,6 +223,19 @@
             }, 3000);
         }
 
+        function logout() {
+            $.ajax({
+                url: '/api/user/_sign_out',
+                type: 'GET',
+                dataType: 'json',
+                error: function () {
+                    alter_danger('注销失败!');
+                },
+                success : function(data, textStatus, xhr) {
+                    window.location.href="/";
+                }
+            })
+        }
     </script>
 
     {% endblock head %}
@@ -251,9 +264,9 @@
                 </div>
                 <div id="header-nav-left">
                     <div class="user-account-btn dropdown">
-                        <a href="#" title="My Account" class="user-profile clearfix" data-toggle="dropdown">
-                            <img width="28" src="{{ url_for('static', filename='images/icons/JimV-icon_144X144.png') }}" alt="Profile image">
-                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;James Iter</span>
+                        <a href="#" title="Admin" class="user-profile clearfix" data-toggle="dropdown">
+                            <img width="28" src="{{ url_for('static', filename='avatar/Burung-Pelatuk_144x144.png') }}" alt="Avatar">
+                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Admin</span>
                             <i class="glyph-icon icon-angle-down"></i>
                         </a>
                         <div class="dropdown-menu float-left">
@@ -261,43 +274,20 @@
                                 <div class="login-box clearfix">
                                     <div class="user-img">
                                         <a href="#" title="" class="change-img">Change photo</a>
-                                        <img src="" alt="">
+                                        <img src="{{ url_for('static', filename='avatar/Burung-Pelatuk_144x144.png') }}" alt="Avatar">
                                     </div>
                                     <div class="user-info">
                                         <span>
-                                            Thomas Barnes
-                                            <i>UX/UI developer</i>
+                                            Admin
+                                            <i>管理员</i>
                                         </span>
-                                        <a href="#" title="Edit profile">Edit profile</a>
-                                        <a href="#" title="View notifications">View notifications</a>
                                     </div>
                                 </div>
-                                <div class="divider"></div>
-                                <ul class="reset-ul mrg5B">
-                                    <li>
-                                        <a href="#">
-                                            <i class="glyph-icon float-right icon-caret-right"></i>
-                                            View login page example
-                                        </a>
-                                    </li>
-                                    <li>
-                                        <a href="#">
-                                            <i class="glyph-icon float-right icon-caret-right"></i>
-                                            View lockscreen example
-                                        </a>
-                                    </li>
-                                    <li>
-                                        <a href="#">
-                                            <i class="glyph-icon float-right icon-caret-right"></i>
-                                            View account details
-                                        </a>
-                                    </li>
-                                </ul>
                                 <div class="pad5A button-pane button-pane-alt text-center">
-                                        <a href="#" class="btn display-block font-normal btn-danger">
-                                            <i class="glyph-icon icon-power-off"></i>
-                                            Logout
-                                        </a>
+                                    <a href="#" class="btn display-block font-normal btn-danger" onclick="logout();">
+                                        <i class="glyph-icon icon-power-off"></i>
+                                        安全退出
+                                    </a>
                                 </div>
                             </div>
                         </div>

+ 1 - 21
views/misc.py

@@ -21,25 +21,5 @@ blueprint = Blueprint(
 
 
 def login():
-    host_url = request.host_url.rstrip('/')
-
-    if request.method == 'POST':
-        payload = {
-            'login_name': request.form.get('login_name'),
-            'password': request.form.get('password')
-        }
-
-        url = host_url + '/api/user/_sign_in'
-        headers = {'content-type': 'application/json'}
-        ret = requests.post(url, data=json.dumps(payload), headers=headers, cookies=request.cookies)
-        ret = json.loads(ret.content)
-
-        if ret['state']['code'] == '200':
-            return
-
-        else:
-            pass
-
-    else:
-        return render_template('login.html')
+    return render_template('login.html')