Skip to content
Snippets Groups Projects
Select Git revision
  • b10de1b248c3157563ce93e27dd0e1c03fed5866
  • master default protected
  • replication_test
  • release-1.10 protected
  • dev protected
  • 556-usage-statistics
  • 553-semantic-recommendation-2
  • 553-semantic-recommendation
  • release-1.9 protected
  • 551-init-broker-service-permissions
  • 549-test-oai-pmh
  • 545-saving-multiple-times-breaks-pid-metadata
  • 499-standalone-compute-service-2
  • 539-load-tests
  • hotfix/helm-chart
  • luca_ba_new_interface
  • 534-bug-when-adding-access-to-user-that-is-not-registered-at-dashboard-service
  • release-1.8 protected
  • 533-integrate-semantic-recommendation
  • feature/openshift
  • 518-spark-doesn-t-map-the-headers-correct
  • v1.10.4 protected
  • v1.10.3 protected
  • v1.10.2 protected
  • v1.10.1 protected
  • v1.10.0-rc13 protected
  • v1.10.0-rc12 protected
  • v1.10.0-rc11 protected
  • v1.10.0-rc10 protected
  • v1.10.0-rc9 protected
  • v1.10.0-rc8 protected
  • v1.10.0-rc7 protected
  • v1.10.0-rc6 protected
  • v1.10.0-rc5 protected
  • v1.10.0-rc4 protected
  • v1.10.0-rc3 protected
  • v1.10.0-rc2 protected
  • v1.10.0rc1 protected
  • v1.10.0rc0 protected
  • v1.10.0 protected
  • v1.9.3 protected
41 results

login.vue

Blame
  • login.vue 4.00 KiB
    <template>
      <div>
        <v-form ref="form" v-model="valid" @submit.prevent="submit">
          <v-card v-if="!token" flat tile>
            <v-card-title>
              Login
            </v-card-title>
            <v-card-text>
              <v-alert
                border="left"
                color="info">
                If you need an account, <a @click="signup">create one</a> or if you cannot login, <a @click="forgot">reset</a> your information.
              </v-alert>
              <v-row dense>
                <v-col sm="6">
                  <v-text-field
                    v-model="username"
                    autocomplete="off"
                    autofocus
                    required
                    name="username"
                    :rules="[v => !!v || $t('Required')]"
                    label="Username *" />
                </v-col>
              </v-row>
              <v-row dense>
                <v-col sm="6">
                  <v-text-field
                    v-model="password"
                    autocomplete="off"
                    type="password"
                    required
                    name="password"
                    :rules="[v => !!v || $t('Required')]"
                    label="Password *" />
                </v-col>
              </v-row>
            </v-card-text>
            <v-card-actions>
              <v-btn
                id="login"
                class="mb-2 ml-2"
                :disabled="!valid"
                color="primary"
                type="submit"
                name="submit"
                :loading="loading"
                @click="login">
                Login
              </v-btn>
            </v-card-actions>
          </v-card>
        </v-form>
        <p v-if="token">Already logged-in</p>
      </div>
    </template>
    
    <script>
    import { authenticate, tokenToUser } from '@/api/user'
    export default {
      data () {
        return {
          loading: false,
          error: false, // XXX: `error` is never changed
          valid: false,
          username: 'mweise',
          password: null
        }
      },
      computed: {
        loadingColor () {
          return this.error ? 'red lighten-2' : 'primary'
        },
        token () {
          return this.$store.state.token
        },
        user () {
          return this.$store.state.user
        },
        clientSecret () {
          return this.$config.clientSecret
        },
        config () {
          if (this.token === null) {
            return {}
          }
          return {
            headers: { Authorization: `Bearer ${this.token}` }
          }
        }
      },
      mounted () {
        if (this.$route.query.email_verified !== undefined) {
          console.info('Successfully verified your E-Mail Address')
          this.$toast.success('Successfully verified your E-Mail Address!')
        } else if (this.$route.query.password_reset !== undefined) {
          console.info('Successfully reset password')
          this.$toast.success('Successfully reset password!')
        }
      },
      methods: {
        submit () {
          this.$refs.form.validate()
        },
        async login () {
          try {
            this.loading = true
            const res = await authenticate(this.clientSecret, this.username, this.password)
            console.debug('login user', res.data)
            this.$store.commit('SET_TOKEN', res.data.access_token)
            const user = tokenToUser(this.token)
            console.debug('user', user)
            this.$store.commit('SET_USER', user)
            this.$vuetify.theme.dark = user?.theme_dark || false
            await this.$router.push({ path: this.$route.query.redirect ? this.$route.query.redirect : '/container' })
          } catch (error) {
            console.error('Failed to login', error)
            const { status } = error.response
            if (status === 418) {
              this.$toast.error('Check your inbox and confirm your e-mail address')
              console.error('user has not confirmed e-mail', error)
            } else if (status === 404) {
              this.$toast.error('Username not found')
              console.error('user has not confirmed e-mail', error)
            } else {
              this.$toast.error('Login not successful')
              console.error('login user failed', error)
            }
            this.loading = false
          }
        },
        signup () {
          this.$router.push('/signup')
        },
        forgot () {
          this.$router.push('/forgot')
        }
      }
    }
    </script>