Просмотр исходного кода

:pencil2: Cleaned up if statements, less nesting

juan_spike
tomit4 3 лет назад
Родитель
Сommit
cca081243e
2 измененных файлов: 26 добавлений и 33 удалений
  1. 1
    1
      backend/lib/services/user.js
  2. 25
    32
      frontend/src/views/OnboardingView.vue

+ 1
- 1
backend/lib/services/user.js Просмотреть файл

@@ -243,9 +243,9 @@ module.exports = class UserService extends Schmervice.Service {
243 243
      */
244 244
     validateToken(token) {
245 245
         const key = this.server.registrations['main-app-plugin'].options.jwtKey
246
-        const decodedToken = Jwt.token.decode(token)
247 246
         // NOTE: reveals email...perhaps unhashed email belongs here instead...
248 247
         try {
248
+            const decodedToken = Jwt.token.decode(token)
249 249
             Jwt.token.verify(decodedToken, key)
250 250
             return { isValid: true, payload: decodedToken.decoded.payload }
251 251
         } catch (err) {

+ 25
- 32
frontend/src/views/OnboardingView.vue Просмотреть файл

@@ -65,39 +65,32 @@ export default {
65 65
     async created() {
66 66
         this.survey = await surveyFactory.createSurvey()
67 67
         this.authenticator = new Authenticator()
68
-        if (document.cookie.length) {
69
-            const sessionToken = this.grabCookie('siimee_session_onboarding')
70
-            if (sessionToken) {
71
-                const sessionData = await this.authenticator.validateJwt(
72
-                    sessionToken,
73
-                )
74
-                // NOTE: Left off here, INCOMPLETE, no ACCESS TOKEN yet, crazy amount of logic here...
75
-                if (sessionData.isValid) {
76
-                    const userEmail = sessionData.payload.email
77
-                    const emailIsInCache =
78
-                        await this.authenticator.checkEmailCache(userEmail)
79
-                    if (emailIsInCache) {
80
-                        const user = await fetchUserByEmail(userEmail)
81
-                        const userId = user.user_id
82
-                        const profilesFromUserId = await fetchProfilesByUserId(
83
-                            userId,
84
-                        )
85
-                        let profileId
86
-                        if (profilesFromUserId.length === 1) {
87
-                            profileId = profilesFromUserId[0].profile_id
88
-                            this.currentProfileId = profileId
89
-                        }
90
-                        const profile = await fetchProfileByProfileId(profileId)
91
-                        profile.responses.forEach(response => {
92
-                            this.responses.push({
93
-                                response_key_id: response.response_key_id,
94
-                                val: response.val,
95
-                            })
96
-                        })
97
-                        this.currentStep = this.responses.length + 3
98
-                        this.goToStep(this.currentStep)
99
-                    }
68
+        const sessionToken = this.grabCookie('siimee_session_onboarding')
69
+        const sessionData = await this.authenticator.validateJwt(sessionToken)
70
+        // NOTE: Left off here, INCOMPLETE, no ACCESS TOKEN yet, crazy amount of logic here...
71
+        if (sessionData.isValid) {
72
+            const userEmail = sessionData.payload.email
73
+            const emailIsInCache = await this.authenticator.checkEmailCache(
74
+                userEmail,
75
+            )
76
+            if (emailIsInCache) {
77
+                const user = await fetchUserByEmail(userEmail)
78
+                const userId = user.user_id
79
+                const profilesFromUserId = await fetchProfilesByUserId(userId)
80
+                let profileId
81
+                if (profilesFromUserId.length === 1) {
82
+                    profileId = profilesFromUserId[0].profile_id
83
+                    this.currentProfileId = profileId
100 84
                 }
85
+                const profile = await fetchProfileByProfileId(profileId)
86
+                profile.responses.forEach(response => {
87
+                    this.responses.push({
88
+                        response_key_id: response.response_key_id,
89
+                        val: response.val,
90
+                    })
91
+                })
92
+                this.currentStep = this.responses.length + 3
93
+                this.goToStep(this.currentStep)
101 94
             }
102 95
         }
103 96
     },

Загрузка…
Отмена
Сохранить