|
|
@@ -9,7 +9,8 @@
|
|
9
|
9
|
<!--
|
|
10
|
10
|
<ion-button @click='clear'>Clear Pref</ion-button>
|
|
11
|
11
|
<ion-button @click='btnLogout'>Btn Logout</ion-button> -->
|
|
12
|
|
- <template v-if="isLogin">
|
|
|
12
|
+ <template v-if="refIsLogin && myprofile">
|
|
|
13
|
+
|
|
13
|
14
|
<ion-list>
|
|
14
|
15
|
<ion-list-header>
|
|
15
|
16
|
<ion-label>Notifications</ion-label>
|
|
|
@@ -24,16 +25,16 @@
|
|
24
|
25
|
<ion-label>Select Courses You like</ion-label>
|
|
25
|
26
|
</ion-list-header>
|
|
26
|
27
|
<ion-item>
|
|
27
|
|
- <ion-select aria-label="Fruit" placeholder="Select all fruits that apply"
|
|
|
28
|
+ <ion-select aria-label="Training Courses" placeholder="Select Course You like"
|
|
28
|
29
|
:compareWith="compareWith" @ionChange="handleChange($event)">
|
|
29
|
30
|
<ion-select-option :value="c" v-for="c in list_courses">{{ c.name }}</ion-select-option>
|
|
30
|
31
|
</ion-select>
|
|
31
|
32
|
</ion-item>
|
|
32
|
33
|
</ion-list>
|
|
33
|
|
- <div class='ion-padding'>
|
|
|
34
|
+ <div class='ion-padding' v-if="myprofile">
|
|
34
|
35
|
<h1>I love ...</h1>
|
|
35
|
|
- <ion-chip v-for="s in selecteds">
|
|
36
|
|
- <ion-label>{{ s }}</ion-label>
|
|
|
36
|
+ <ion-chip v-for="s in myprofile.course_likes">
|
|
|
37
|
+ <ion-label>{{ s.name }}</ion-label>
|
|
37
|
38
|
<ion-icon :icon="close" @click="removeItem(s)"></ion-icon>
|
|
38
|
39
|
</ion-chip>
|
|
39
|
40
|
</div>
|
|
|
@@ -57,22 +58,23 @@
|
|
57
|
58
|
<ion-button @click='fbLogin' expand='full'>Facebook Login</ion-button>
|
|
58
|
59
|
</ion-col>
|
|
59
|
60
|
<ion-col size=6>
|
|
60
|
|
- <ion-button @click='ggLogin' expand='full'>Google Login</ion-button>
|
|
|
61
|
+ <ion-button @click='ggLoginClick' expand='full'>Google Login</ion-button>
|
|
61
|
62
|
</ion-col>
|
|
62
|
63
|
</ion-row>
|
|
63
|
64
|
</ion-grid>
|
|
|
65
|
+ <ion-text color="danger" v-if="formError">{{ formError }}</ion-text>
|
|
64
|
66
|
</template>
|
|
65
|
67
|
</ion-content>
|
|
66
|
68
|
</ion-page>
|
|
67
|
69
|
</template>
|
|
68
|
70
|
|
|
69
|
71
|
<script setup lang="ts">
|
|
70
|
|
-import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonRow, IonCol, IonGrid, IonToggle, IonLabel, IonChip, IonIcon, IonSelect, IonSelectOption } from '@ionic/vue';
|
|
|
72
|
+import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonRow, IonCol, IonGrid, IonToggle, IonLabel, IonChip, IonIcon, IonSelect, IonSelectOption, IonList, IonListHeader, IonItem, IonText } from '@ionic/vue';
|
|
71
|
73
|
import ExploreContainer from '@/components/ExploreContainer.vue';
|
|
72
|
74
|
import LoginForm from '@/components/LoginForm.vue';
|
|
73
|
75
|
import { defineComponent, onMounted } from 'vue';
|
|
74
|
76
|
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
|
|
75
|
|
-import { facebookLogin, setUserToken, logout, clearPref, BASE_URL, listCourses } from '@/composable/settings';
|
|
|
77
|
+import { facebookLogin, setUserToken, logout, clearPref, BASE_URL, listCourses, getPref, likeCourse, isLogin, ggLogin } from '@/composable/settings';
|
|
76
|
78
|
import { InAppBrowser } from '@capgo/inappbrowser'
|
|
77
|
79
|
import { close, closeCircle, pin } from 'ionicons/icons';
|
|
78
|
80
|
|
|
|
@@ -97,13 +99,14 @@ const FACEBOOK_PERMISSIONS = [
|
|
97
|
99
|
//'user_gender',
|
|
98
|
100
|
];
|
|
99
|
101
|
|
|
100
|
|
-const isLogin = ref(false)
|
|
|
102
|
+const refIsLogin = ref(false)
|
|
101
|
103
|
const liveNoti = ref(true)
|
|
102
|
104
|
const favCourseNoti = ref(true)
|
|
103
|
105
|
const newsNoti = ref(true)
|
|
104
|
106
|
const list_courses = ref([])
|
|
105
|
|
-
|
|
|
107
|
+const formError = ref(null)
|
|
106
|
108
|
const selecteds = ref([])
|
|
|
109
|
+const myprofile = ref()
|
|
107
|
110
|
|
|
108
|
111
|
const openReset = async () => {
|
|
109
|
112
|
console.log("open Reset")
|
|
|
@@ -111,11 +114,13 @@ const openReset = async () => {
|
|
111
|
114
|
console.info("bw ", browser)
|
|
112
|
115
|
InAppBrowser.addListener("urlChangeEvent", urlChange)
|
|
113
|
116
|
}
|
|
114
|
|
-const removeItem = (s) => {
|
|
|
117
|
+const removeItem = async(s) => {
|
|
|
118
|
+ /*
|
|
115
|
119
|
let temp = selecteds.value
|
|
116
|
120
|
temp = temp.filter( e => e !== s)
|
|
117
|
121
|
console.log(temp)
|
|
118
|
|
- selecteds.value = temp
|
|
|
122
|
+ selecteds.value = temp*/
|
|
|
123
|
+ myprofile.value = await likeCourse(s.id)
|
|
119
|
124
|
}
|
|
120
|
125
|
const urlChange = (event) => {
|
|
121
|
126
|
console.info("url change ", event)
|
|
|
@@ -129,12 +134,25 @@ const urlChange = (event) => {
|
|
129
|
134
|
//accounts/password_reset/done/
|
|
130
|
135
|
}
|
|
131
|
136
|
|
|
132
|
|
-const ggLogin = async () => {
|
|
|
137
|
+const ggLoginClick = async () => {
|
|
|
138
|
+ console.log("ggLogin")
|
|
133
|
139
|
const response = await GoogleAuth.signIn();
|
|
134
|
|
- console.log(response);
|
|
135
|
|
- console.log(response.accessToken)
|
|
136
|
|
- if( response.authentication.accessToken ) {
|
|
137
|
|
- isLogin.value = true
|
|
|
140
|
+ let t1 = response.authentication.accessToken;
|
|
|
141
|
+ let t2 = response.authentication.idToken;
|
|
|
142
|
+ let t3 = response.authentication.refreshToken;
|
|
|
143
|
+ let token = response.authentication.idToken
|
|
|
144
|
+ console.log(token)
|
|
|
145
|
+ if(response.authentication) {
|
|
|
146
|
+ try{
|
|
|
147
|
+ let d = await ggLogin(t1, t2)
|
|
|
148
|
+ await setUserToken(d.key)
|
|
|
149
|
+ myprofile.value = await getPref()
|
|
|
150
|
+ refIsLogin.value = true
|
|
|
151
|
+
|
|
|
152
|
+ }catch(error) {
|
|
|
153
|
+ formError.value = "Please Check Your UserId/Password"
|
|
|
154
|
+ console.log(error)
|
|
|
155
|
+ }
|
|
138
|
156
|
}
|
|
139
|
157
|
}
|
|
140
|
158
|
|
|
|
@@ -145,39 +163,51 @@ const fbLogin = async () => {
|
|
145
|
163
|
console.log("-- fbLogin --")
|
|
146
|
164
|
console.info(result.accessToken)
|
|
147
|
165
|
if (result.accessToken) {
|
|
148
|
|
- let d = await facebookLogin(result.accessToken)
|
|
149
|
|
- console.log("facebook authen ", d)
|
|
150
|
|
- await setUserToken(d.key)
|
|
151
|
|
-
|
|
152
|
|
- // Login successful.
|
|
153
|
|
- isLogin.value = true
|
|
|
166
|
+ try{
|
|
|
167
|
+ let d = await facebookLogin(result.accessToken)
|
|
|
168
|
+ console.log("facebook authen ", d)
|
|
|
169
|
+ await setUserToken(d.key)
|
|
|
170
|
+ myprofile.value = await getPref()
|
|
|
171
|
+ await getProfile()
|
|
|
172
|
+ // Login successful.
|
|
|
173
|
+ refIsLogin.value = true
|
|
|
174
|
+ }catch(error) {
|
|
|
175
|
+ formError.value = "Please Check Your UserId/Password"
|
|
|
176
|
+ }
|
|
154
|
177
|
console.log(`Facebook access token is ${result.accessToken.token}`);
|
|
155
|
178
|
}
|
|
156
|
179
|
}
|
|
157
|
180
|
const fbLogout = async () => {
|
|
158
|
181
|
await FacebookLogin.logout();
|
|
159
|
|
- isLogin.value = false
|
|
|
182
|
+ await GoogleAuth.signOut()
|
|
|
183
|
+ refIsLogin.value = false
|
|
160
|
184
|
await logout()
|
|
161
|
185
|
}
|
|
162
|
186
|
const btnLogout = async () => {
|
|
163
|
|
- isLogin.value = false
|
|
|
187
|
+ refIsLogin.value = false
|
|
164
|
188
|
await logout()
|
|
165
|
189
|
}
|
|
166
|
190
|
onIonViewWillEnter(async () => {
|
|
|
191
|
+ console.log("ion view will enter")
|
|
|
192
|
+ console.log(await isLogin())
|
|
167
|
193
|
const result = await (<FacebookLoginResponse>(
|
|
168
|
194
|
FacebookLogin.getCurrentAccessToken()
|
|
169
|
195
|
));
|
|
170
|
196
|
console.log(result == undefined)
|
|
171
|
197
|
if (result != undefined && result.accessToken) {
|
|
172
|
198
|
console.log(`Facebook access token is ${result.accessToken.token}`);
|
|
173
|
|
- isLogin.value = true
|
|
|
199
|
+ refIsLogin.value = true
|
|
174
|
200
|
await getProfile()
|
|
175
|
201
|
}else {
|
|
176
|
|
- isLogin.value = false
|
|
|
202
|
+ refIsLogin.value = false
|
|
177
|
203
|
}
|
|
178
|
204
|
|
|
179
|
205
|
list_courses.value = await listCourses()
|
|
180
|
206
|
ggCheckLogin()
|
|
|
207
|
+ refIsLogin.value = await isLogin()
|
|
|
208
|
+ if( refIsLogin.value == true ) {
|
|
|
209
|
+ myprofile.value = await getPref()
|
|
|
210
|
+ }
|
|
181
|
211
|
|
|
182
|
212
|
})
|
|
183
|
213
|
const getProfile = async () => {
|
|
|
@@ -189,9 +219,10 @@ const getProfile = async () => {
|
|
189
|
219
|
}
|
|
190
|
220
|
const ggCheckLogin = async() => {
|
|
191
|
221
|
GoogleAuth.refresh()
|
|
192
|
|
- .then((data) => {
|
|
|
222
|
+ .then(async (data) => {
|
|
193
|
223
|
if (data.accessToken) {
|
|
194
|
|
- isLogin.value = true
|
|
|
224
|
+ refIsLogin.value = true
|
|
|
225
|
+ myprofile.value = await getPref()
|
|
195
|
226
|
}
|
|
196
|
227
|
})
|
|
197
|
228
|
.catch((error) => {
|
|
|
@@ -204,7 +235,8 @@ const clear = async() => {
|
|
204
|
235
|
await clearPref()
|
|
205
|
236
|
}
|
|
206
|
237
|
const userLogin = async (data) => {
|
|
207
|
|
- console.info("user login ", data)
|
|
|
238
|
+ console.info("user login = ", data)
|
|
|
239
|
+ console.info(data.key)
|
|
208
|
240
|
if(data.error) {
|
|
209
|
241
|
console.log("ERROR")
|
|
210
|
242
|
}else {
|
|
|
@@ -212,15 +244,20 @@ const userLogin = async (data) => {
|
|
212
|
244
|
await setUserToken(data.key)
|
|
213
|
245
|
|
|
214
|
246
|
// Login successful.
|
|
215
|
|
- isLogin.value = true
|
|
|
247
|
+ refIsLogin.value = true
|
|
216
|
248
|
}
|
|
217
|
249
|
}
|
|
218
|
250
|
|
|
219
|
251
|
const compareWith = (o1, o2) => {
|
|
220
|
252
|
return o1 && o2 ? o1.id === o2.id : o1 === o2;
|
|
221
|
253
|
}
|
|
222
|
|
-const handleChange = (ev) =>{
|
|
|
254
|
+const handleChange = async (ev) =>{
|
|
223
|
255
|
console.log('Current value:', ev.detail.value);
|
|
224
|
|
- selecteds.value.push(ev.detail.value.name)
|
|
|
256
|
+ let v = ev.detail.value
|
|
|
257
|
+ myprofile.value = await likeCourse(v.id)
|
|
|
258
|
+ if( selecteds.value.indexOf(v.name) == -1 ) {
|
|
|
259
|
+ selecteds.value.push(v.name)
|
|
|
260
|
+ }
|
|
|
261
|
+
|
|
225
|
262
|
}
|
|
226
|
263
|
</script>
|