简体   繁体   English

检查密码后重定向页面

[英]Redirect page after checking password

I use the userClicked() in code.gs of my google apps script to save some data if the user password in login.html is correct.如果 login.html 中的用户密码正确,我会在我的 google 应用程序脚本的 code.gs 中使用userClicked()来保存一些数据。 How can I redirect the user to page.html after saving data in line #18?在第 18 行保存数据后,如何将用户重定向到 page.html? I want to redirect only if the password is correct.我只想在密码正确时重定向。 So I can't use simple on the login page.所以我不能在登录页面上使用 simple 。

Code.gs file login.html Code.gs 文件login.html

code.gs代码.gs

function doGet(e) {
  if (!e.parameters.v){
    return HtmlService.createTemplateFromFile("login").evaluate();
  }
  else {
    return HtmlService.createTemplateFromFile(e.parameters['v']).evaluate();
  }  
}

function userClicked(userInfo){
  if (userInfo.userPassword && userInfo.userPassword == userInfo.dbPassword){

    /* save page data in a google spreadsheet */
    var ss = SpreadsheetApp.openById("1OU6y0Iid5r2xGcfxZpUqGzZjZo8Gz7rALkYcajCslN8");      // calls "DB_" spreadsheet 
    var ws = ss.getSheetByName("Sheet1");    
    var lastRow = ws.getRange("A1").getDataRegion().getLastRow();  // get last row of column A
    var lastRow1 = lastRow + 1;    
    ws.getRange("A"+ lastRow1 +":D"+ lastRow1).setValues([[new Date(), userInfo.userName, userInfo.userPassword, userInfo.dbPassword ]]);

  }
}

function include(filename){
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

function lookup(pass){
  var ss = SpreadsheetApp.openById("1gBo8UrCpqtQ5Rf67HCriEDRhJeQuhvPZ1vebeTHndt0");      // calls "Therapists" spreadsheet 
  var ws = ss.getSheetByName("Therapists");
  var data = ws.getRange(1, 4, ws.getLastRow(), 2).getValues();
  var therapistsList =  data.map(function(r){ return r[0];});
  var passwordsList =  data.map(function(r){ return r[1];});
  var position = therapistsList.indexOf(pass);  
  if (position > -1){
    return passwordsList[position];
  }
  else {
    return 'Not Found!';
  }
}

Login.html登录.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <!--Let browser know website is optimized for mobile-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <!--Import Google Icon Font-->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

    <?!= include("css"); ?>
    </head>

    <body>

    <div class="container">

      <p>Login</p>

      <div class="row">
        <div class="input-field col s3">
          <input id="username" type="text" class="validate">
          <label for="username">Username</label>
        </div>
        <div class="input-field col s3">
          <input disabled id="dbPass" type="text" class="validate">
          <label for="dbPass">Database Pass</label>
        </div>

      </div><!-- row -->
      <div class="row">
        <div class="input-field col s3">
          <input id="userPass" type="text" class="validate">
          <label for="userPass">Password</label>
        </div>
      </div><!-- row -->

       <div class="row">
         <button id="btn" class="waves-effect waves-light btn-small blue accent-4"><i class="material-icons left">play_arrow</i>submit</button>
       </div>

    </div> <!-- Container -->

  <!-- Compiled and minified JavaScript -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
  <?!= include("js_"); ?>
  </body>
</html>

add tag and surround inside all your input field and other elements that take values from user.use return attribute with your function name.在所有输入字段和其他元素中添加标签和环绕,这些元素从 user.use 返回属性中获取值以及您的函数名称。 Return attribute does is;返回属性确实是; if your function returns true you can direct return false, you can't redirect如果你的函数返回true,你可以直接返回false,你不能重定向

Ex:前任:

 <form onsubmit="return productsvalidationform();" method="POST" action="AddProductServlet">
         <div class="form-group">                                                          
              <label>Product Name</label><br> <input type="text" required class="form-control" name="ProductName" placeholder="productname" id="productname">

         </div>                     

    </form>

productsvalidationform();产品验证表单(); is the function,This function return true or false.If true we can be redirected to AddProductServlet.In the form tag, include action attribute that describes where you want to go.是函数,这个函数返回true或false。如果为true,我们可以重定向到AddProductServlet。在form标签中,包含描述你要去哪里的action属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM