tum пре 2 година
родитељ
комит
3269cf184c

+ 93 - 9
src/composable/settings.ts

1
 import { CapacitorHttp } from '@capacitor/core';
1
 import { CapacitorHttp } from '@capacitor/core';
2
 import Axios from "axios";
2
 import Axios from "axios";
3
+//import axios from "axios";
3
 import { setupCache } from 'axios-cache-interceptor';
4
 import { setupCache } from 'axios-cache-interceptor';
4
 
5
 
5
 
6
 
8
 
9
 
9
 export const TOKEN = '173cb9e357a861abd91e8008fab9246e0cc116af'
10
 export const TOKEN = '173cb9e357a861abd91e8008fab9246e0cc116af'
10
 //export const BASE_URL = 'http://192.168.1.35:8020/'
11
 //export const BASE_URL = 'http://192.168.1.35:8020/'
11
-//export const BASE_URL = 'http://localhost:8020/'
12
-export const BASE_URL = 'https://www.tigermuaythai.live/'
12
+export const BASE_URL = 'http://localhost:8020/'
13
+//export const BASE_URL = 'https://www.tigermuaythai.live/'
13
 
14
 
14
 const axios = setupCache(Axios); 
15
 const axios = setupCache(Axios); 
16
+//
17
+//axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
18
+//axios.defaults.xsrfCookieName = "csrftoken";
15
 
19
 
16
 export const getProducts = async () => {
20
 export const getProducts = async () => {
17
   console.log("Get Products")
21
   console.log("Get Products")
37
 
41
 
38
 export const getToken = async () => {
42
 export const getToken = async () => {
39
   console.log("get token ")
43
   console.log("get token ")
40
-  const { data } = await axios.post(BASE_URL + "api-token-auth/", {username: 'root', password: 'Tum 1984'})
41
-  console.log("get token ", data)
42
-  await Preferences.set({
44
+  const token = await Preferences.get({ key: 'token' });
45
+  console.log(token)
46
+  if( token.value == null ) {
47
+    //const { data } = await axios.post(BASE_URL + "api-token-auth/", {username: 'root', password: 'Tum 1984'})
48
+    const { data } = await axios.post(BASE_URL + "dj-rest-auth/login/", {username: 'root', password: 'Tum 1984'})
49
+    console.log("get token ", data)
50
+    await Preferences.set({
51
+      key: 'token', 
52
+      value: data.token
53
+    })
54
+    return data.token
55
+  }else {
56
+    return token.value
57
+  }
58
+}
59
+export const initAPI = async () => {
60
+  const r = await axios.get(BASE_URL + "backend/api/")
61
+  console.log("--- init api ---")
62
+  console.log(r)
63
+  console.log("-- cookie ---")
64
+  const cookieHeaders = r.headers['Set-Cookie'];
65
+  console.log(cookieHeaders)
66
+}
67
+export const setUserToken = async(token) => {
68
+  let data = await Preferences.set({
69
+    key: 'user_token', 
70
+    value: token
71
+  })
72
+  let data2 = await Preferences.set({
43
     key: 'token', 
73
     key: 'token', 
44
-    value: data.token
74
+    value: token
45
   })
75
   })
46
-  return data.token
76
+  return data
47
 }
77
 }
48
-
49
 export const getTrainers = async () => {
78
 export const getTrainers = async () => {
50
   const token = await Preferences.get({ key: 'token' });
79
   const token = await Preferences.get({ key: 'token' });
51
   console.log("token = ", token)
80
   console.log("token = ", token)
81
   }
110
   }
82
 }
111
 }
83
 export const listCourses = async  () => {
112
 export const listCourses = async  () => {
84
-
113
+  console.log("list courses ... ")
85
   const token = await Preferences.get({ key: 'token' });
114
   const token = await Preferences.get({ key: 'token' });
86
   console.log("token = ", token)
115
   console.log("token = ", token)
87
   const { data } = await axios.get(BASE_URL + "backend/api/courses/?ordering=-id&status=active", {
116
   const { data } = await axios.get(BASE_URL + "backend/api/courses/?ordering=-id&status=active", {
228
   })
257
   })
229
   return data
258
   return data
230
 }
259
 }
260
+export const facebookLogin = async(access_token) => {
261
+
262
+  const token = await Preferences.get({ key: 'token' });
263
+  console.log("access_code = ", access_token)
264
+  const { data } = await axios.post(BASE_URL + 'dj-rest-auth/facebook/',{access_token: access_token.token}, {
265
+    headers: {
266
+      'Content-Type': 'application/json', 
267
+    }
268
+  }).catch((error) => {
269
+    console.log("fb error = ", error)
270
+  })
271
+  console.log("facebook login = ", data)
272
+  return data
273
+}
274
+
275
+export const logout = async() => {
276
+
277
+  console.log("--- logout ---")
278
+  const token = await Preferences.get({ key: 'user_token' });
279
+  console.log("user_token = ", token)
280
+  //const { data } = await axios.post(BASE_URL + 'dj-rest-auth/logout/', {}, {
281
+    //headers: { 
282
+    //'Authorization': `Token ${token.value}`
283
+    //}
284
+  //})
285
+  await clearPref()
286
+  const { data } = await axios.post(BASE_URL + 'dj-rest-auth/logout/')
287
+  return data
288
+}
289
+export const clearPref = async() => {
290
+
291
+  const clear = await Preferences.clear()
292
+  return clear
293
+}
294
+export const isLogin = async() => {
295
+  const { value } = await Preferences.get({ key: 'user_token' });
296
+  if( value ) 
297
+    return true
298
+  else
299
+    return false
300
+}
301
+
302
+export const restSignup = async (username, email, pass1, pass2) => {
303
+  const { data } = await axios.post(BASE_URL + 'dj-rest-auth/registration/',{
304
+    username: username, 
305
+    email: email,
306
+    password1: pass1,
307
+    password2: pass2, 
308
+  }, {
309
+    headers: {
310
+      'Content-Type': 'application/json', 
311
+    }
312
+  })
313
+  return data
314
+}

+ 5 - 0
src/router/index.ts

52
         component: () => import('@/views/SearchPage.vue')
52
         component: () => import('@/views/SearchPage.vue')
53
       },
53
       },
54
       {
54
       {
55
+        path: 'signup/',
56
+        name: 'signup', 
57
+        component: () => import('@/views/SignupPage.vue')
58
+      },
59
+      {
55
         path: 'post_detail/:id/',
60
         path: 'post_detail/:id/',
56
         name: 'post_detail', 
61
         name: 'post_detail', 
57
         component: () => import('@/views/PostDetailPage.vue')
62
         component: () => import('@/views/PostDetailPage.vue')

+ 9 - 2
src/views/CourseMatDetailPage.vue

45
 import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent,   IonNavLink,
45
 import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent,   IonNavLink,
46
     IonButton,
46
     IonButton,
47
     IonButtons,
47
     IonButtons,
48
-    IonBackButton, onIonViewWillEnter, IonRow, IonGrid, IonCol, IonItem, IonList, IonAvatar, IonLabel, IonItemDivider} from '@ionic/vue';
48
+    IonBackButton, onIonViewWillEnter, IonRow, IonGrid, IonCol, IonItem, IonList, IonAvatar, IonLabel, IonItemDivider,
49
+    useIonRouter } from '@ionic/vue';
49
 
50
 
50
 import { Autoplay, Keyboard, Pagination, Scrollbar, Zoom } from 'swiper/modules';
51
 import { Autoplay, Keyboard, Pagination, Scrollbar, Zoom } from 'swiper/modules';
51
 import { Swiper, SwiperSlide } from 'swiper/vue';
52
 import { Swiper, SwiperSlide } from 'swiper/vue';
60
 import '@ionic/vue/css/ionic-swiper.css';
61
 import '@ionic/vue/css/ionic-swiper.css';
61
 
62
 
62
 import { useRoute } from 'vue-router';
63
 import { useRoute } from 'vue-router';
63
-import { getMat, BASE_URL, listMats } from '@/composable/settings';
64
+import { getMat, BASE_URL, listMats, isLogin} from '@/composable/settings';
64
 import { ref } from 'vue';
65
 import { ref } from 'vue';
65
 import CourseMat from '@/components/CourseMat.vue'
66
 import CourseMat from '@/components/CourseMat.vue'
66
 
67
 
73
 const name = ref()
74
 const name = ref()
74
 const mats = ref()
75
 const mats = ref()
75
 
76
 
77
+const ionRouter = useIonRouter();
76
 
78
 
77
 onIonViewWillEnter(async () => {
79
 onIonViewWillEnter(async () => {
80
+  const rl  = await isLogin()
81
+  if( rl == false ) {
82
+    ionRouter.navigate('/tabs/tab4', 'forward', 'replace');
83
+  }
78
   mat.value = await getMat(id)
84
   mat.value = await getMat(id)
79
   console.log(mat.value)
85
   console.log(mat.value)
80
   name.value = mat.value.vimeo_name || mat.value.course_name
86
   name.value = mat.value.vimeo_name || mat.value.course_name
81
   mats.value  = await listMats(mat.value.related_mats)
87
   mats.value  = await listMats(mat.value.related_mats)
88
+
82
 })
89
 })
83
 </script>
90
 </script>
84
 
91
 

+ 18 - 1
src/views/ProfilePage.vue

7
     </ion-header>
7
     </ion-header>
8
     <ion-content>
8
     <ion-content>
9
       <div class="example-content">Listen now content</div>
9
       <div class="example-content">Listen now content</div>
10
+      <ion-button @click='clear'>Clear Pref</ion-button>
11
+      <ion-button @click='btnLogout'>Btn Logout</ion-button>
12
+      <ion-button router-link="/tabs/signup">Signup</ion-button>
10
       <template v-if="isLogin">
13
       <template v-if="isLogin">
11
       <ion-button @click='fbLogout'>Logout</ion-button>
14
       <ion-button @click='fbLogout'>Logout</ion-button>
12
       </template>
15
       </template>
23
 import ExploreContainer from '@/components/ExploreContainer.vue';
26
 import ExploreContainer from '@/components/ExploreContainer.vue';
24
 import { defineComponent, onMounted } from 'vue';
27
 import { defineComponent, onMounted } from 'vue';
25
 import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
28
 import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
29
+import { facebookLogin, setUserToken, logout, clearPref } from '@/composable/settings';
26
 
30
 
27
 onMounted(() => {
31
 onMounted(() => {
28
   GoogleAuth.initialize();
32
   GoogleAuth.initialize();
57
   const result = await (<FacebookLoginResponse>(
61
   const result = await (<FacebookLoginResponse>(
58
     FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS })
62
     FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS })
59
   ));
63
   ));
60
-
64
+  console.log("-- fbLogin --")
65
+  console.info(result.accessToken)
61
   if (result.accessToken) {
66
   if (result.accessToken) {
67
+    let d = await facebookLogin(result.accessToken)
68
+    console.log("facebook authen ", d)
69
+    await setUserToken(d.key)
70
+    
62
     // Login successful.
71
     // Login successful.
63
     isLogin.value = true
72
     isLogin.value = true
64
     console.log(`Facebook access token is ${result.accessToken.token}`);
73
     console.log(`Facebook access token is ${result.accessToken.token}`);
67
 const fbLogout = async () => {
76
 const fbLogout = async () => {
68
   await FacebookLogin.logout();
77
   await FacebookLogin.logout();
69
   isLogin.value = false
78
   isLogin.value = false
79
+  await logout()
80
+}
81
+const btnLogout = async () => {
82
+  isLogin.value = false
83
+  await logout()
70
 }
84
 }
71
 onIonViewWillEnter(async () => {
85
 onIonViewWillEnter(async () => {
72
   const result = await (<FacebookLoginResponse>(
86
   const result = await (<FacebookLoginResponse>(
103
             }
117
             }
104
         });
118
         });
105
 }
119
 }
120
+const clear = async() => {
121
+  await clearPref()
122
+}
106
 </script>
123
 </script>

+ 111 - 0
src/views/SignupPage.vue

1
+<template>
2
+  <ion-page>
3
+    <ion-header>
4
+      <ion-toolbar>
5
+        <ion-buttons slot="start">
6
+          <ion-back-button></ion-back-button>
7
+        </ion-buttons>
8
+        <ion-title>
9
+          Signup
10
+        </ion-title>
11
+      </ion-toolbar>
12
+    </ion-header>
13
+    <ion-content class='ion-padding'>
14
+      <ion-input label="Username"  ref="username" label-placement="floating" fill="outline" placeholder="Example, john"
15
+      error-text="Help me" 
16
+        ></ion-input>
17
+      <ion-list>
18
+        <ion-item>
19
+          <ion-input label="Email" label-placement="floating" ref='email' fill="outline" type="email" placeholder="Example, hello@gmail.com"></ion-input>
20
+        </ion-item>
21
+        <ion-item>
22
+          <ion-input label="Password" label-placement='floating' fill='outline' ref="password" type="password" placeholder="Password"></ion-input>
23
+        </ion-item>
24
+        <ion-item>
25
+          <ion-input label="Password Confirmation" label-placement='floating' fill='outline' ref="password2" type="password" placeholder="Password Confirmation"></ion-input>
26
+        </ion-item>
27
+      </ion-list>
28
+      <div>
29
+      <ion-button @click="signup" class=' ion-margin-top'>Signup</ion-button>
30
+      </div>
31
+      <br>
32
+       <ion-input
33
+    ref="input"
34
+    type="email"
35
+    fill="solid"
36
+    label="Email"
37
+    label-placement="floating"
38
+    helper-text="Enter a valid email"
39
+    error-text="Invalid email"
40
+    @ionInput="validate"
41
+    @ionBlur="markTouched"
42
+  ></ion-input>
43
+    </ion-content>
44
+  </ion-page>
45
+</template>
46
+
47
+<script setup lang="ts">
48
+import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonList, IonSearchbar, IonLabel,
49
+IonItem, IonBackButton, IonProgressBar, IonButtons, IonInfiniteScroll,
50
+    IonInfiniteScrollContent, InfiniteScrollCustomEvent, IonInput } from '@ionic/vue';
51
+import { defineComponent, onMounted } from 'vue';
52
+import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
53
+import { searchMat, callUrl,restSignup } from '@/composable/settings';
54
+
55
+import { ref } from 'vue';
56
+import SearchItem from '@/components/SearchItem.vue';
57
+
58
+const results = ref();
59
+const is_empty = ref(false);
60
+const processing = ref(false)
61
+let next_url = null
62
+
63
+const username = ref(null)
64
+const password = ref(null)
65
+const password2 = ref(null)
66
+const email = ref(null)
67
+const input = ref(null)
68
+
69
+const signup = async () => { 
70
+  username.value.$el.errorText = "No way"
71
+  username.value.$el.classList.remove('ion-valid')
72
+  username.value.$el.classList.remove('ion-invalid')
73
+  username.value.$el.classList.add('ion-invalid')
74
+  username.value.$el.classList.add('ion-touched');
75
+  try {
76
+    console.log("username = ", username.value.$el.value)
77
+    const data = await restSignup(username.value.$el.value, email.value.$el.value, password.value.$el.value, password2.value.$el.value)
78
+    console.log(data)
79
+  }catch( err ) {
80
+    console.log("-- error --")
81
+    console.log(err)
82
+    username.value.$el.classList.add('ion-invalid')
83
+  }
84
+}
85
+
86
+const validateEmail = (email) => {
87
+        return email.match(
88
+          /^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
89
+        );
90
+      }
91
+
92
+  const validate = (ev) => {
93
+        const value = ev.target.value;
94
+
95
+        input.value.$el.classList.remove('ion-valid');
96
+        input.value.$el.classList.remove('ion-invalid');
97
+
98
+        if (value === '') return;
99
+
100
+        validateEmail(value)
101
+          ? input.value.$el.classList.add('ion-valid')
102
+          : input.value.$el.classList.add('ion-invalid');
103
+      }
104
+
105
+const markTouched = () => {
106
+  input.value.$el.classList.add('ion-touched');
107
+}
108
+const markTouched2 = () => {
109
+  username.value.$el.classList.add('ion-touched');
110
+}
111
+</script>

+ 9 - 9
src/views/Tab1Page.vue

67
 import { CapacitorHttp } from '@capacitor/core';
67
 import { CapacitorHttp } from '@capacitor/core';
68
 import { ref } from 'vue';
68
 import { ref } from 'vue';
69
 import { TOKEN, getProducts, setToken, getObject, getToken, getTrainers, listMats, storeAPNToken,
69
 import { TOKEN, getProducts, setToken, getObject, getToken, getTrainers, listMats, storeAPNToken,
70
-getTodayProgs, getLive, getPosts} from '@/composable/settings';
70
+getTodayProgs, getLive, getPosts, initAPI} from '@/composable/settings';
71
 //import VueCoreVideoPlayer from 'vue-core-video-player'
71
 //import VueCoreVideoPlayer from 'vue-core-video-player'
72
 import { vueVimeoPlayer } from 'vue-vimeo-player'
72
 import { vueVimeoPlayer } from 'vue-vimeo-player'
73
 
73
 
109
 
109
 
110
   //const player = new Player(video, options);
110
   //const player = new Player(video, options);
111
 
111
 
112
+const liveObj = ref()
112
 const modules =  [Autoplay, Keyboard, Pagination, Scrollbar, Zoom]
113
 const modules =  [Autoplay, Keyboard, Pagination, Scrollbar, Zoom]
113
   onIonViewWillEnter(async () => {
114
   onIonViewWillEnter(async () => {
114
     //console.log("video " ,video)
115
     //console.log("video " ,video)
126
     // setToken()
127
     // setToken()
127
     // let u = getObject()
128
     // let u = getObject()
128
     //console.log('u ', u)
129
     //console.log('u ', u)
129
-
130
+    await initAPI()
130
     token.value = await getToken()
131
     token.value = await getToken()
131
     getTrainers().then( (data) => {
132
     getTrainers().then( (data) => {
132
       trainers.value = data
133
       trainers.value = data
146
     getTodayProgs().then( (data) => {
147
     getTodayProgs().then( (data) => {
147
       todays.value = data
148
       todays.value = data
148
     })
149
     })
150
+    setInterval( async () => {
151
+      console.log("did enter")
152
+      if( liveObj.value == null ||  liveObj.value.result == false ) {
153
+        liveObj.value = await getLive()
154
+      }
155
+    }, 10000)
149
   })
156
   })
150
 
157
 
151
   onIonViewWillLeave(() => {
158
   onIonViewWillLeave(() => {
153
 
160
 
154
   })
161
   })
155
 
162
 
156
-const liveObj = ref()
157
   onIonViewDidEnter(async() => {
163
   onIonViewDidEnter(async() => {
158
-    setInterval( async () => {
159
-      console.log("did enter")
160
-      if( liveObj.value == null ||  liveObj.value.result == false ) {
161
-        liveObj.value = await getLive()
162
-      }
163
-    }, 10000)
164
   })
164
   })
165
 
165
 
166
   const doGet = async () => {
166
   const doGet = async () => {

+ 7 - 2
src/views/Tab3Page.vue

3
     <ion-header>
3
     <ion-header>
4
       <ion-toolbar>
4
       <ion-toolbar>
5
         <ion-title>Schedule</ion-title>
5
         <ion-title>Schedule</ion-title>
6
+       <ion-buttons slot="end">
7
+          <ion-button :router-link="'/tabs/search_page/'">
8
+            <ion-icon slot="icon-only" :icon="search"></ion-icon>
9
+          </ion-button>
10
+        </ion-buttons>
6
       </ion-toolbar>
11
       </ion-toolbar>
7
     </ion-header>
12
     </ion-header>
8
     <ion-content>
13
     <ion-content>
76
 
81
 
77
 <script setup lang="ts">
82
 <script setup lang="ts">
78
 import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonIcon, IonSegment, IonSegmentButton, onIonViewWillEnter, IonGrid, 
83
 import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonIcon, IonSegment, IonSegmentButton, onIonViewWillEnter, IonGrid, 
79
-IonRow, IonCol } from '@ionic/vue';
80
-import { home, heart, pin, star, call, globe, basket, barbell, trash, person } from 'ionicons/icons';
84
+IonRow, IonCol, IonButton, IonButtons } from '@ionic/vue';
85
+import { home, heart, pin, star, call, globe, basket, barbell, trash, person, search } from 'ionicons/icons';
81
 import ExploreContainer from '@/components/ExploreContainer.vue';
86
 import ExploreContainer from '@/components/ExploreContainer.vue';
82
 import CourseSchedule from '@/components/CourseSchedule.vue';
87
 import CourseSchedule from '@/components/CourseSchedule.vue';
83
 import { ref } from 'vue';
88
 import { ref } from 'vue';