Blame view

api/dashboard/src/pages/login.vue 3.36 KB
0d8c0f816   Thanasis Naskos   initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  <template>
    <b-container>
      <b-col sm="8" md="6" lg="4" class="mx-auto">
        <b-card class="login-card">
          <form @submit.prevent="login">
            <h1 class="title text-muted pb-3">
              KEA
            </h1>
            <b-form-group>
              <b-input-group class="input-group-seamless no-border" :class="{ 'is-invalid': form.invalid('email') }">
                <b-input-group-prepend>
                  <span class="input-group-text">
                    <fa icon="envelope" :class="{ 'text-danger': form.feedback('email') }" />
                  </span>
                </b-input-group-prepend>
                <b-form-input v-model="form.email"
                              type="email"
                              name="email"
                              required
                              :state="form.state('email')"
                              placeholder="Email"
                />
              </b-input-group>
              <b-form-invalid-feedback :state="form.state('email')">
                <div v-html="form.feedback('email')" />
              </b-form-invalid-feedback>
            </b-form-group>
            <b-form-group>
              <b-input-group class="input-group-seamless no-border" :class="{ 'is-invalid': form.invalid('password') }">
                <b-input-group-prepend>
                  <span class="input-group-text">
                    <fa icon="lock" :class="{ 'text-danger': form.feedback('password') }" />
                  </span>
                </b-input-group-prepend>
                <b-form-input v-model="form.password"
                              type="password"
                              name="password"
                              required
                              :state="form.state('password')"
                              placeholder="Password"
                />
              </b-input-group>
            </b-form-group>
            <b-button type="submit" block variant="primary" class="w-100" :disabled="form.busy">
              <b-spinner v-if="form.busy" class="spinner-center" small />
              Login
            </b-button>
          </form>
        </b-card>
      </b-col>
    </b-container>
  </template>
  
  <script>
  import Form from '~/utils/form'
  export default {
    name: 'Login',
    layout: 'public',
    middleware: 'guest',
    data: () => ({
        form: new Form({
            email: '',
            password: ''
        })
    }),
  
    methods: {
      async login () {
        let data
  
        // Submit the form.
        try {
            const response = await this.form.post('/login')
            data = response.data
        } catch (e) {
            return
        }
  
        // Save the token.
        this.$store.dispatch('auth/saveToken', {
            token: data.token,
            remember: this.remember
        })
  
        // Fetch the user.
        await this.$store.dispatch('auth/fetchUser')
  
        // Redirect home.
        this.$router.push({ name: 'panel.dashboard' })
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
    .login-card {
      width: 390px;
      background: #fff;
      border-radius: 10px;
      overflow: hidden;
      padding: 10px 25px 10px 25px;
      box-shadow: 0 5px 10px 0px rgba(0, 0, 0, 0.1);
      -moz-box-shadow: 0 5px 10px 0px rgba(0, 0, 0, 0.1);
      -webkit-box-shadow: 0 5px 10px 0px rgba(0, 0, 0, 0.1);
      -o-box-shadow: 0 5px 10px 0px rgba(0, 0, 0, 0.1);
      -ms-box-shadow: 0 5px 10px 0px rgba(0, 0, 0, 0.1);
    }
    .title {
        display: block;
        line-height: 1.2;
        text-align: center;
    }
  </style>