Parcourir la source

:gears: Small User API cleanup + removed one of many onboarding survey step props

juan-auth-overpass
juancarbajal98 il y a 2 ans
Parent
révision
9b3e9382c4

+ 5
- 5
backend/lib/plugins/user.js Voir le fichier

12
 const UserProfilesListRoute = require('../routes/user/list-profiles')
12
 const UserProfilesListRoute = require('../routes/user/list-profiles')
13
 const UserLoginRoute = require('../routes/user/login')
13
 const UserLoginRoute = require('../routes/user/login')
14
 const UserSignupRoute = require('../routes/user/signup')
14
 const UserSignupRoute = require('../routes/user/signup')
15
-const UserEmailRoute = require('../routes/user/email.js')
16
-const UserVerifyActiveRoute = require('../routes/user/verifyactivesession.js')
17
-const UserGetAccessRoute = require('../routes/user/getaccess.js')
18
-const UserValidateSessionRoute = require('../routes/user/validatesession.js')
15
+const UserEmailRoute = require('../routes/user/send-email')
16
+const UserVerifyActiveRoute = require('../routes/user/verify-session')
17
+const UserCreateTokenRoute = require('../routes/user/token')
18
+const UserValidateSessionRoute = require('../routes/user/validate-session')
19
 const UserPassword = require('../routes/user/authentication')
19
 const UserPassword = require('../routes/user/authentication')
20
 
20
 
21
 const UserService = require('../services/user')
21
 const UserService = require('../services/user')
55
         await server.route(UserProfilesListRoute)
55
         await server.route(UserProfilesListRoute)
56
         await server.route(UserEmailRoute)
56
         await server.route(UserEmailRoute)
57
         await server.route(UserVerifyActiveRoute)
57
         await server.route(UserVerifyActiveRoute)
58
-        await server.route(UserGetAccessRoute)
58
+        await server.route(UserCreateTokenRoute)
59
         await server.route(UserValidateSessionRoute)
59
         await server.route(UserValidateSessionRoute)
60
         await server.route(UserPassword)
60
         await server.route(UserPassword)
61
     },
61
     },

backend/lib/routes/user/email.js → backend/lib/routes/user/send-email.js Voir le fichier

14
 
14
 
15
 module.exports = {
15
 module.exports = {
16
     method: 'POST',
16
     method: 'POST',
17
-    path: '/sendemail/',
17
+    path: '/send-email/',
18
     options: {
18
     options: {
19
         ...pluginConfig.docs.get,
19
         ...pluginConfig.docs.get,
20
         tags: ['api'],
20
         tags: ['api'],

backend/lib/routes/user/getaccess.js → backend/lib/routes/user/token.js Voir le fichier

6
     handlerType: 'authentication',
6
     handlerType: 'authentication',
7
     docs: {
7
     docs: {
8
         get: {
8
         get: {
9
-            description: 'gets session token for authentication',
10
-            notes: 'Gets session token for authentication',
9
+            description: 'creates session token for authentication',
10
+            notes: 'Creates session token for authentication',
11
         },
11
         },
12
     },
12
     },
13
 }
13
 }
14
 
14
 
15
 module.exports = {
15
 module.exports = {
16
     method: 'POST',
16
     method: 'POST',
17
-    path: '/getaccess',
17
+    path: '/token',
18
     options: {
18
     options: {
19
         ...pluginConfig.docs.get,
19
         ...pluginConfig.docs.get,
20
         tags: ['api'],
20
         tags: ['api'],

backend/lib/routes/user/validatesession.js → backend/lib/routes/user/validate-session.js Voir le fichier

15
 
15
 
16
 module.exports = {
16
 module.exports = {
17
     method: 'POST',
17
     method: 'POST',
18
-    path: '/validatesession',
18
+    path: '/validate-session',
19
     options: {
19
     options: {
20
         ...pluginConfig.docs.get,
20
         ...pluginConfig.docs.get,
21
         tags: ['api'],
21
         tags: ['api'],

backend/lib/routes/user/verifyactivesession.js → backend/lib/routes/user/verify-session.js Voir le fichier


+ 4
- 4
frontend/src/components/onboarding/Auth.vue Voir le fichier

48
                 password: userPass.val,
48
                 password: userPass.val,
49
             })
49
             })
50
             await this.createProfileForNewUser(newUserId, this.responses)
50
             await this.createProfileForNewUser(newUserId, this.responses)
51
-            const accessToken = await this.getAccessToken({
51
+            const accessToken = await this.createToken({
52
                 ...this.answered,
52
                 ...this.answered,
53
             })
53
             })
54
             console.log('accessToken :=>', accessToken)
54
             console.log('accessToken :=>', accessToken)
55
-            const sessionInfo = await this.authenticator.sendAuthEmail({
55
+            const sessionInfo = await this.authenticator.sendEmail({
56
                 ...this.answered,
56
                 ...this.answered,
57
                 accessToken: accessToken,
57
                 accessToken: accessToken,
58
             })
58
             })
70
                     'User has not answered minimum amount of questions to create profile',
70
                     'User has not answered minimum amount of questions to create profile',
71
                 )
71
                 )
72
         },
72
         },
73
-        async getAccessToken(payload) {
74
-            return await this.authenticator.getAccessToken({
73
+        async createToken(payload) {
74
+            return await this.authenticator.createToken({
75
                 payload,
75
                 payload,
76
             })
76
             })
77
         },
77
         },

+ 7
- 2
frontend/src/components/onboarding/QuestionResponse.vue Voir le fichier

28
             type: Number,
28
             type: Number,
29
             required: true,
29
             required: true,
30
         },
30
         },
31
-        surveyStepsCount: {
32
-            type: Number,
31
+        survey: {
32
+            type: Object,
33
             required: true,
33
             required: true,
34
+            default: () => {},
34
         },
35
         },
35
     },
36
     },
36
     emits: ['update-answers'],
37
     emits: ['update-answers'],
38
         radioItems: [1, 2, 3, 4, 5],
39
         radioItems: [1, 2, 3, 4, 5],
39
         answer: null,
40
         answer: null,
40
         noChoiceMade: null,
41
         noChoiceMade: null,
42
+        surveyStepsCount: null,
41
     }),
43
     }),
44
+    created (){
45
+        this.surveyStepsCount = this.survey?.steps?.length
46
+    },
42
     methods: {
47
     methods: {
43
         onUpdate(index) {
48
         onUpdate(index) {
44
             this.noChoiceMade = false
49
             this.noChoiceMade = false

+ 6
- 6
frontend/src/services/auth.service.js Voir le fichier

4
     constructor() {
4
     constructor() {
5
         this.curentUser = null
5
         this.curentUser = null
6
     }
6
     }
7
-    async sendAuthEmail(answered) {
8
-        return await db.post('/user/sendemail/', answered)
7
+    async sendEmail(answered) {
8
+        return await db.post('/user/send-email/', answered)
9
     }
9
     }
10
-    async verifyAuthSession(hashedToken) {
10
+    async verifySession(hashedToken) {
11
         return await db.get(`/user/verify/${hashedToken}`)
11
         return await db.get(`/user/verify/${hashedToken}`)
12
     }
12
     }
13
-    async getAccessToken(req) {
14
-        return await db.post('/user/getaccess', req, true)
13
+    async createToken(req) {
14
+        return await db.post('/user/token', req, true)
15
     }
15
     }
16
     async validateSession(hashedAccessToken) {
16
     async validateSession(hashedAccessToken) {
17
-        return await db.post('/user/validatesession', hashedAccessToken, true)
17
+        return await db.post('/user/validate-session', hashedAccessToken, true)
18
     }
18
     }
19
 }
19
 }
20
 
20
 

+ 3
- 4
frontend/src/views/OnboardingView.vue Voir le fichier

15
                 :question='step'
15
                 :question='step'
16
                 :responses='responses'
16
                 :responses='responses'
17
                 :survey='survey'
17
                 :survey='survey'
18
-                :surveyStepsCount='survey?.steps?.length'
19
                 @handle-submit='onSubmit'
18
                 @handle-submit='onSubmit'
20
                 @update-answers='updateAnswers'
19
                 @update-answers='updateAnswers'
21
                 v-if='step && currentStep == i'
20
                 v-if='step && currentStep == i'
61
         this.authenticator = new Authenticator()
60
         this.authenticator = new Authenticator()
62
         hashedAccessToken = this.grabStoredCookie('siimee_access')
61
         hashedAccessToken = this.grabStoredCookie('siimee_access')
63
         try {
62
         try {
64
-            const sessionData = await this.verifySession(hashedAccessToken)
63
+            const sessionData = await this.validateSession(hashedAccessToken)
65
             currentProfileId = sessionData.profileId
64
             currentProfileId = sessionData.profileId
66
             this.responses = sessionData.responses
65
             this.responses = sessionData.responses
67
             this.currentStep = this.responses.length + 3
66
             this.currentStep = this.responses.length + 3
90
                 cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
89
                 cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
91
             return cookieVal
90
             return cookieVal
92
         },
91
         },
93
-        async verifySession(hashedAccessToken) {
92
+        async validateSession(hashedAccessToken) {
94
             if (!hashedAccessToken)
93
             if (!hashedAccessToken)
95
                 return console.warn('WARNING :=> accessToken is not defined')
94
                 return console.warn('WARNING :=> accessToken is not defined')
96
             const validatedToken = await this.authenticator.validateSession(
95
             const validatedToken = await this.authenticator.validateSession(
128
                     currentProfileId,
127
                     currentProfileId,
129
                 )
128
                 )
130
                 try {
129
                 try {
131
-                    await this.verifySession(hashedAccessToken)
130
+                    await this.validateSession(hashedAccessToken)
132
                 } catch (err) {
131
                 } catch (err) {
133
                     this.currentStep = 0
132
                     this.currentStep = 0
134
                     this.goToStep(this.currentStep)
133
                     this.goToStep(this.currentStep)

+ 1
- 1
frontend/src/views/VerifyView.vue Voir le fichier

48
                 throw new Error('accessToken not in cookie store!')
48
                 throw new Error('accessToken not in cookie store!')
49
         },
49
         },
50
         async verifyActiveSession(hashedToken) {
50
         async verifyActiveSession(hashedToken) {
51
-            const sessionData = await this.authenticator.verifyAuthSession(
51
+            const sessionData = await this.authenticator.verifySession(
52
                 hashedToken,
52
                 hashedToken,
53
             )
53
             )
54
             if (!sessionData.hashesMatch)
54
             if (!sessionData.hashesMatch)

Chargement…
Annuler
Enregistrer