Login.vue 2.68 KB
Newer Older
1
<template>
Bat's avatar
Bat committed
2
  <div class="main pusher" v-title="'Log In'">
3
4
5
6
7
8
9
10
11
12
13
14
    <div class="ui vertical stripe segment">
      <div class="ui small text container">
        <h2>Log in to your Funkwhale account</h2>
        <form class="ui form" @submit.prevent="submit()">
          <div v-if="error" class="ui negative message">
            <div class="header">We cannot log you in</div>
            <ul class="list">
              <li v-if="error == 'invalid_credentials'">Please double-check your username/password couple is correct</li>
              <li v-else>An unknown error happend, this can mean the server is down or cannot be reached</li>
            </ul>
          </div>
          <div class="field">
15
            <label>Username or email</label>
16
17
18
19
20
            <input
            ref="username"
            required
            type="text"
            autofocus
21
            placeholder="Enter your username or email"
22
23
24
25
26
27
28
29
30
31
32
33
34
            v-model="credentials.username"
            >
          </div>
          <div class="field">
            <label>Password</label>
            <input
            required
            type="password"
            placeholder="Enter your password"
            v-model="credentials.password"
            >
          </div>
          <button :class="['ui', {'loading': isLoading}, 'button']" type="submit">Login</button>
Eliot Berriot's avatar
Eliot Berriot committed
35
36
37
          <router-link class="ui right floated basic button" :to="{path: '/signup'}">
            Create an account
          </router-link>
38
39
40
41
42
43
44
45
46
47
        </form>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: 'login',
48
  props: {
49
    next: {type: String, default: '/'}
50
  },
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  data () {
    return {
      // We need to initialize the component with any
      // properties that will be used in it
      credentials: {
        username: '',
        password: ''
      },
      error: '',
      isLoading: false
    }
  },
  mounted () {
    this.$refs.username.focus()
  },
  methods: {
    submit () {
      var self = this
      self.isLoading = true
      this.error = ''
      var credentials = {
        username: this.credentials.username,
        password: this.credentials.password
      }
      // We need to pass the component's this context
      // to properly make use of http in the auth service
77
78
      this.$store.dispatch('auth/login', {
        credentials,
79
80
81
        next: '/library',
        onError: error => {
          if (error.response.status === 400) {
82
83
84
85
            self.error = 'invalid_credentials'
          } else {
            self.error = 'unknown_error'
          }
86
        }
87
      }).then(e => {
88
89
90
91
92
93
94
95
96
97
98
        self.isLoading = false
      })
    }
  }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>