summaryrefslogtreecommitdiffstats
path: root/src/views
diff options
context:
space:
mode:
Diffstat (limited to 'src/views')
-rw-r--r--src/views/Home.vue2
-rw-r--r--src/views/Login.vue25
-rw-r--r--src/views/Register.vue27
3 files changed, 27 insertions, 27 deletions
diff --git a/src/views/Home.vue b/src/views/Home.vue
index e5b446b..5a2a903 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -16,7 +16,7 @@ export default {
16 16
17 computed: { 17 computed: {
18 get_username() { 18 get_username() {
19 return this.$store.getters.get_user.username 19 return this.$store.getters['get_user'].username
20 } 20 }
21 }, 21 },
22 22
diff --git a/src/views/Login.vue b/src/views/Login.vue
index ae43ecd..cb5c8d8 100644
--- a/src/views/Login.vue
+++ b/src/views/Login.vue
@@ -6,9 +6,8 @@
6 6
7 <input type="submit" value="Login!"> 7 <input type="submit" value="Login!">
8 </form> 8 </form>
9 <p v-for="(mess, key) in messages" :key="key">{{mess}}</p>
10 9
11 <router-link to="/register"> Still don't have account? </router-link> 10 <router-link to="/register"> Still don't have an account? </router-link>
12 11
13 </div> 12 </div>
14</template> 13</template>
@@ -21,25 +20,27 @@ export default {
21 return { 20 return {
22 login: "", 21 login: "",
23 password: "", 22 password: "",
24 messages: []
25 } 23 }
26 }, 24 },
27 methods: { 25 methods: {
28 async log_in(e) { 26 async log_in(e) {
29 e.preventDefault() 27 e.preventDefault()
30 28
31 const data = { 29 const login_data = {
32 "username": this.login, 30 "username": this.login,
33 "password": this.password 31 "password": this.password
34 } 32 }
35 try{ 33
36 const res = await AuthService.login(data) 34 const {data, status} = await AuthService.login(login_data)
37 this.$store.dispatch('login', {token: res.token, user: res.user}) 35
38 this.$router.push('/') 36 if (status === 200) {
39 } catch (error) { 37 this.$store.dispatch('login', {token: data.token, user: data.user})
40 console.log(error.response.data) 38 this.$notify({
41 this.messages.push('Wrong username or password!') 39 type: 'success',
42 } 40 text: 'Success!'
41 })
42 this.$router.push('/')
43 }
43 } 44 }
44 }, 45 },
45 created() { 46 created() {
diff --git a/src/views/Register.vue b/src/views/Register.vue
index c03f5fd..eb382c5 100644
--- a/src/views/Register.vue
+++ b/src/views/Register.vue
@@ -7,9 +7,8 @@
7 7
8 <input type="submit" value="Register!"> 8 <input type="submit" value="Register!">
9 </form> 9 </form>
10 <p v-for="(mess, key) in messages" :key="key">{{mess}}</p>
11 10
12 <router-link to="/login">Already have account?</router-link> 11 <router-link to="/login">Already have an account?</router-link>
13 12
14 </div> 13 </div>
15</template> 14</template>
@@ -23,7 +22,6 @@ export default {
23 login: "", 22 login: "",
24 password: "", 23 password: "",
25 repeat_password: "", 24 repeat_password: "",
26 messages: []
27 } 25 }
28 }, 26 },
29 methods: { 27 methods: {
@@ -32,27 +30,28 @@ export default {
32 30
33 e.preventDefault() 31 e.preventDefault()
34 if(this.password !== this.repeat_password){ 32 if(this.password !== this.repeat_password){
35 this.messages.push("Passwords not equals") 33 this.$notify({
34 type: 'warn',
35 text: 'Passwords not equals',
36 })
36 this.password = "" 37 this.password = ""
37 this.repeat_password = "" 38 this.repeat_password = ""
38 39
39 return null 40 return null
40 } 41 }
41 42
42 const data = { 43 const register_data = {
43 "username": this.login, 44 "username": this.login,
44 "password": this.password 45 "password": this.password
45 } 46 }
46 47
47 try { 48 const { status } = await AuthService.register(register_data)
48 await AuthService.register(data) 49 if (status === 200) {
49 this.messages.push("Success!") 50 this.$notify({
50 }catch (error) { 51 type: 'success',
51 if(error.response.data.username) 52 text:'Register success, you can now login.!'
52 this.messages.push(error.response.data.username[0]) 53 })
53 if (error.response.data.password) 54 this.$router.push('/login')
54 this.messages.push(error.response.data.password[0])
55
56 } 55 }
57 } 56 }
58 }, 57 },