Advertisement
Guest User

web1registerjs

a guest
Jan 8th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JavaScript Document
  2. function registerCheck(){
  3.     var check=1;
  4. // username
  5.     username=document.getElementById("username").value;
  6.     if(username==""){
  7.         document.getElementById("z-username").innerHTML='<span style="color:red;">Bạn chưa nhập tài khoản</span>';
  8.         document.register.username.style.backgroundColor="red";
  9.         check=0;
  10.     }
  11.     else{
  12.         document.getElementById("z-username").innerHTML='<span style="color:#17EB50;">OK!</span>';
  13.         document.register.username.style.backgroundColor="#17EB50";
  14.     }
  15. // password
  16.     //pasword
  17.     password=document.getElementById("password").value;
  18.     if(password==""){
  19.         document.getElementById("z-password").innerHTML='<span style="color:red;">Bạn chưa nhập mật khẩu</span>';
  20.         document.register.password.style.backgroundColor="red";
  21.         check=0;
  22.     }
  23.     else if(password.length>=6 && password.length<=20)
  24.     {
  25.         document.getElementById("z-password").innerHTML='<span style="color:#17EB50;">OK!</span>';
  26.         document.register.password.style.backgroundColor="#17EB50";
  27.     }
  28.     else{
  29.         document.getElementById("z-password").innerHTML='<span style="color:red;">Kích thước mật khẩu bạn nhập không hợp lệ</span>';
  30.         document.register.password.style.backgroundColor="red";
  31.         check=0;
  32.     }
  33.     //repassword
  34.     repassword=document.getElementById("repassword").value;
  35.     if(repassword==""){
  36.         document.getElementById("z-repassword").innerHTML='<span style="color:red;">Bạn chưa nhập mật khẩu lại</span>';
  37.         document.register.repassword.style.backgroundColor="red";
  38.         check=0;
  39.     }
  40.     else if(repassword.length<6 || repassword.length>20){
  41.         document.getElementById("z-repassword").innerHTML='<span style="color:red;">Kích thước mật khẩu bạn nhập không hợp lệ</span>';
  42.         document.register.repassword.style.backgroundColor="red";
  43.         check=0;
  44.     }
  45.     else if(password!=repassword){
  46.         document.getElementById("z-repassword").innerHTML='<span style="color:red;">Mật khẩu nhập lại khác với mật khẩu trên</span>';
  47.         document.register.repassword.style.backgroundColor="red";
  48.         check=0;
  49.     }
  50.     else{
  51.         document.getElementById("z-repassword").innerHTML='<span style="color:#17EB50;">OK!</span>';
  52.         document.register.repassword.style.backgroundColor="#17EB50";
  53.     }
  54. // name
  55.       // fname
  56.     fname=document.getElementById("fname").value;
  57.     if(fname==""){
  58.         document.getElementById("z-fname").innerHTML='<span style="color:red;">Bạn chưa nhập họ và tên lót/đệm</span>';
  59.         document.register.fname.style.backgroundColor="red";
  60.         check=0;
  61.     }
  62.     else{
  63.         document.getElementById("z-fname").innerHTML='<span style="color:#17EB50;">OK!</span>';
  64.         document.register.fname.style.backgroundColor="#17EB50";
  65.     }
  66.     //lname
  67.     lname=document.getElementById("lname").value;
  68.     if(lname==""){
  69.         document.getElementById("z-lname").innerHTML='<span style="color:red;">Bạn chưa nhập tên</span>';
  70.         document.register.lname.style.backgroundColor="red";
  71.         check=0;
  72.     }
  73.     else{
  74.         document.getElementById("z-lname").innerHTML='<span style="color:#17EB50;">OK!</span>';
  75.         document.register.lname.style.backgroundColor="#17EB50";
  76.     }
  77. //email
  78.     email=document.getElementById("email").value;
  79.     var aCong=email.indexOf("@");
  80.     var dauCham = email.lastIndexOf(".");
  81.     if(email==""){
  82.         document.getElementById("z-email").innerHTML='<span style="color:red;">Bạn chưa nhập email</span>';
  83.         document.register.email.style.backgroundColor="red";
  84.         check=0;
  85.     }
  86.     else if( (aCong<1) || (dauCham<aCong+2) || (dauCham+2>email.length) ){
  87.         document.getElementById("z-email").innerHTML='<span style="color:red;">Bạn nhập email chưa hợp lý</span>';
  88.         document.register.email.style.backgroundColor="red";
  89.         check=0;
  90.     }
  91.     else{
  92.         document.getElementById("z-email").innerHTML='<span style="color:#17EB50;">OK!</span>';
  93.         document.register.email.style.backgroundColor="#17EB50";
  94.     }
  95.  
  96.     if(check==1){
  97.         alert("Bạn đã đăng ký thành công");
  98.         //
  99.         var userID=0;
  100.         while (true) {
  101.             if (window.localStorage.getItem('user' + userID)==null)
  102.                 break;
  103.             userID++;
  104.         }
  105.         window.localStorage.setItem ('user'+userID, username);
  106.         window.localStorage.setItem ('user'+userID+'pw', password);
  107.         //
  108.         //return true;
  109.         window.location.href = "index.html";
  110.     }
  111.     else{
  112.         alert("Bạn đăng ký chưa thành công! Bạn cần phải sửa lại thông tin chưa chính xác.");
  113.         //return false;
  114.     }
  115. }
  116. function fixusername(){
  117.     document.register.username.style.backgroundColor="white";
  118. }
  119. function fixpassword(){
  120.     document.register.password.style.backgroundColor="white";
  121. }
  122. function fixrepassword(){  
  123.     document.register.repassword.style.backgroundColor="white";
  124. }
  125. function fixfname(){   
  126.     document.register.fname.style.backgroundColor="white";
  127. }
  128. function fixlname(){   
  129.     document.register.lname.style.backgroundColor="white";
  130. }
  131. function fixemail(){   
  132.     document.register.email.style.backgroundColor="white";
  133. }
  134.  
  135.  
  136.  
  137. // SIGN IN
  138. function signinCheck () {
  139.     username = document.signin.username.value;
  140.     if (username=="") {
  141.         alert ("Vui lòng điền tên đăng nhập");
  142.         return false;
  143.     }
  144.     password = document.signin.password.value;
  145.     if (password=="") {
  146.         alert ("Vui lòng điền mật khẩu");
  147.         return false;
  148.     }
  149.  
  150.     var userID = 0;
  151.  
  152.     while (true) {
  153.         if (window.localStorage.getItem('user' + userID) == username || window.localStorage.getItem('user' + userID)==null)
  154.             break;
  155.         userID++;
  156.     }
  157.  
  158.     if (window.localStorage.getItem('user' + userID)==null) {
  159.         alert ("Tài khoản không tồn tại");
  160.         return false;
  161.     }
  162.  
  163.     if (window.localStorage.getItem ('user'+userID+'pw') != password) {
  164.         alert ("Vui lòng kiểm tra lại tài khoản và mật khẩu");
  165.         return false;
  166.     }
  167.  
  168.     window.localStorage.setItem ('signedinID', userID);
  169.     window.location.href = window.location.href;
  170.     return false;
  171. }
  172.  
  173. function signout () {
  174.     window.localStorage.removeItem ('signedinID');
  175.     window.location.href = "index.html";
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement