Преглед изворни кода

:pencil2: Fixed merge issues

juan-filtering-match-pool
tomit4 пре 2 година
родитељ
комит
50a647ca05

+ 0
- 1
frontend/src/components/onboarding/Auth.vue Прегледај датотеку

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

+ 2
- 26
frontend/src/router/guards.js Прегледај датотеку

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
 const loginIfToken = async () => {
17
 const loginIfToken = async () => {
42
-    const sessionData = await verifySession()
18
+    const sessionData = await authenticator.verifySessionCookie('siimee_access')
43
     if (
19
     if (
44
         sessionData?.profileId &&
20
         sessionData?.profileId &&
45
         sessionData?.accessToken &&
21
         sessionData?.accessToken &&
73
     } else {
49
     } else {
74
         nextCb()
50
         nextCb()
75
     }
51
     }
76
-}
52
+        }
77
 
53
 
78
 export { checkLoginStatus }
54
 export { checkLoginStatus }

+ 23
- 0
frontend/src/services/auth.service.js Прегледај датотеку

22
     async removeSession(hashedAccessToken) {
22
     async removeSession(hashedAccessToken) {
23
         return await db.post('/user/removesession', hashedAccessToken, true)
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
 const authenticator = new Authenticator()
49
 const authenticator = new Authenticator()
27
 
50
 

+ 0
- 26
frontend/src/utils/index.js Прегледај датотеку

130
     return surveyResponses
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
 export {
133
 export {
158
     validatorMapping,
134
     validatorMapping,
159
     surveyFactory,
135
     surveyFactory,
165
     randomMedia,
141
     randomMedia,
166
     randomName,
142
     randomName,
167
     randomEmail,
143
     randomEmail,
168
-    grabStoredCookie,
169
-    verifySession,
170
 }
144
 }

+ 2
- 13
frontend/src/views/HomeView.vue Прегледај датотеку

95
             )
95
             )
96
             this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
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
         async logout() {
98
         async logout() {
111
             if (currentProfile.isLoggedIn) {
99
             if (currentProfile.isLoggedIn) {
112
                 currentProfile.logout()
100
                 currentProfile.logout()
113
             }
101
             }
114
-            const hashedAccessToken = this.grabStoredCookie('siimee_access')
102
+            const hashedAccessToken =
103
+                authenticator.grabStoredCookie('siimee_access')
115
             const removedSession = await authenticator.removeSession(
104
             const removedSession = await authenticator.removeSession(
116
                 hashedAccessToken,
105
                 hashedAccessToken,
117
             )
106
             )

+ 3
- 27
frontend/src/views/OnboardingView.vue Прегледај датотеку

38
 import { surveyFactory } from '@/utils'
38
 import { surveyFactory } from '@/utils'
39
 import stepViews from '@/components/onboarding'
39
 import stepViews from '@/components/onboarding'
40
 import SurveyCompleteView from './SurveyCompleteView.vue'
40
 import SurveyCompleteView from './SurveyCompleteView.vue'
41
-let hashedAccessToken = null
42
 
41
 
43
 export default {
42
 export default {
44
     name: 'OnboardingView',
43
     name: 'OnboardingView',
56
     }),
55
     }),
57
     async created() {
56
     async created() {
58
         this.survey = await surveyFactory.createSurvey()
57
         this.survey = await surveyFactory.createSurvey()
59
-        hashedAccessToken = this.grabStoredCookie('siimee_access')
60
         try {
58
         try {
61
-            const sessionData = await this.verifySession(hashedAccessToken)
59
+            const sessionData =
60
+                await authenticator.verifySessionCookie('siimee_access')
62
             if (sessionData) {
61
             if (sessionData) {
63
                 await currentProfile.login(
62
                 await currentProfile.login(
64
                     sessionData.profileId,
63
                     sessionData.profileId,
83
         async goToStep(num) {
82
         async goToStep(num) {
84
             this.currentStep = num
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
         formatResponses(responses) {
85
         formatResponses(responses) {
110
             return responses.map(response => {
86
             return responses.map(response => {
111
                 return {
87
                 return {
139
                 )
115
                 )
140
                 currentProfile._profile.responses = this.responses
116
                 currentProfile._profile.responses = this.responses
141
                 try {
117
                 try {
142
-                    await this.verifySession(hashedAccessToken)
118
+                    await authenticator.verifySessionCookie('siimee_access')
143
                 } catch (err) {
119
                 } catch (err) {
144
                     this.currentStep = 0
120
                     this.currentStep = 0
145
                     this.goToStep(this.currentStep)
121
                     this.goToStep(this.currentStep)

+ 3
- 21
frontend/src/views/VerifyView.vue Прегледај датотеку

12
     name: 'VerifyView',
12
     name: 'VerifyView',
13
     async created() {
13
     async created() {
14
         hash = this.$route.params.hashedToken
14
         hash = this.$route.params.hashedToken
15
-        hashedAccessToken = this.grabCookie('siimee_access')
15
+        hashedAccessToken = authenticator.grabStoredCookie('siimee_access')
16
         try {
16
         try {
17
             this.isHashInUrl(hash)
17
             this.isHashInUrl(hash)
18
             await this.doesAccessTokenExist(hashedAccessToken)
18
             await this.doesAccessTokenExist(hashedAccessToken)
19
             await this.verifyActiveSession(hash)
19
             await this.verifyActiveSession(hash)
20
-            const sessionData = await this.isSessionTokenValid(hash)
20
+            const sessionData =
21
+                await authenticator.verifySessionCookie('siimee_access')
21
             await currentProfile.login(
22
             await currentProfile.login(
22
                 sessionData.profileId,
23
                 sessionData.profileId,
23
                 this.$waveui.notify,
24
                 this.$waveui.notify,
29
         this.$router.push('/')
30
         this.$router.push('/')
30
     },
31
     },
31
     methods: {
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
         isHashInUrl(hash) {
33
         isHashInUrl(hash) {
45
             if (!hash) throw new Error('URL contains no hash!')
34
             if (!hash) throw new Error('URL contains no hash!')
46
         },
35
         },
54
             if (!sessionData.hashesMatch)
43
             if (!sessionData.hashesMatch)
55
                 throw new Error('Hash is not in activeSessions!')
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
 </script>
48
 </script>

Loading…
Откажи
Сачувај