Advertisement
Guest User

Untitled

a guest
Feb 7th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             <template>
  2.     <form id="login" align="center">
  3.         <h1>Вход</h1>
  4.         <div class="inputFields">
  5.             <span class="error" v-if="empty">*Все поля должны быть заполнены.</span>
  6.             <span class="error" v-if="incorrect">*Логин или пароль введены не верно.</span>
  7.             <div class="user-input-wrp">
  8.                 <br/>
  9.                 <input type="text" class="input" id="loginField" name="username" v.model="input.username" v-on:change="updateUsername" autofocus required tabindex="1" />
  10.                 <span class="floating-label">Логин</span>
  11.             </div>
  12.             <div class="user-input-wrp">
  13.                 <br/>
  14.                 <input type="password" class="input" id="passwordField" name="password" v.model="input.password" v-on:keyup.enter="login" v-on:change="updatePassword" required tabindex="2" />
  15.                 <span class="floating-label">Пароль</span>
  16.             </div>
  17.             <button class="button" id="loginButton" form="login" type="button" v-on:keyup.enter="login" v-on:click="login()" tabindex="3"><span>Вход</span></button>
  18.         </div>
  19.         <button class="button" id="registerButton" form="login" type="button" v-on:click="toRegisterPage()" tabindex="4">Еще нет аккаунта? Зарегистрируйтесь!</button>
  20.     </form>
  21. </template>
  22.  
  23. <script>
  24.     import axios from 'axios';
  25.     export default {
  26.         name: 'Login',
  27.         data() {
  28.             return {
  29.                 empty: true,
  30.                 incorrect: false,
  31.                 info: "",
  32.                 input: {
  33.                     username: "",
  34.                     password: ""
  35.                 }
  36.             }
  37.         },
  38.         methods: {
  39.             login() {
  40.                 if(!this.empty) {
  41.                     var this_ = this;
  42.                     axios.post('/api/sign_in/', {username: this.input.username,
  43.                         password: this.input.password})
  44.                         .then(function (response) {
  45.                             localStorage.token = response.data.token;
  46.                             this_.$emit("authenticated", true);
  47.                             this_.$router.replace({ name: "secure" });
  48.                         }).catch(function (error) {
  49.                             console.log(error);
  50.                             this_.incorrect = true;
  51.                         });
  52.                     /*this_.$emit("authenticated", true);
  53.                     this_.$router.replace({ name: "secure" });*/
  54.                 }
  55.             },
  56.             toRegisterPage() {
  57.                 this.$router.replace({ name: "register" });
  58.             },
  59.             updateUsername(event) {
  60.                 this.input.username = event.target.value;
  61.                 this.incorrect = false;
  62.                 if (this.input.username == "" || this.input.password == "") {
  63.                     this.empty = true;
  64.                 }
  65.                 else {
  66.                     this.empty = false;
  67.                 }
  68.             },
  69.             updatePassword(event) {
  70.                 this.input.password = event.target.value;
  71.                 this.incorrect = false;
  72.                 if (this.input.username == "" || this.input.password == "") {
  73.                     this.empty = true;
  74.                 }
  75.                 else {
  76.                     this.empty = false;
  77.                 }
  78.             }
  79.         }
  80.     }
  81. </script>
  82.  
  83. <style scoped>
  84.     #login {
  85.         display: flex;
  86.         flex-direction: column;
  87.         align-items: center;
  88.         justify-content: space-around;
  89.         width: 30%;
  90.         min-width: 300px;
  91.         border: 1px solid #CCCCCC;
  92.         background-color: #FFFFFF;
  93.         margin: auto;
  94.         margin-top: 5vh;
  95.         height: 80vh;
  96.         min-height: 350px;
  97.         padding: 20px;
  98.         font: 20px Calibri;
  99.     }
  100.  
  101.     .input {
  102.         font: 20px Calibri;
  103.         border-left: 0px;
  104.         border-right: 0px;
  105.         border-top: 0px;
  106.         border-bottom: 1px solid #3A78DE;
  107.     }
  108.  
  109.     .button {
  110.         width: 75%;
  111.         font: 20px Calibri;
  112.         color: #FFFFFF;
  113.         border-radius: 2px;
  114.         padding: 4px;
  115.         border: 0px;
  116.         margin: 10px;
  117.         cursor: pointer;
  118.         outline: none !important;
  119.         background-color: #FFF;
  120.     }
  121.  
  122.     button:hover {
  123.         opacity: 0.8;
  124.     }
  125.  
  126.     button:focus {
  127.         outline: none !important
  128.     }
  129.  
  130.     #loginButton {
  131.         background-color: #3A78DE;
  132.         color: white;
  133.         box-shadow: 0.1em 0.1em 5px rgba(122,122,122,0.5);
  134.         transition: all 0.5s;
  135.         cursor: pointer;
  136.     }
  137.     #loginButton span {
  138.         cursor: pointer;
  139.         display: inline-block;
  140.         position: relative;
  141.         transition: 0.5s;
  142.     }
  143.  
  144.     #loginButton span:after {
  145.         content: '\00bb';
  146.         position: absolute;
  147.         opacity: 0;
  148.         top: 0;
  149.         right: -20px;
  150.         transition: 0.5s;
  151.     }
  152.  
  153.     #loginButton:focus span,
  154.     #loginButton:hover span {
  155.         padding-right: 25px;
  156.     }
  157.  
  158.     #loginButton:focus span:after,
  159.     #loginButton:hover span:after {
  160.         opacity: 1;
  161.         right: 0;
  162.     }
  163.  
  164.     #registerButton{
  165.         text-align: left;
  166.         font-size: 15px;
  167.         color: #3A78DE;
  168.     }
  169.  
  170.     input:focus {
  171.         outline: none !important;
  172.     }
  173.     .inputFields {
  174.         width: 100%;
  175.         display: flex;
  176.         align-items: center;
  177.         flex-direction: column;
  178.     }
  179.     .user-input-wrp {
  180.         position: relative;
  181.         width: 75%;
  182.     }
  183.     .user-input-wrp .input{
  184.         width: 100%;
  185.         outline: none;
  186.         border:none;
  187.         border-bottom: 1px solid #3A78DE;
  188.     }
  189.     .user-input-wrp .input:invalid {
  190.         box-shadow: none !important;
  191.         border-bottom: 1px solid red;
  192.     }
  193.     .user-input-wrp .input:focus{
  194.         border-width: medium medium 2px;
  195.     }
  196.     .user-input-wrp .floating-label {
  197.         position: absolute;
  198.         pointer-events: none;
  199.         top: 18px;
  200.         left: 5px;
  201.         transition: 0.15s ease all;
  202.         color: #777;
  203.     }
  204.     .user-input-wrp input:focus ~ .floating-label,
  205.     .user-input-wrp input:not(:focus):valid ~ .floating-label{
  206.         top: 5px;
  207.         left: 0px;
  208.         font-size: 13px;
  209.         opacity: 1;
  210.         color: #000;
  211.     }
  212.     .error {
  213.         font: 13px Colibri;
  214.         width: 75%;
  215.         color: red;
  216.         text-align: left;
  217.     }
  218. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement