tum 2 年之前
父節點
當前提交
cd5a4ade8f

+ 8 - 0
capacitor.config.ts

@@ -11,6 +11,14 @@ const config: CapacitorConfig = {
11 11
     CapacitorHttp: {
12 12
       enabled: true
13 13
     },
14
+    GoogleAuth: {
15
+      scopes: ['profile', 'email'],
16
+      serverClientId: '214019008700-7d2rl1u56edjj1s8lk9fvk9934ook9r3.apps.googleusercontent.com',
17
+      forceCodeForRefreshToken: true,
18
+    },
19
+    PushNotifications: {
20
+      presentationOptions: ["badge", "sound", "alert"]
21
+    }
14 22
   }
15 23
 };
16 24
 

+ 18 - 0
package-lock.json

@@ -10,6 +10,8 @@
10 10
       "dependencies": {
11 11
         "@capacitor-community/apple-sign-in": "^5.0.0",
12 12
         "@capacitor-community/facebook-login": "^5.0.3",
13
+        "@capacitor-community/fcm": "^5.0.2",
14
+        "@capacitor/android": "5.5.0",
13 15
         "@capacitor/app": "5.0.6",
14 16
         "@capacitor/core": "5.5.0",
15 17
         "@capacitor/haptics": "5.0.6",
@@ -1745,6 +1747,22 @@
1745 1747
         "node": ">=16.0.0"
1746 1748
       }
1747 1749
     },
1750
+    "node_modules/@capacitor-community/fcm": {
1751
+      "version": "5.0.2",
1752
+      "resolved": "https://registry.npmjs.org/@capacitor-community/fcm/-/fcm-5.0.2.tgz",
1753
+      "integrity": "sha512-E3RjjI0Vm9RaAPzhrjacN5IdHV7KpTyNEzj4UnsHimwYU62YIs+mtcC4IDhzPvASuA3/XXj8ZOjWvQwN3osYxA==",
1754
+      "peerDependencies": {
1755
+        "@capacitor/core": "^5.0.0"
1756
+      }
1757
+    },
1758
+    "node_modules/@capacitor/android": {
1759
+      "version": "5.5.0",
1760
+      "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-5.5.0.tgz",
1761
+      "integrity": "sha512-ipJijb3M0FA6DvotS9zrbJ8p/mTEVg9EVtBmvUexogm8g5se1mc7i1gvOr3MQ/iTZ3PnNrRC/P7kHxa2R55iqg==",
1762
+      "peerDependencies": {
1763
+        "@capacitor/core": "^5.5.0"
1764
+      }
1765
+    },
1748 1766
     "node_modules/@capacitor/app": {
1749 1767
       "version": "5.0.6",
1750 1768
       "resolved": "https://registry.npmjs.org/@capacitor/app/-/app-5.0.6.tgz",

+ 2 - 0
package.json

@@ -14,6 +14,8 @@
14 14
   "dependencies": {
15 15
     "@capacitor-community/apple-sign-in": "^5.0.0",
16 16
     "@capacitor-community/facebook-login": "^5.0.3",
17
+    "@capacitor-community/fcm": "^5.0.2",
18
+    "@capacitor/android": "5.5.0",
17 19
     "@capacitor/app": "5.0.6",
18 20
     "@capacitor/core": "5.5.0",
19 21
     "@capacitor/haptics": "5.0.6",

+ 1 - 0
src/components/CourseMat.vue

@@ -41,6 +41,7 @@
41 41
     console.log("name === ", props.obj)
42 42
 
43 43
     const obj = props.obj
44
+
44 45
     if(await isLogin()) {
45 46
       pref = await getPref()
46 47
       console.debug(" pref = ", pref)

+ 18 - 16
src/composable/settings.ts

@@ -8,9 +8,9 @@ import { Preferences } from '@capacitor/preferences';
8 8
 
9 9
 
10 10
 export const TOKEN = '173cb9e357a861abd91e8008fab9246e0cc116af'
11
-//export const BASE_URL = 'http://192.168.1.35:8020/'
12
-export const BASE_URL = 'http://localhost:8020/'
13
-//export const BASE_URL = 'https://www.tigermuaythai.live/'
11
+
12
+//export const BASE_URL = 'http://localhost:8020/'
13
+export const BASE_URL = 'https://www.tigermuaythai.live/'
14 14
 
15 15
 export const APPLE_CALLBACK = BASE_URL + "soc_accounts/apple/login/callback/";
16 16
 //const axios = setupCache(Axios); 
@@ -50,9 +50,9 @@ export const getToken = async () => {
50 50
     console.log("get token ", data)
51 51
     await Preferences.set({
52 52
       key: 'token', 
53
-      value: data.token
53
+      value: data.key
54 54
     })
55
-    return data.token
55
+    return data.key
56 56
   }else {
57 57
     return token.value
58 58
   }
@@ -64,16 +64,17 @@ export const initAPI = async () => {
64 64
   console.log("-- cookie ---")
65 65
   const cookieHeaders = r.headers['Set-Cookie'];
66 66
   console.log(cookieHeaders)
67
+  return r;
67 68
 }
68 69
 export const setUserToken = async(token) => {
69 70
   let data = await Preferences.set({
70 71
     key: 'user_token', 
71 72
     value: token
72 73
   })
73
-  let data2 = await Preferences.set({
74
-    key: 'token', 
75
-    value: token
76
-  })
74
+  //let data2 = await Preferences.set({
75
+    //key: 'token', 
76
+    //value: token
77
+  //})
77 78
   return data
78 79
 }
79 80
 export const getTrainers = async () => {
@@ -148,8 +149,8 @@ export const getMat = async(pk) => {
148 149
 }
149 150
 
150 151
 export const storeAPNToken = async (device_token) => {
151
-  
152 152
   const token = await Preferences.get({ key: 'token' });
153
+  console.log('storeAPNToken ', token, device_token) 
153 154
   console.log("token = ", token)
154 155
   const { data } = await axios.post(BASE_URL + "backend/api/device_tokens/",{token: device_token},
155 156
   {
@@ -316,7 +317,8 @@ export const logout = async() => {
316 317
 }
317 318
 export const clearPref = async() => {
318 319
 
319
-  const clear = await Preferences.clear()
320
+  //const clear = await Preferences.clear()
321
+  const clear = await Preferences.remove({key: 'user_token'})
320 322
   return clear
321 323
 }
322 324
 export const isLogin = async() => {
@@ -356,7 +358,7 @@ export const resetPassword = async (email) => {
356 358
 
357 359
 
358 360
 export const getPref = async () => {
359
-  const token = await Preferences.get({ key: 'token' });
361
+  const token = await Preferences.get({ key: 'user_token' });
360 362
   console.log("token = ", token)
361 363
   const { data } = await axios.get(BASE_URL + `backend/api/profiles/myprofile/`, {
362 364
     headers: { 
@@ -371,7 +373,7 @@ export const getPref = async () => {
371 373
   return data
372 374
 }
373 375
 export const likeCourse = async (cid) => {
374
-  const token = await Preferences.get({ key: 'token' });
376
+  const token = await Preferences.get({ key: 'user_token' });
375 377
   console.log("token = ", token)
376 378
   const { data } = await axios.get(BASE_URL + `backend/api/profiles/like_course/?cid=${cid}`, {
377 379
     headers: { 
@@ -382,7 +384,7 @@ export const likeCourse = async (cid) => {
382 384
   return data
383 385
 }
384 386
 export const likeMat = async (cid) => {
385
-  const token = await Preferences.get({ key: 'token' });
387
+  const token = await Preferences.get({ key: 'user_token' });
386 388
   console.log("token = ", token)
387 389
   const { data } = await axios.get(BASE_URL + `backend/api/profiles/like_mat/?cid=${cid}`, {
388 390
     headers: { 
@@ -395,7 +397,7 @@ export const likeMat = async (cid) => {
395 397
 
396 398
 
397 399
 export const updateNoti = async (noti) => {
398
-  const token = await Preferences.get({ key: 'token' });
400
+  const token = await Preferences.get({ key: 'user_token' });
399 401
   console.log("token = ", token)
400 402
   const { data } = await axios.post(BASE_URL + `backend/api/profiles/update_noti/`,
401 403
   {live_noti: noti.liveNoti, 'news_noti':noti.newsNoti},
@@ -410,7 +412,7 @@ export const updateNoti = async (noti) => {
410 412
 
411 413
 export const appleLogin = async(access_token) => {
412 414
 
413
-  const token = await Preferences.get({ key: 'token' });
415
+  const token = await Preferences.get({ key: 'user_token' });
414 416
   console.log("access_code = ", access_token)
415 417
   const { data } = await axios.post(BASE_URL + 'dj-rest-auth/apple/',{access_token: access_token.authorizationCode, id_token: access_token.identityToken}, {
416 418
     headers: {

+ 5 - 1
src/views/CourseMatDetailPage.vue

@@ -46,7 +46,7 @@
46 46
 import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent,   IonNavLink,
47 47
     IonButton,
48 48
     IonButtons,
49
-    IonBackButton, onIonViewWillEnter, IonRow, IonGrid, IonCol, IonItem, IonList, IonAvatar, IonLabel, IonItemDivider,
49
+    IonBackButton, onIonViewWillEnter, onIonViewDidLeave, IonRow, IonGrid, IonCol, IonItem, IonList, IonAvatar, IonLabel, IonItemDivider,
50 50
     useIonRouter } from '@ionic/vue';
51 51
 
52 52
 import { Autoplay, Keyboard, Pagination, Scrollbar, Zoom } from 'swiper/modules';
@@ -88,6 +88,10 @@ onIonViewWillEnter(async () => {
88 88
   mats.value  = await listMats(mat.value.related_mats)
89 89
 
90 90
 })
91
+onIonViewDidLeave(async () => {
92
+  mat.value.embed = null; 
93
+})
94
+
91 95
 </script>
92 96
 
93 97
 <style scoped>

+ 8 - 3
src/views/ProfilePage.vue

@@ -82,7 +82,7 @@
82 82
 </template>
83 83
 
84 84
 <script setup lang="ts">
85
-import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonRow, IonCol, IonGrid, IonToggle, IonLabel, IonChip, IonIcon, IonSelect, IonSelectOption, IonList, IonListHeader, IonItem, IonText } from '@ionic/vue';
85
+import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonRow, IonCol, IonGrid, IonToggle, IonLabel, IonChip, IonIcon, IonSelect, IonSelectOption, IonList, IonListHeader, IonItem, IonText, IonImg } from '@ionic/vue';
86 86
 import ExploreContainer from '@/components/ExploreContainer.vue';
87 87
 import LoginForm from '@/components/LoginForm.vue';
88 88
 import { defineComponent, onMounted } from 'vue';
@@ -162,7 +162,12 @@ const urlChange = (event) => {
162 162
 
163 163
 const ggLoginClick = async () => {
164 164
   console.log("ggLogin")
165
-  const response = await GoogleAuth.signIn();
165
+  let response = null;
166
+  try{
167
+    response = await GoogleAuth.signIn();
168
+  }catch(error) {
169
+    console.log("Error ", error);
170
+  }
166 171
   let t1 = response.authentication.accessToken;
167 172
   let t2 = response.authentication.idToken;
168 173
   let t3 = response.authentication.refreshToken;
@@ -297,7 +302,7 @@ const userLogin = async (data) => {
297 302
   }else {
298 303
     console.log("Success")
299 304
     await setUserToken(data.key)
300
-    
305
+    myprofile.value  = await getPref()
301 306
     // Login successful.
302 307
     refIsLogin.value = true
303 308
   }

+ 10 - 1
src/views/Tab1Page.vue

@@ -79,6 +79,8 @@ import { vueVimeoPlayer } from 'vue-vimeo-player'
79 79
 import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
80 80
 
81 81
 import { PushNotifications } from '@capacitor/push-notifications';
82
+import { FCM } from "@capacitor-community/fcm";
83
+
82 84
 
83 85
 import Player from '@vimeo/player';
84 86
 
@@ -122,7 +124,8 @@ const modules =  [Autoplay, Keyboard, Pagination, Scrollbar, Zoom]
122 124
     let v = await isLogin()
123 125
     console.log("v === ", v)
124 126
     if( v == false ) {
125
-      ionRouter.navigate('/tabs/tab4', 'forward', 'replace');
127
+    ;
128
+      //ionRouter.navigate('/tabs/tab4', 'forward', 'replace');
126 129
     }
127 130
     //console.log("video " ,video)
128 131
     //console.log("video id", video.value.id)
@@ -196,6 +199,12 @@ const addListeners = async () => {
196 199
   await PushNotifications.addListener('registration', token => {
197 200
     console.info('Registration token: ', token.value);
198 201
     storeAPNToken(token.value)
202
+    
203
+    FCM.subscribeTo({ topic: "TMT" })
204
+    .then((r) => {
205
+      console.log("subsribe to topic ", r)
206
+    })
207
+    .catch((err) => console.log(err));
199 208
   });
200 209
 
201 210
   await PushNotifications.addListener('registrationError', err => {