Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //let state = initalstate();
  2.  
  3. document.addEventListener("DOMContentLoaded", function () {
  4.     if (document.getElementById('landvue')) {
  5.         Vue.component('modal', {
  6.             template: '#modal-template',
  7.             props: {
  8.                 show: {
  9.                     type: Boolean,
  10.                     required: true,
  11.                     twoWay: true
  12.                 }
  13.             }
  14.         });
  15.         const Login = new Vue({
  16.             el: '#landvue',
  17.             data: function(){
  18.                 return some();
  19.             },
  20.             mounted() {
  21.                 if (localStorage.getItem('username')) {
  22.                     let en64us = window.atob(localStorage.getItem('username'))
  23.                     this.LoginForm.username = en64us;
  24.                     this.IfExistLogin = true;
  25.                 } else {
  26.                     this.IfExistLogin = false;
  27.                 }
  28.             },
  29.             methods: {
  30.                 enableev: function () {
  31.                     document.onkeydown = this.writetwoauth;
  32.                 },
  33.                 writetwoauth(e) {
  34.                     debugger
  35.                     let key = Number(e.key);
  36.                     let checkvals = this.twoauth.one !== null && this.twoauth.two !== null && this.twoauth.three !== null && this.twoauth.four !== null;
  37.  
  38.                    
  39.                     if (this.twoauthmodal == true) {
  40.                         if (e.keyCode === 8) {
  41.                             if (this.twoauth.four >= 0 && this.twoauth.four !== null) {
  42.                                 this.twoauth.four = null
  43.                                 return;
  44.                             } else if (this.twoauth.three >= 0 && this.twoauth.three !== null) {
  45.                                 this.twoauth.three = null
  46.                                 return;
  47.                             } else if (this.twoauth.two >= 0 && this.twoauth.two !== null) {
  48.                                 this.twoauth.two = null
  49.                                 return;
  50.                             } else if (this.twoauth.one >= 0 && this.twoauth.one !== null) {
  51.                                 this.twoauth.one = null
  52.                                 return;
  53.                             }
  54.                         }
  55.  
  56.                         if (!isNaN(key) && this.twoauth.one == null) {
  57.                             this.twoauth.one = e.key;
  58.                         } else if (!isNaN(key) && this.twoauth.two == null) {
  59.                             this.twoauth.two = e.key;
  60.                         } else if (!isNaN(key) && this.twoauth.three == null) {
  61.                             this.twoauth.three = e.key;
  62.                         } else if (!isNaN(key) && this.twoauth.four == null) {
  63.                             this.twoauth.four = e.key;
  64.                            
  65.                                 let otp = "";
  66.                                 otp = this.twoauth.one.toString();
  67.                                 otp = otp + this.twoauth.two.toString();
  68.                                 otp = otp + this.twoauth.three.toString();
  69.                                 otp = otp + this.twoauth.four.toString();
  70.                                 if (this.login_title == "რეგისტრაცია") {
  71.                                     this.RegTwoAuth(otp);
  72.                                 } else {
  73.                                     this.LoginTwoAuth(otp);
  74.                                 }
  75.                            
  76.  
  77.                         }
  78.  
  79.                        
  80.                     } else {
  81.                     }
  82.                    
  83.                 },
  84.                 RegTwoAuth: function (otp) {
  85.                     this.isLoading = true;
  86.                     console.log("RegTwoAuth");
  87.                     let token = document.querySelector('token, input[name=__RequestVerificationToken]').getAttribute('value');
  88.  
  89.                     let data = new FormData();
  90.                     data.append('Phone', this.RegistrationForm.phone);
  91.                     data.append('Otp', otp);
  92.                     data.append('__RequestVerificationToken', token);
  93.  
  94.                     axios.post('/user/SubmitPhoneOtp', data)
  95.                         .then((response) => {
  96.                             console.log(response);
  97.                             this.RegistrationForm.GUID = response.data.model.otpGuid;
  98.                             this.twoauthmodal = false;
  99.                             this.isLoading = false;
  100.                             document.onkeydown = null;
  101.                         })
  102.                         .catch((response) => {
  103.                             console.log(response);
  104.                         })
  105.                     //this.twoauthmodal = true;
  106.                     //this.enableev();
  107.                 },
  108.                 ConfirmRegOTP: function () {
  109.                     this.isLoading = true;
  110.  
  111.                     this.twoauth.one = null;
  112.                     this.twoauth.two = null;
  113.                     this.twoauth.three = null;
  114.                     this.twoauth.four = null;
  115.                     let token = document.querySelector('token, input[name=__RequestVerificationToken]').getAttribute('value');
  116.  
  117.                     let data = new FormData();
  118.                     data.append('Phone', this.RegistrationForm.phone);
  119.                     data.append('__RequestVerificationToken', token);
  120.  
  121.                     axios.post('/user/GeneratePhoneOtp', data)
  122.                         .then((response) => {
  123.                             this.isLoading = false;
  124.                             console.log(response);
  125.                         })
  126.                         .catch((response) => {
  127.                             console.log(response);
  128.                         })
  129.                     this.twoauthmodal = true;
  130.                     this.enableev();
  131.                 },
  132.                 UserRegistration: function () {
  133.                     this.isLoading = true;
  134.                     let token = document.querySelector('token, input[name=__RequestVerificationToken]').getAttribute('value');
  135.  
  136.                     let data = new FormData();
  137.                     data.append('UserName', this.RegistrationForm.username);
  138.                     data.append('PhoneNumber', this.RegistrationForm.phone);
  139.                     data.append('Name', this.RegistrationForm.name);
  140.                     data.append('Surname', this.RegistrationForm.surname);
  141.                     data.append('Email', this.RegistrationForm.mail);
  142.                     data.append('Password', this.RegistrationForm.password);
  143.                     data.append('RepeatPassword', this.RegistrationForm.repassword);
  144.                     data.append('IsApplyTerms', this.RegistrationForm.rules);
  145.                     data.append('OtpToken', this.RegistrationForm.GUID);
  146.                     data.append('__RequestVerificationToken', token);
  147.  
  148.                     axios.post('/user/Registration', data)
  149.                         .then((response) => {
  150.                             console.log(response);
  151.                         })
  152.                         .catch((error) => {
  153.  
  154.                         })
  155.                 },
  156.                 UserLogin: function () {
  157.                     this.isLoading = true;
  158.                     let token = document.querySelector('token, input[name=__RequestVerificationToken]').getAttribute('value');
  159.  
  160.                     let data = new FormData();
  161.                     data.append('UserName', this.LoginForm.username);
  162.                     data.append('Password', this.LoginForm.password);
  163.                     data.append('IsRemember', this.LoginForm.remember);
  164.                     data.append('__RequestVerificationToken', token);
  165.  
  166.                     axios.post('/user/Login', data, {
  167.                         headers: {
  168.                             'Content-Type': "application/json; charset=utf-8",
  169.                         }
  170.                     })
  171.                         .then((response) => {
  172.                             debugger
  173.                             console.log(response);
  174.                             this.isLoading = false;
  175.                             switch (true) {
  176.                                 case (this.LoginForm.username == "" && this.LoginForm.password == ""):
  177.                                     this.errors.fielderror = true;
  178.                                     this.errors.emptyfield.username = true;
  179.                                     this.errors.emptyfield.password = true;
  180.                                     this.errors.errortext = "გთხოვთ შეავსოთ ყველა სავალდებულო ველი";
  181.                                     this.errors.showerror = true;
  182.                                     break;
  183.                                 case (this.LoginForm.username == ""):
  184.                                     this.errors.fielderror = true;
  185.                                     this.errors.emptyfield.password = false;
  186.                                     this.errors.emptyfield.username = true;
  187.                                     this.errors.errortext = "გთხოვთ შეავსოთ ყველა სავალდებულო ველი";
  188.                                     this.errors.showerror = true;
  189.                                     break;
  190.                                 case (this.LoginForm.password == ""):
  191.                                     this.errors.fielderror = true;
  192.                                     this.errors.emptyfield.username = false;
  193.                                     this.errors.emptyfield.password = true;
  194.                                     this.errors.errortext = "გთხოვთ შეავსოთ ყველა სავალდებულო ველი";
  195.                                     this.errors.showerror = true;
  196.                                     break;
  197.                                 case (!response.data.success && response.data.fieldErrors.length > 0 && response.data.fieldErrors[0].fieldName == "UserName"):
  198.                                     this.errors.fielderror = true;
  199.                                     this.errors.emptyfield.username = true;
  200.                                     this.errors.emptyfield.password = false;
  201.                                     this.errors.errortext = "ელ-ფოსტის მისამართი არ áƒáƒ ის სწორი";
  202.                                     this.errors.showerror = true;
  203.                                     break;
  204.                                 case (!response.data.success):
  205.                                     this.errors.showerror = true;
  206.                                     this.errors.emptyfield.username = false;
  207.                                     this.errors.emptyfield.password = false;
  208.                                     this.errors.errortext = response.data.messages[0];
  209.                                     break;
  210.                                 case (response.data.success && !response.data.model.isOtpAuthorization):
  211.                                     this.errors.showerror = false;
  212.                                     if (this.LoginForm.remember) {
  213.                                         let sv64us = window.btoa(this.LoginForm.username)
  214.                                         localStorage.setItem("username", `${sv64us}`)
  215.                                     }
  216.                                     window.location = response.data.redirectUrl;
  217.                                     break;
  218.                                 case (response.data.success && response.data.model.isOtpAuthorization):
  219.                                     this.twoauthmodal = true;
  220.                                     this.enableev();
  221.                                     break;
  222.  
  223.                             }
  224.                         })
  225.                         .catch((response) => {
  226.                             console.log(response)
  227.                         })
  228.                 },
  229.                 LoginTwoAuth(otp) {
  230.                     let token = document.querySelector('token, input[name=__RequestVerificationToken]').getAttribute('value');
  231.  
  232.                     let data = new FormData();
  233.                     data.append('UserName', this.LoginForm.username);
  234.                     data.append('Otp', otp);
  235.                     data.append('Password', this.LoginForm.password);
  236.                     data.append('__RequestVerificationToken', token);
  237.  
  238.                     axios.post('/user/OtpLogin', data, {
  239.                         headers: {
  240.                             'Content-Type': "application/json; charset=utf-8",
  241.                         }
  242.                     })
  243.                         .then((response) => {
  244.                             console.log(response);
  245.                         })
  246.                         .catch((response) => {
  247.                             console.log(response)
  248.                         })
  249.                 },
  250.                 Hinteye() {
  251.                     this.passwordFieldType = this.passwordFieldType === 'password' ? 'text' : 'password'
  252.                     if (this.passwordFieldType == 'text') {
  253.                         this.passeye = "greeneye.svg";
  254.                     } else {
  255.                         this.passeye = "pass_eye.svg";
  256.                     }
  257.                 },
  258.                 PassOnChange: function () {
  259.                     if (this.LoginForm.password === "") {
  260.                         this.InputValidate = false
  261.                     } else {
  262.                         this.InputValidate = true
  263.                     }
  264.                 },
  265.                 ChangeTitle: function () {
  266.                     if (this.login_title == "ავტორიზაცია") {
  267.                         this.RegistrationForm.password = "";
  268.                         this.InputValidate = false
  269.                         this.login_title = "რეგისტრაცია";
  270.                     } else {
  271.                         this.login_title = "ავტორიზაცია";
  272.                     }
  273.                 },
  274.                 removeExistUser: function () {
  275.                     localStorage.removeItem("username");
  276.                     this.LoginForm.username = "";
  277.                     this.IfExistLogin = false;
  278.                 },
  279.                 ProfileDropdown: function () {
  280.                     this.ProfileDropdownCheck = this.ProfileDropdownCheck === true ? false : true
  281.                 },
  282.                 MobileInpChange: function () {
  283.                     console.log("tes");
  284.                     if (this.RegistrationForm.phone === "") {
  285.                         this.RegistrationForm.phoneconfirm = false
  286.                     } else {
  287.                         this.RegistrationForm.phoneconfirm = true
  288.                     }
  289.                 }
  290.             }
  291.             //created() {
  292.             //    if (this.showModal === true) {
  293.             //        document.onkeydown = this.writetwoauth
  294.             //    } else {
  295.  
  296.             //    }
  297.             //}
  298.         });
  299.     } else if (document.getElementById('dashboard')) {
  300.         const dashboard = new Vue({
  301.             el: "#dashboard",
  302.             data: {
  303.                 ProfileDropdownCheck: false
  304.             },
  305.             methods: {
  306.                 ProfileDropdown: function () {
  307.                     this.ProfileDropdownCheck = this.ProfileDropdownCheck === true ? false : true
  308.                 }
  309.             }
  310.         })
  311.     }
  312. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement