Advertisement
Guest User

login

a guest
Mar 26th, 2018
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div id="main-container">
  3.     <div class="layout ">
  4.       <transition name="fade">
  5.         <div v-show="currentState === viewStates.CHOOSE" class="login-choose">
  6.           <h2 class="white-color">Social Network</h2>
  7.           <h6 class="white-color">Don't Sign up, Facebook is better !</h6>
  8.          <div class="">
  9.            <div class="ui inverted white button" @click="currentState = viewStates.LOGIN">Login</div>
  10.            <div class="ui inverted blue button" @click="currentState = viewStates.SIGNUP">Sign up</div>
  11.          </div>
  12.        </div>
  13.      </transition>
  14.      <transition name="fade">
  15.        <div v-show="currentState === viewStates.LOGIN" class="login-login ui blue segment">
  16.          <h2 style="text-align: center">Login</h2>
  17.          <div id="login-form" class="ui form">
  18.            <div class="field">
  19.              <label for="login-email">Email</label>
  20.              <input id="login-email" name="login-email" v-model="loginUser.email" type="email">
  21.            </div>
  22.            <div class="field">
  23.              <label for="login-password">Password</label>
  24.              <input id="login-password" name="login-password" v-model="loginUser.password" type="password">
  25.            </div>
  26.          </div>
  27.          <div class="ui negative message" v-if="loginErrors.length > 0">
  28.            <div class="header" v-for="error in loginErrors">
  29.              {{ error }}
  30.            </div>
  31.          </div>
  32.          <div style="margin-top: 25px; text-align: right">
  33.            <div class="ui black button" @click="currentState = viewStates.CHOOSE">Cancel</div>
  34.            <div class="ui blue button" @click="login" :class="{ 'disabled': !validLoginForm }">Login</div>
  35.          </div>
  36.        </div>
  37.      </transition>
  38.      <transition name="fade">
  39.        <div v-show="currentState === viewStates.SIGNUP" class="login-login ui blue segment">
  40.          <h2 style="text-align: center">Sign up</h2>
  41.          <div id="signup-form" class="ui form">
  42.            <div class="two fields">
  43.              <div class="field">
  44.                <label for="signup-first-name">First Name</label>
  45.                <input id="signup-first-name" name="signup-first-name" v-model="signupUser.firstName" type="text">
  46.              </div>
  47.              <div class="field">
  48.                <label for="signup-last-name">Last Name</label>
  49.                <input id="signup-last-name" name="signup-last-name" v-model="signupUser.lastName" type="text">
  50.              </div>
  51.            </div>
  52.            <div class="field">
  53.              <label for="signup-email">Email</label>
  54.              <input id="signup-email" name="signup-email" v-model="signupUser.email" type="email">
  55.            </div>
  56.            <div class="field">
  57.              <label for="signup-password">Password</label>
  58.              <input id="signup-password" name="signup-password" v-model="signupUser.password" type="password">
  59.            </div>
  60.            <div class="inline fields">
  61.              <label>Gender</label>
  62.              <div class="field">
  63.                <label for="gender-male">Male</label>
  64.                <input type="radio" id="gender-male" v-model="signupUser.gender" value="male">
  65.              </div>
  66.              <div class="field">
  67.                <label for="gender-female">Female</label>
  68.                <input type="radio" id="gender-female" v-model="signupUser.gender" value="female">
  69.              </div>
  70.            </div>
  71.            <div class="field">
  72.              <label for="signup-birthdate">Birthdate</label>
  73.              <input type="date" id="signup-birthdate" name="signup-birthdate"  v-model="signupUser.birthdate">
  74.            </div>
  75.          </div>
  76.          <div class="ui negative message" v-if="signupErrors.length > 0">
  77.            <div class="header" v-for="error in signupErrors">
  78.              {{ error }}
  79.            </div>
  80.          </div>
  81.          <div style="margin-top: 25px; text-align: right">
  82.            <div class="ui black button" @click="currentState = viewStates.CHOOSE">Cancel</div>
  83.            <div class="ui green button" @click="signup" :class="{ 'disabled': !validSignupForm }">Sign up</div>
  84.          </div>
  85.        </div>
  86.      </transition>
  87.    </div>
  88.  </div>
  89. </template>
  90.  
  91. <script>
  92.  export default {
  93.    watch: {
  94.      loginUser: {
  95.        handler: function () {
  96.          this.validLoginForm = $('#login-form').form('is valid')
  97.        },
  98.        deep: true
  99.      },
  100.      signupUser: {
  101.        handler: function () {
  102.          this.validSignupForm = $('#signup-form').form('is valid')
  103.        },
  104.        deep: true
  105.      }
  106.    },
  107.    data () {
  108.      return {
  109.        viewStates: {
  110.          CHOOSE: 0,
  111.          LOGIN: 1,
  112.          SIGNUP: 2
  113.        },
  114.        loginUser: {
  115.          email: null,
  116.          password: null
  117.        },
  118.        signupUser: {
  119.          firstName: null,
  120.          lastName: null,
  121.          gender: 'male',
  122.          birthdate: null,
  123.          email: null,
  124.          password: null
  125.        },
  126.        currentState: 0,
  127.        validLoginForm: false,
  128.        validSignupForm: false,
  129.        loginErrors: [],
  130.        signupErrors: []
  131.      }
  132.    },
  133.    methods: {
  134.      login () {
  135.        if (!this.validLoginForm) return
  136.        let loginData = {
  137.          email: this.loginUser.email,
  138.          password: this.loginUser.password
  139.        }
  140.        this.$auth.login({
  141.          params: loginData,
  142.          rememberMe: true,
  143.          fetchUser: true,
  144.          error: function (error) {
  145.            this.loginErrors = error.body.errors
  146.          }
  147.        })
  148.      },
  149.      signup () {
  150.        if (!this.validSignupForm) return
  151.        let self = this
  152.        let registerData = {
  153.          email: this.signupUser.email,
  154.          password: this.signupUser.password,
  155.          first_name: this.signupUser.firstName,
  156.          last_name: this.signupUser.lastName,
  157.          gender: this.signupUser.gender,
  158.          birthdate: this.signupUser.birthdate
  159.        }
  160.        this.$auth.register({
  161.          params: registerData,
  162.          rememberMe: true,
  163.          fetchUser: true,
  164.          success: function () {
  165.            self.currentState = self.viewStates.LOGIN
  166.          },
  167.          error: function (error) {
  168.            this.signupErrors = error.body.errors.full_messages
  169.          }
  170.        })
  171.      }
  172.    },
  173.    mounted () {
  174.      $('#login-form').form({
  175.        fields: {
  176.          'login-email': 'email',
  177.          'login-password': 'minLength[8]'
  178.        },
  179.        inline: true
  180.      })
  181.      $('#signup-form').form({
  182.        fields: {
  183.          'signup-email': 'email',
  184.          'signup-password': 'minLength[8]',
  185.          'signup-first-name': 'empty',
  186.          'signup-last-name': 'empty',
  187.          'signup-birthdate': 'empty'
  188.        },
  189.        inline: true
  190.      })
  191.    }
  192.  }
  193. </script>
  194.  
  195. <style scoped>
  196.  .fade-enter-active, .fade-leave-active {
  197.    transition: opacity .5s
  198.  }
  199.  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  200.    opacity: 0
  201.  }
  202.  #main-container {
  203.    width: 100%;
  204.    height: 100vh;
  205.    background: url("/static/login-background.jpg") no-repeat center center;
  206.    background-size: cover;
  207.    position: relative;
  208.  }
  209.  #main-container .layout {
  210.    position: absolute;
  211.    top: 0;
  212.    left: 0;
  213.    bottom: 0;
  214.    right: 0;
  215.    width: 100%;
  216.    height: 100%;
  217.    background-color: rgba(0, 0, 0, 0.5);
  218.  }
  219.  #main-container .login-choose,  #main-container .login-login {
  220.    position: absolute;
  221.    top: 50%;
  222.    left: 50%;
  223.    transform: translate(-50%, -50%);
  224.  }
  225.  #main-container .login-choose {
  226.    text-align: center;
  227.  }
  228.  #main-container .login-login {
  229.    width: 450px;
  230.  }
  231.  #main-container .login-choose h2 {
  232.    font-size: 5rem;
  233.  }
  234.  #main-container .login-choose h6 {
  235.    font-size: 1.4rem;
  236.    margin: 20px auto;
  237.  }
  238. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement