From 720ffaf0083564c85a07d66a6d303f34706add41 Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Thu, 2 Jul 2020 02:50:55 +0300
Subject: feat: start refactoring the code to actually use vuex

This includes creating multiple stores as needed for components and removing all complex states from components (since all those states should be stored in vuex)
---
 src/site/pages/login.vue | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

(limited to 'src/site/pages/login.vue')

diff --git a/src/site/pages/login.vue b/src/site/pages/login.vue
index 514cbc5..3c43755 100644
--- a/src/site/pages/login.vue
+++ b/src/site/pages/login.vue
@@ -63,6 +63,8 @@
 </template>
 
 <script>
+import { mapState } from 'vuex';
+
 export default {
 	name: 'Login',
 	data() {
@@ -74,40 +76,31 @@ export default {
 			isLoading: false
 		};
 	},
-	computed: {
-		config() {
-			return this.$store.state.config;
-		}
-	},
+	computed: mapState(['config', 'auth']),
 	metaInfo() {
 		return { title: 'Login' };
 	},
+	created() {
+		if (this.auth.loggedIn) {
+			this.redirect();
+		}
+	},
 	methods: {
 		async login() {
-			if (this.isLoading) return;
-			if (!this.username || !this.password) {
-				this.$store.dispatch('alert', {
+			if (this.auth.isLoading) return;
+
+			const { username, password } = this;
+			if (!username || !password) {
+				this.$store.dispatch('alert/set', {
 					text: 'Please fill both fields before attempting to log in.',
 					error: true
 				});
 				return;
 			}
-			this.isLoading = true;
-
-			try {
-				const data = await this.$axios.$post(`auth/login`, {
-					username: this.username,
-					password: this.password
-				});
-				this.$axios.setToken(data.token, 'Bearer');
-				document.cookie = `token=${encodeURIComponent(data.token)}`;
-				this.$store.dispatch('login', { token: data.token, user: data.user });
 
+			await this.$store.dispatch('auth/login', { username, password });
+			if (this.auth.loggedIn) {
 				this.redirect();
-			} catch (error) {
-				//
-			} finally {
-				this.isLoading = false;
 			}
 		},
 		/*
@@ -126,7 +119,7 @@ export default {
 				});
 		},*/
 		redirect() {
-			this.$store.commit('loggedIn', true);
+			console.log('redirect');
 			if (typeof this.$route.query.redirect !== 'undefined') {
 				this.$router.push(this.$route.query.redirect);
 				return;
-- 
cgit v1.2.3


From c2dbbe6396540ee9d76991a00f5028b49d221d0c Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Thu, 2 Jul 2020 23:42:02 +0300
Subject: feat: refactor account to use vuex, fix small presentational
 components

---
 src/site/pages/login.vue | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/site/pages/login.vue')

diff --git a/src/site/pages/login.vue b/src/site/pages/login.vue
index 3c43755..cef0868 100644
--- a/src/site/pages/login.vue
+++ b/src/site/pages/login.vue
@@ -99,6 +99,7 @@ export default {
 			}
 
 			await this.$store.dispatch('auth/login', { username, password });
+
 			if (this.auth.loggedIn) {
 				this.redirect();
 			}
@@ -119,7 +120,6 @@ export default {
 				});
 		},*/
 		redirect() {
-			console.log('redirect');
 			if (typeof this.$route.query.redirect !== 'undefined') {
 				this.$router.push(this.$route.query.redirect);
 				return;
-- 
cgit v1.2.3


From fb0bc57542a44dcc94149f393d8a4ff0c2e7902b Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Tue, 7 Jul 2020 02:02:59 +0300
Subject: feat: try fixing THE SHITTY WATERFALL

---
 src/site/pages/login.vue | 46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

(limited to 'src/site/pages/login.vue')

diff --git a/src/site/pages/login.vue b/src/site/pages/login.vue
index cef0868..9e5658d 100644
--- a/src/site/pages/login.vue
+++ b/src/site/pages/login.vue
@@ -10,13 +10,15 @@
 			<div class="columns">
 				<div class="column is-4 is-offset-4">
 					<b-field>
-						<b-input v-model="username"
+						<b-input
+							v-model="username"
 							type="text"
 							placeholder="Username"
 							@keyup.enter.native="login" />
 					</b-field>
 					<b-field>
-						<b-input v-model="password"
+						<b-input
+							v-model="password"
 							type="password"
 							placeholder="Password"
 							password-reveal
@@ -24,12 +26,18 @@
 					</b-field>
 
 					<p class="control has-addons is-pulled-right">
-						<router-link v-if="config.userAccounts"
+						<router-link
+							v-if="config.userAccounts"
 							to="/register"
-							class="is-text">Don't have an account?</router-link>
+							class="is-text">
+							Don't have an account?
+						</router-link>
 						<span v-else>Registration is closed at the moment</span>
-						<button class="button is-primary big ml1"
-							@click="login">login</button>
+						<button
+							class="button is-primary big ml1"
+							@click="login">
+							login
+						</button>
 					</p>
 				</div>
 			</div>
@@ -73,7 +81,7 @@ export default {
 			password: null,
 			mfaCode: null,
 			isMfaModalActive: false,
-			isLoading: false
+			isLoading: false,
 		};
 	},
 	computed: mapState(['config', 'auth']),
@@ -87,21 +95,27 @@ export default {
 	},
 	methods: {
 		async login() {
-			if (this.auth.isLoading) return;
+			if (this.isLoading) return;
 
 			const { username, password } = this;
 			if (!username || !password) {
 				this.$store.dispatch('alert/set', {
 					text: 'Please fill both fields before attempting to log in.',
-					error: true
+					error: true,
 				});
 				return;
 			}
 
-			await this.$store.dispatch('auth/login', { username, password });
-
-			if (this.auth.loggedIn) {
-				this.redirect();
+			try {
+				this.isLoading = true;
+				await this.$store.dispatch('auth/login', { username, password });
+				if (this.auth.loggedIn) {
+					this.redirect();
+				}
+			} catch (e) {
+				this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
+			} finally {
+				this.isLoading = false;
 			}
 		},
 		/*
@@ -118,14 +132,14 @@ export default {
 					this.isLoading = false;
 					this.$onPromiseError(err);
 				});
-		},*/
+		}, */
 		redirect() {
 			if (typeof this.$route.query.redirect !== 'undefined') {
 				this.$router.push(this.$route.query.redirect);
 				return;
 			}
 			this.$router.push('/dashboard');
-		}
-	}
+		},
+	},
 };
 </script>
-- 
cgit v1.2.3


From fd3f6de51a082dcd72c2ef557747e031ef7b9c4a Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Thu, 9 Jul 2020 02:24:40 +0300
Subject: refactor: refactor most of the admin pages to use the store instead
 of internal states

---
 src/site/pages/login.vue | 47 ++++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 19 deletions(-)

(limited to 'src/site/pages/login.vue')

diff --git a/src/site/pages/login.vue b/src/site/pages/login.vue
index 9e5658d..569e9d9 100644
--- a/src/site/pages/login.vue
+++ b/src/site/pages/login.vue
@@ -25,20 +25,32 @@
 							@keyup.enter.native="login" />
 					</b-field>
 
-					<p class="control has-addons is-pulled-right">
-						<router-link
-							v-if="config.userAccounts"
-							to="/register"
-							class="is-text">
-							Don't have an account?
-						</router-link>
-						<span v-else>Registration is closed at the moment</span>
-						<button
-							class="button is-primary big ml1"
-							@click="login">
-							login
-						</button>
-					</p>
+					<p class="control has-addons is-pulled-right" />
+
+					<div class="level">
+						<div class="level-left">
+							<div class="level-item">
+								<router-link
+									v-if="config.userAccounts"
+									to="/register"
+									class="is-text">
+									Don't have an account?
+								</router-link>
+								<span v-else>Registration is closed at the moment</span>
+							</div>
+						</div>
+
+						<div class="level-right">
+							<p class="level-item">
+								<b-button
+									size="is-medium"
+									type="is-lolisafe"
+									@click="login">
+									Login
+								</b-button>
+							</p>
+						</div>
+					</div>
 				</div>
 			</div>
 		</div>
@@ -99,10 +111,7 @@ export default {
 
 			const { username, password } = this;
 			if (!username || !password) {
-				this.$store.dispatch('alert/set', {
-					text: 'Please fill both fields before attempting to log in.',
-					error: true,
-				});
+				this.$notifier.error('Please fill both fields before attempting to log in.');
 				return;
 			}
 
@@ -113,7 +122,7 @@ export default {
 					this.redirect();
 				}
 			} catch (e) {
-				this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
+				this.$notifier.error(e.message);
 			} finally {
 				this.isLoading = false;
 			}
-- 
cgit v1.2.3

