Pārlūkot izejas kodu

:pencil2: Fixed merge issues

tags/0.0.4
tomit4 2 gadus atpakaļ
vecāks
revīzija
f7229008ec

+ 0
- 1
frontend/src/components/onboarding/Auth.vue Parādīt failu

@@ -47,7 +47,6 @@ export default {
47 47
             const accessToken = await this.getAccessToken({
48 48
                 ...this.answered,
49 49
             })
50
-            console.log('accessToken :=>', accessToken)
51 50
             const sessionInfo = await authenticator.sendAuthEmail({
52 51
                 ...this.answered,
53 52
                 accessToken: accessToken,

+ 2
- 26
frontend/src/router/guards.js Parādīt failu

@@ -14,32 +14,8 @@ async function log(to) {
14 14
     }
15 15
 }
16 16
 
17
-// TODO: move to utils/index.js and import to this file, OnboardingView.vue and VerifyView.vue
18
-const grabStoredCookie = cookieKey => {
19
-    const cookies = document.cookie.split('; ').reduce((prev, current) => {
20
-        const [name, ...value] = current.split('=')
21
-        prev[name] = value.join('=')
22
-        return prev
23
-    }, {})
24
-    const cookieVal = cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
25
-    return cookieVal
26
-}
27
-
28
-const verifySession = async () => {
29
-    const hashedAccessToken = grabStoredCookie('siimee_access')
30
-    if (!hashedAccessToken)
31
-        return console.warn('WARNING :=> accessToken is not defined')
32
-    const validatedToken =
33
-        await authenticator.validateSession(hashedAccessToken)
34
-    if (validatedToken.error) {
35
-        console.error('ERROR :=>', validatedToken.error)
36
-    } else {
37
-        return validatedToken
38
-    }
39
-}
40
-
41 17
 const loginIfToken = async () => {
42
-    const sessionData = await verifySession()
18
+    const sessionData = await authenticator.verifySessionCookie('siimee_access')
43 19
     if (
44 20
         sessionData?.profileId &&
45 21
         sessionData?.accessToken &&
@@ -73,6 +49,6 @@ const checkLoginStatus = async (destination, nextCb) => {
73 49
     } else {
74 50
         nextCb()
75 51
     }
76
-}
52
+        }
77 53
 
78 54
 export { checkLoginStatus }

+ 23
- 0
frontend/src/services/auth.service.js Parādīt failu

@@ -22,6 +22,29 @@ class Authenticator {
22 22
     async removeSession(hashedAccessToken) {
23 23
         return await db.post('/user/removesession', hashedAccessToken, true)
24 24
     }
25
+    grabStoredCookie(cookieKey) {
26
+        const cookies = document.cookie.split('; ').reduce((prev, current) => {
27
+            const [name, ...value] = current.split('=')
28
+            prev[name] = value.join('=')
29
+            return prev
30
+        }, {})
31
+        const cookieVal =
32
+            cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
33
+        return cookieVal
34
+    }
35
+    async verifySessionCookie(sessionCookie) {
36
+        const hashedAccessToken = this.grabStoredCookie(sessionCookie)
37
+        if (!hashedAccessToken)
38
+            return console.warn('WARNING :=> accessToken is not defined')
39
+        const validatedToken = await authenticator.validateSession(
40
+            hashedAccessToken,
41
+        )
42
+        if (validatedToken.error) {
43
+            console.error('ERROR :=>', validatedToken.error)
44
+        } else {
45
+            return validatedToken
46
+        }
47
+    }
25 48
 }
26 49
 const authenticator = new Authenticator()
27 50
 

+ 0
- 26
frontend/src/utils/index.js Parādīt failu

@@ -130,30 +130,6 @@ const randomSurveyResponses = count => {
130 130
     return surveyResponses
131 131
 }
132 132
 
133
-const grabStoredCookie = cookieKey => {
134
-    const cookies = document.cookie.split('; ').reduce((prev, current) => {
135
-        const [name, ...value] = current.split('=')
136
-        prev[name] = value.join('=')
137
-        return prev
138
-    }, {})
139
-    const cookieVal = cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
140
-    return cookieVal
141
-}
142
-
143
-const verifySession = async () => {
144
-    const hashedAccessToken = grabStoredCookie('siimee_access')
145
-    if (!hashedAccessToken)
146
-        return console.warn('WARNING :=> accessToken is not defined')
147
-    const validatedToken = await authenticator.validateSession(
148
-        hashedAccessToken,
149
-    )
150
-    if (validatedToken.error) {
151
-        console.error('ERROR :=>', validatedToken.error)
152
-    } else {
153
-        return validatedToken
154
-    }
155
-}
156
-
157 133
 export {
158 134
     validatorMapping,
159 135
     surveyFactory,
@@ -165,6 +141,4 @@ export {
165 141
     randomMedia,
166 142
     randomName,
167 143
     randomEmail,
168
-    grabStoredCookie,
169
-    verifySession,
170 144
 }

+ 2
- 13
frontend/src/views/HomeView.vue Parādīt failu

@@ -95,23 +95,12 @@ export default {
95 95
             )
96 96
             this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
97 97
         },
98
-        grabStoredCookie(cookieKey) {
99
-            const cookies = document.cookie
100
-                .split('; ')
101
-                .reduce((prev, current) => {
102
-                    const [name, ...value] = current.split('=')
103
-                    prev[name] = value.join('=')
104
-                    return prev
105
-                }, {})
106
-            const cookieVal =
107
-                cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
108
-            return cookieVal
109
-        },
110 98
         async logout() {
111 99
             if (currentProfile.isLoggedIn) {
112 100
                 currentProfile.logout()
113 101
             }
114
-            const hashedAccessToken = this.grabStoredCookie('siimee_access')
102
+            const hashedAccessToken =
103
+                authenticator.grabStoredCookie('siimee_access')
115 104
             const removedSession = await authenticator.removeSession(
116 105
                 hashedAccessToken,
117 106
             )

+ 3
- 27
frontend/src/views/OnboardingView.vue Parādīt failu

@@ -38,7 +38,6 @@ import { currentProfile, authenticator } from '../services'
38 38
 import { surveyFactory } from '@/utils'
39 39
 import stepViews from '@/components/onboarding'
40 40
 import SurveyCompleteView from './SurveyCompleteView.vue'
41
-let hashedAccessToken = null
42 41
 
43 42
 export default {
44 43
     name: 'OnboardingView',
@@ -56,9 +55,9 @@ export default {
56 55
     }),
57 56
     async created() {
58 57
         this.survey = await surveyFactory.createSurvey()
59
-        hashedAccessToken = this.grabStoredCookie('siimee_access')
60 58
         try {
61
-            const sessionData = await this.verifySession(hashedAccessToken)
59
+            const sessionData =
60
+                await authenticator.verifySessionCookie('siimee_access')
62 61
             if (sessionData) {
63 62
                 await currentProfile.login(
64 63
                     sessionData.profileId,
@@ -83,29 +82,6 @@ export default {
83 82
         async goToStep(num) {
84 83
             this.currentStep = num
85 84
         },
86
-        grabStoredCookie(cookieKey) {
87
-            const cookies = document.cookie
88
-                .split('; ')
89
-                .reduce((prev, current) => {
90
-                    const [name, ...value] = current.split('=')
91
-                    prev[name] = value.join('=')
92
-                    return prev
93
-                }, {})
94
-            const cookieVal =
95
-                cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
96
-            return cookieVal
97
-        },
98
-        async verifySession(hashedAccessToken) {
99
-            if (!hashedAccessToken)
100
-                return console.warn('WARNING :=> accessToken is not defined')
101
-            const validatedToken =
102
-                await authenticator.validateSession(hashedAccessToken)
103
-            if (validatedToken.error) {
104
-                throw new Error(validatedToken.error)
105
-            } else {
106
-                return validatedToken
107
-            }
108
-        },
109 85
         formatResponses(responses) {
110 86
             return responses.map(response => {
111 87
                 return {
@@ -139,7 +115,7 @@ export default {
139 115
                 )
140 116
                 currentProfile._profile.responses = this.responses
141 117
                 try {
142
-                    await this.verifySession(hashedAccessToken)
118
+                    await authenticator.verifySessionCookie('siimee_access')
143 119
                 } catch (err) {
144 120
                     this.currentStep = 0
145 121
                     this.goToStep(this.currentStep)

+ 3
- 21
frontend/src/views/VerifyView.vue Parādīt failu

@@ -12,12 +12,13 @@ export default {
12 12
     name: 'VerifyView',
13 13
     async created() {
14 14
         hash = this.$route.params.hashedToken
15
-        hashedAccessToken = this.grabCookie('siimee_access')
15
+        hashedAccessToken = authenticator.grabStoredCookie('siimee_access')
16 16
         try {
17 17
             this.isHashInUrl(hash)
18 18
             await this.doesAccessTokenExist(hashedAccessToken)
19 19
             await this.verifyActiveSession(hash)
20
-            const sessionData = await this.isSessionTokenValid(hash)
20
+            const sessionData =
21
+                await authenticator.verifySessionCookie('siimee_access')
21 22
             await currentProfile.login(
22 23
                 sessionData.profileId,
23 24
                 this.$waveui.notify,
@@ -29,18 +30,6 @@ export default {
29 30
         this.$router.push('/')
30 31
     },
31 32
     methods: {
32
-        grabCookie(cookieKey) {
33
-            const cookies = document.cookie
34
-                .split('; ')
35
-                .reduce((prev, current) => {
36
-                    const [name, ...value] = current.split('=')
37
-                    prev[name] = value.join('=')
38
-                    return prev
39
-                }, {})
40
-            return `${cookieKey}` in cookies
41
-                ? cookies[`${cookieKey}`]
42
-                : undefined
43
-        },
44 33
         isHashInUrl(hash) {
45 34
             if (!hash) throw new Error('URL contains no hash!')
46 35
         },
@@ -54,13 +43,6 @@ export default {
54 43
             if (!sessionData.hashesMatch)
55 44
                 throw new Error('Hash is not in activeSessions!')
56 45
         },
57
-        async isSessionTokenValid(hash) {
58
-            const sessionTokenIsValid =
59
-                await authenticator.validateSession(hash)
60
-            if (sessionTokenIsValid.error) {
61
-                throw new Error(sessionTokenIsValid.error)
62
-            } else return sessionTokenIsValid
63
-        },
64 46
     },
65 47
 }
66 48
 </script>

Notiek ielāde…
Atcelt
Saglabāt