Skip to content
Snippets Groups Projects
Signup.vue 2.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • Eliot Berriot's avatar
    Eliot Berriot committed
    <template>
    
    Bat's avatar
    Bat committed
      <div class="main pusher" v-title="'Sign Up'">
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        <div class="ui vertical stripe segment">
          <div class="ui small text container">
    
            <h2><i18next path="Create a funkwhale account"/></h2>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            <form
              v-if="$store.state.instance.settings.users.registration_enabled.value"
              :class="['ui', {'loading': isLoadingInstanceSetting}, 'form']"
              @submit.prevent="submit()">
              <div v-if="errors.length > 0" class="ui negative message">
    
                <div class="header"><i18next path="We cannot create your account"/></div>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
                <ul class="list">
                  <li v-for="error in errors">{{ error }}</li>
                </ul>
              </div>
              <div class="field">
    
                <i18next tag="label" path="Username"/>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
                <input
                ref="username"
                required
                type="text"
                autofocus
                placeholder="Enter your username"
                v-model="username">
              </div>
              <div class="field">
    
                <i18next tag="label" path="Email"/>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
                <input
                ref="email"
                required
                type="email"
                placeholder="Enter your email"
                v-model="email">
              </div>
              <div class="field">
    
                <i18next tag="label" path="Password"/>
    
                <password-input v-model="password" />
    
    Eliot Berriot's avatar
    Eliot Berriot committed
              </div>
    
              <button :class="['ui', 'green', {'loading': isLoading}, 'button']" type="submit"><i18next path="Create my account"/></button>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            </form>
    
            <i18next v-else tag="p" path="Registration is currently disabled on this instance, please try again later."/>
    
    Eliot Berriot's avatar
    Eliot Berriot committed
          </div>
        </div>
      </div>
    </template>
    
    <script>
    import axios from 'axios'
    import logger from '@/logging'
    
    
    import PasswordInput from '@/components/forms/PasswordInput'
    
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    export default {
      name: 'login',
    
      components: {
        PasswordInput
      },
    
    Eliot Berriot's avatar
    Eliot Berriot committed
      props: {
        next: {type: String, default: '/'}
      },
      data () {
        return {
          username: '',
          email: '',
          password: '',
          isLoadingInstanceSetting: true,
          errors: [],
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        }
      },
      created () {
        let self = this
        this.$store.dispatch('instance/fetchSettings', {
          callback: function () {
            self.isLoadingInstanceSetting = false
          }
        })
      },
      methods: {
        submit () {
          var self = this
          self.isLoading = true
          this.errors = []
          var payload = {
            username: this.username,
            password1: this.password,
            password2: this.password,
            email: this.email
          }
          return axios.post('auth/registration/', payload).then(response => {
            logger.default.info('Successfully created account')
            self.$router.push({
              name: 'profile',
              params: {
                username: this.username
              }})
          }, error => {
    
            self.errors = error.backendErrors
    
    Eliot Berriot's avatar
    Eliot Berriot committed
            self.isLoading = false
          })
        }
      }
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    </style>