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

40
          </div>
41
          <button tabindex="3" :class="['ui', {'loading': isLoading}, 'right', 'floated', 'green', 'button']" type="submit"><i18next path="Login"/></button>
42 43 44 45 46 47 48
        </form>
      </div>
    </div>
  </div>
</template>

<script>
49
import PasswordInput from '@/components/forms/PasswordInput'
50 51

export default {
52
  props: {
53
    next: {type: String, default: '/'}
54
  },
55 56 57
  components: {
    PasswordInput
  },
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  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
      }
82 83
      this.$store.dispatch('auth/login', {
        credentials,
84 85 86
        next: '/library',
        onError: error => {
          if (error.response.status === 400) {
87 88 89 90
            self.error = 'invalid_credentials'
          } else {
            self.error = 'unknown_error'
          }
91
        }
92
      }).then(e => {
93 94 95 96 97 98 99 100 101 102 103
        self.isLoading = false
      })
    }
  }

}
</script>

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