From a6b6fe95c0fe2aa60ebbfca87fde47e629035c49 Mon Sep 17 00:00:00 2001 From: wakarimasen Date: Wed, 8 Mar 2017 18:28:41 +0100 Subject: [PATCH 1/5] Show visual feedback on login error, redirect on success --- src/components/login_form/login_form.js | 8 ++- src/components/login_form/login_form.vue | 9 ++++ src/modules/users.js | 68 +++++++++++++----------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index 827c704c..2ad5b0b5 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -1,13 +1,17 @@ const LoginForm = { data: () => ({ - user: {} + user: {}, + authError: false }), computed: { loggingIn () { return this.$store.state.users.loggingIn } }, methods: { submit () { - this.$store.dispatch('loginUser', this.user) + this.$store.dispatch('loginUser', this.user).then( + () => { this.$router.push('/main/friends')}, + () => { this.authError = true } + ) } } } diff --git a/src/components/login_form/login_form.vue b/src/components/login_form/login_form.vue index c0273bae..279469ee 100644 --- a/src/components/login_form/login_form.vue +++ b/src/components/login_form/login_form.vue @@ -17,6 +17,9 @@
+
+ +
@@ -39,6 +42,12 @@ margin-top: 1.0em; min-height: 28px; } + + .error { + margin-top: 0em; + margin-bottom: 0em; + background-color: rgba(255, 48, 16, 0.65); + } } diff --git a/src/modules/users.js b/src/modules/users.js index 31731880..a5274480 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -65,40 +65,48 @@ const users = { }) }, loginUser (store, userCredentials) { - const commit = store.commit - commit('beginLogin') - store.rootState.api.backendInteractor.verifyCredentials(userCredentials) - .then((response) => { - if (response.ok) { - response.json() - .then((user) => { - user.credentials = userCredentials - commit('setCurrentUser', user) - commit('addNewUsers', [user]) + return new Promise((resolve, reject) => { + const commit = store.commit + commit('beginLogin') + store.rootState.api.backendInteractor.verifyCredentials(userCredentials) + .then((response) => { + if (response.ok) { + response.json() + .then((user) => { + user.credentials = userCredentials + commit('setCurrentUser', user) + commit('addNewUsers', [user]) - // Set our new backend interactor - commit('setBackendInteractor', backendInteractorService(userCredentials)) + // Set our new backend interactor + commit('setBackendInteractor', backendInteractorService(userCredentials)) - // Start getting fresh tweets. - store.dispatch('startFetching', 'friends') + // Start getting fresh tweets. + store.dispatch('startFetching', 'friends') - // Get user mutes and follower info - store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => { - each(mutedUsers, (user) => { user.muted = true }) - store.commit('addNewUsers', mutedUsers) + // Get user mutes and follower info + store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => { + each(mutedUsers, (user) => { user.muted = true }) + store.commit('addNewUsers', mutedUsers) + }) + + // Fetch our friends + store.rootState.api.backendInteractor.fetchFriends() + .then((friends) => commit('addNewUsers', friends)) }) - - // Fetch our friends - store.rootState.api.backendInteractor.fetchFriends() - .then((friends) => commit('addNewUsers', friends)) - }) - } - commit('endLogin') - }) - .catch((error) => { - console.log(error) - commit('endLogin') - }) + } else { + // Authentication failed + commit('endLogin') + reject() + } + commit('endLogin') + resolve() + }) + .catch((error) => { + console.log(error) + commit('endLogin') + reject() + }) + }) } } } From c0e8111d642ca9f85fbb4091f2ac9e86f4238a58 Mon Sep 17 00:00:00 2001 From: wakarimasen Date: Wed, 8 Mar 2017 19:08:01 +0100 Subject: [PATCH 2/5] Clear username and password field on failed login --- src/components/login_form/login_form.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index 2ad5b0b5..e489f381 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -10,7 +10,11 @@ const LoginForm = { submit () { this.$store.dispatch('loginUser', this.user).then( () => { this.$router.push('/main/friends')}, - () => { this.authError = true } + () => { + this.authError = true + this.user.username = '' + this.user.password = '' + } ) } } From ccc460bb5ed1c8b7338f8a26bdb3029c74b26024 Mon Sep 17 00:00:00 2001 From: wakarimasen Date: Wed, 8 Mar 2017 19:22:56 +0100 Subject: [PATCH 3/5] Give more specific reason for failed login --- src/components/login_form/login_form.js | 4 ++-- src/components/login_form/login_form.vue | 2 +- src/modules/users.js | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index e489f381..bc801397 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -10,8 +10,8 @@ const LoginForm = { submit () { this.$store.dispatch('loginUser', this.user).then( () => { this.$router.push('/main/friends')}, - () => { - this.authError = true + (error) => { + this.authError = error this.user.username = '' this.user.password = '' } diff --git a/src/components/login_form/login_form.vue b/src/components/login_form/login_form.vue index 279469ee..8a32e064 100644 --- a/src/components/login_form/login_form.vue +++ b/src/components/login_form/login_form.vue @@ -18,7 +18,7 @@
- +
diff --git a/src/modules/users.js b/src/modules/users.js index a5274480..482c3b14 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -96,7 +96,11 @@ const users = { } else { // Authentication failed commit('endLogin') - reject() + if (response.status === 401) { + reject('Wrong username or password') + } else { + reject('An error occured, please try again') + } } commit('endLogin') resolve() @@ -104,7 +108,7 @@ const users = { .catch((error) => { console.log(error) commit('endLogin') - reject() + reject('Failed to connect to server, try again') }) }) } From 0810b2d51a6f0fbbfe1604f6d1954cde8ed08290 Mon Sep 17 00:00:00 2001 From: wakarimasen Date: Wed, 8 Mar 2017 19:31:39 +0100 Subject: [PATCH 4/5] Fix typo --- src/modules/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/users.js b/src/modules/users.js index 482c3b14..51643bd1 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -99,7 +99,7 @@ const users = { if (response.status === 401) { reject('Wrong username or password') } else { - reject('An error occured, please try again') + reject('An error occurred, please try again') } } commit('endLogin') From 9511691c9467e26c3237b4a2c936e8a757b3e515 Mon Sep 17 00:00:00 2001 From: shpuld Date: Thu, 9 Mar 2017 02:21:23 +0200 Subject: [PATCH 5/5] Make the error into a div instead of a button to get rid of the hover effects. --- src/components/login_form/login_form.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/login_form/login_form.vue b/src/components/login_form/login_form.vue index 8a32e064..b2fa5341 100644 --- a/src/components/login_form/login_form.vue +++ b/src/components/login_form/login_form.vue @@ -18,7 +18,7 @@
- +
{{authError}}
@@ -44,9 +44,11 @@ } .error { - margin-top: 0em; - margin-bottom: 0em; + border-radius: 5px; + text-align: center; background-color: rgba(255, 48, 16, 0.65); + min-height: 28px; + line-height: 28px; } }