<commit_before><template>
  <auth-container>
    <h1 class="display-1 text-center">{{ $tc('views.auth.login.title') }}</h1>

    <v-alert
      class="mt-2 text-justify"
      text
      dense
      border="left"
      style="hypens:auto"
      color="warning">
      <!-- eslint-disable-next-line vue/no-v-html -->
      <div v-html="$tc('views.auth.login.beta.notice')" />
    </v-alert>
    <v-alert v-if="error"
             outlined
             text
             border="left"
             type="error">
      Login failed
    </v-alert>
    <v-form @submit.prevent="login">
      <e-text-field
        id="inputUsername"
        v-model="username"
        :label="$tc('views.auth.login.username')"
        name="username"
        append-icon="mdi-account-outline"
        :dense="$vuetify.breakpoint.xsOnly"
        type="text" />

      <e-text-field
        id="inputPassword"
        v-model="password"
        :label="$tc('views.auth.login.password')"
        name="password"
        append-icon="mdi-lock-outline"
        :dense="$vuetify.breakpoint.xsOnly"
        type="password" />

      <v-btn type="submit"
             :color="username && password ? 'blue darken-2' : 'blue lighten-4'" block
             :disabled="!(username && password)"
             outlined
             :x-large="$vuetify.breakpoint.smAndUp"
             class="my-4">
        <v-progress-circular v-if="normalLoggingIn" indeterminate size="24" />
        <v-icon v-else>$vuetify.icons.ecamp</v-icon>
        <v-spacer />
        <span>{{ $tc('views.auth.login.provider.ecamp') }}</span>
        <v-spacer />
        <icon-spacer />
      </v-btn>
    </v-form>
    <horizontal-rule :label="$tc('views.auth.login.or')" />
    <v-btn dark
           color="green"
           :x-large="$vuetify.breakpoint.smAndUp"
           block
           outlined
           class="my-4"
           @click="loginPbsMiData">
      <v-icon>$vuetify.icons.pbs</v-icon>
      <v-spacer />
      <span class="text--secondary">{{ $tc('views.auth.login.provider.midata') }}</span>
      <v-spacer />
      <icon-spacer />
    </v-btn>
    <v-btn dark
           color="blue-grey lighten-3"
           :x-large="$vuetify.breakpoint.smAndUp"
           block
           outlined
           class="my-4 text--secondary"
           @click="loginGoogle">
      <v-icon>$vuetify.icons.google</v-icon>
      <v-spacer />
      <span class="text--secondary">{{ $tc('views.auth.login.provider.google') }}</span>
      <v-spacer />
      <icon-spacer />
    </v-btn>
    <p class="mt-8 mb-0 text--secondary text-center">
      {{ $tc('views.auth.login.accountless') }}<br>
      <router-link :to="{ name: 'register' }">{{ $tc('views.auth.login.registernow') }}</router-link>
    </p>
  </auth-container>
</template>

<script>
import { isLoggedIn } from '@/plugins/auth'
import AuthContainer from '@/components/layout/AuthContainer.vue'
import HorizontalRule from '@/components/layout/HorizontalRule.vue'
import IconSpacer from '@/components/layout/IconSpacer.vue'

export default {
  name: 'Login',
  components: {
    IconSpacer,
    HorizontalRule,
    AuthContainer
  },
  beforeRouteEnter (to, from, next) {
    if (isLoggedIn()) {
      next(to.query.redirect || '/')
    } else {
      next()
    }
  },
  data () {
    return {
      username: '',
      password: '',
      error: false,
      normalLoggingIn: false,
      showCredits: true
    }
  },
  mounted () {
    this.$store.commit('setLanguage', this.$i18n.browserPreferredLocale)
  },
  methods: {
    async login () {
      this.normalLoggingIn = true
      this.error = false
      if (await this.$auth.login(this.username, this.password)) {
        this.$router.replace(this.$route.query.redirect || '/')
      } else {
        this.normalLoggingIn = false
        this.error = true
      }
    },
    async loginGoogle () {
      await this.$auth.loginGoogle()
    },
    async loginPbsMiData () {
      await this.$auth.loginPbsMiData()
    }
  }
}
</script>

<style lang="scss" scoped>
</style><commit_msg>Fix login now that hal-json-vuex supports HTTP status 204<commit_after><template>
  <auth-container>
    <h1 class="display-1 text-center">{{ $tc('views.auth.login.title') }}</h1>

    <v-alert
      class="mt-2 text-justify"
      text
      dense
      border="left"
      style="hypens:auto"
      color="warning">
      <!-- eslint-disable-next-line vue/no-v-html -->
      <div v-html="$tc('views.auth.login.beta.notice')" />
    </v-alert>
    <v-alert v-if="error"
             outlined
             text
             border="left"
             type="error">
      Login failed
    </v-alert>
    <v-form @submit.prevent="login">
      <e-text-field
        id="inputUsername"
        v-model="username"
        :label="$tc('views.auth.login.username')"
        name="username"
        append-icon="mdi-account-outline"
        :dense="$vuetify.breakpoint.xsOnly"
        type="text" />

      <e-text-field
        id="inputPassword"
        v-model="password"
        :label="$tc('views.auth.login.password')"
        name="password"
        append-icon="mdi-lock-outline"
        :dense="$vuetify.breakpoint.xsOnly"
        type="password" />

      <v-btn type="submit"
             :color="username && password ? 'blue darken-2' : 'blue lighten-4'" block
             :disabled="!(username && password)"
             outlined
             :x-large="$vuetify.breakpoint.smAndUp"
             class="my-4">
        <v-progress-circular v-if="normalLoggingIn" indeterminate size="24" />
        <v-icon v-else>$vuetify.icons.ecamp</v-icon>
        <v-spacer />
        <span>{{ $tc('views.auth.login.provider.ecamp') }}</span>
        <v-spacer />
        <icon-spacer />
      </v-btn>
    </v-form>
    <horizontal-rule :label="$tc('views.auth.login.or')" />
    <v-btn dark
           color="green"
           :x-large="$vuetify.breakpoint.smAndUp"
           block
           outlined
           class="my-4"
           @click="loginPbsMiData">
      <v-icon>$vuetify.icons.pbs</v-icon>
      <v-spacer />
      <span class="text--secondary">{{ $tc('views.auth.login.provider.midata') }}</span>
      <v-spacer />
      <icon-spacer />
    </v-btn>
    <v-btn dark
           color="blue-grey lighten-3"
           :x-large="$vuetify.breakpoint.smAndUp"
           block
           outlined
           class="my-4 text--secondary"
           @click="loginGoogle">
      <v-icon>$vuetify.icons.google</v-icon>
      <v-spacer />
      <span class="text--secondary">{{ $tc('views.auth.login.provider.google') }}</span>
      <v-spacer />
      <icon-spacer />
    </v-btn>
    <p class="mt-8 mb-0 text--secondary text-center">
      {{ $tc('views.auth.login.accountless') }}<br>
      <router-link :to="{ name: 'register' }">{{ $tc('views.auth.login.registernow') }}</router-link>
    </p>
  </auth-container>
</template>

<script>
import { isLoggedIn } from '@/plugins/auth'
import AuthContainer from '@/components/layout/AuthContainer.vue'
import HorizontalRule from '@/components/layout/HorizontalRule.vue'
import IconSpacer from '@/components/layout/IconSpacer.vue'

export default {
  name: 'Login',
  components: {
    IconSpacer,
    HorizontalRule,
    AuthContainer
  },
  beforeRouteEnter (to, from, next) {
    if (isLoggedIn()) {
      next(to.query.redirect || '/')
    } else {
      next()
    }
  },
  data () {
    return {
      username: '',
      password: '',
      error: false,
      normalLoggingIn: false,
      showCredits: true
    }
  },
  mounted () {
    this.$store.commit('setLanguage', this.$i18n.browserPreferredLocale)
  },
  methods: {
    async login () {
      this.normalLoggingIn = true
      this.error = false
      this.$auth.login(this.username, this.password).then(() => {
        this.$router.replace(this.$route.query.redirect || '/')
      }).catch(() => {
        this.normalLoggingIn = false
        this.error = true
      })
    },
    async loginGoogle () {
      await this.$auth.loginGoogle()
    },
    async loginPbsMiData () {
      await this.$auth.loginPbsMiData()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
{'fraction_non_alphanumeric': 0.17283343577135832, 'fraction_numerical': 0.0043023970497848806, 'mean_word_length': 2.126825518831668, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2210651', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2679, 'n_words': 417}