From 62a1a63ff1021f248ec9efa3a3b70e9d33158773 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Sat, 16 Jan 2021 21:22:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E5=84=B2=E5=AD=98=E8=AA=B2?= =?UTF-8?q?=E8=A1=A8=E8=87=B3DB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 16 ++++++++++++++++ index.html | 6 +++--- js/index.vue | 45 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/api.py b/api.py index bb77e1e..7931079 100644 --- a/api.py +++ b/api.py @@ -52,6 +52,22 @@ def get(): else: return '{"status": "error access code"}', 403 +@app.route('/courseTable', methods=["POST"]) +def save(): + # 先驗證 access code 是否正確 + jsonData = request.get_json() + + status, uid, name = facebookAuth(jsonData['token']) + + if status: + with sqlite3.connect('data.db') as conn: + sql = "UPDATE `courseTables` SET `json`=? WHERE `uid`=?" + conn.execute(sql, [json.dumps(jsonData['data'], ensure_ascii=False), uid]) + conn.commit() + return '{"status": "saved"}', 200 + else: + return '{"status": "error access code"}', 403 + if __name__ == '__main__': app.debug = True app.run(host='0.0.0.0') diff --git a/index.html b/index.html index c41a714..d08ce62 100644 --- a/index.html +++ b/index.html @@ -35,9 +35,6 @@ - @@ -54,6 +51,9 @@
+
+
+
diff --git a/js/index.vue b/js/index.vue index def9fdc..a8b3f8d 100644 --- a/js/index.vue +++ b/js/index.vue @@ -6,6 +6,7 @@ var vm = new Vue({ 'departments': [], 'selectDepartment': '', 'foundName': "", + 'token': "" }, created() { window.fbAsyncInit = function() { @@ -17,7 +18,7 @@ var vm = new Vue({ }); FB.AppEvents.logPageView(); - vm.checkLogin() + vm.getCourseTable() }; (function(d, s, id){ @@ -46,17 +47,15 @@ var vm = new Vue({ }) }, methods: { - 'checkLogin': function(){ - console.log("check login") + 'getCourseTable': function(){ FB.getLoginStatus(function(response) { vm.statusChangeCallback(response); }); }, 'statusChangeCallback': function(response){ - console.log(response) if(response.status == "connected"){ - console.log("https://api.snsd0805.com/courseTable?token="+response.authResponse.accessToken) - fetch('https://api.snsd0805.com/courseTable?token='+response.authResponse.accessToken) + this.token = response.authResponse.accessToken + fetch('https://api.snsd0805.com/courseTable?token='+this.token) .then(function(response){ return response.json() }).then(function(jsonData){ @@ -65,6 +64,40 @@ var vm = new Vue({ .catch(function(err){ alert("錯誤: "+err) }) + }else{ + + } + }, + 'saveCourseTable': function(){ + if(this.token!=""){ + fetch('https://api.snsd0805.com/courseTable',{ + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + 'token': vm.token, + 'data': vm.selectCourses + }) + }) + .then(function(response){ + return response.json() + }) + .then(function(response){ + if(response.status=="saved"){ + alert("已儲存") + }else{ + alert("錯誤") + } + }) + .catch(function(err){ + alert("錯誤: "+err) + }) + + }else{ + FB.login(function(response){ + vm.getCourseTable() + }) } }, 'getTime': function(timeString){