entre Desarrolladores

Recibe ayuda de expertos

Registrate y pregunta

Es gratis y fácil

Recibe respuestas

Respuestas, votos y comentarios

Vota y selecciona respuestas

Recibe puntos, vota y da la solución

Pregunta

1voto

Tengo un formulario que valida el usuario con contraseña en una hoja de sheets de google y direcciona a una URL, pero necesito que una vez validado el usuario me envie a una direccion URL escrita en el mismo sheet en la siguiente columna, de tal forma que cuando un usuario se registre el formulario le abra la pagina especial escrita para ese usuario. Es decir si el login fue correcto entonces que me envie a mi URL.

En mi actual codigo el formulario me envia a una URL fija escrita en el codigo, quiero que sea dinamica. Creo que solamente me hace falta una funcion del lado del codigo GS que busque la URL dependiendo del usuario para poder sustituir la URL fija del lado del cliente en el HTML. Les dejo el codigo completo y espero su ayuda. aquí el codigo GS:

function doGet(e) {
 var x = HtmlService.createTemplateFromFile("index");
 var y = x.evaluate();
 var z = y.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
 return z;}

 function checkLogin(username, password) {
 var url = 'https://docs.google.com/spreadsheets/d/1vpJ20I5eJb5GNL84nVx5VqXwbTLMYYxNh0VaOxkl0L8/edit#gid=0';
 var ss= SpreadsheetApp.openByUrl(url);
 var webAppSheet = ss.getSheetByName("DATA");
 var getLastRow =  webAppSheet.getLastRow();
 var found_record = '';
 for(var i = 1; i <= getLastRow; i++){
 if(webAppSheet.getRange(i, 1).getValue() == username && 
 webAppSheet.getRange(i, 2).getValue()== password){
 found_record = 'TRUE';}}
 if(found_record == ''){
 found_record = 'FALSE';}

 return found_record;}

 function AddRecord(usernamee, passwordd, email, phone) {
 var url = 'https://docs.google.com/spreadsheets/d/1vpJ20I5eJb5GNL84nVx5VqXwbTLMYYxNh0VaOxkl0L8/edit#gid=0';
 var ss= SpreadsheetApp.openByUrl(url);
 var webAppSheet = ss.getSheetByName("DATA");
 webAppSheet.appendRow([usernamee,passwordd,email,phone]);}

Aquí el HTML:

<!DOCTYPE html>
 <html>
 <head>
 <base target="_top">
 <script>
 function AddRow(){
 var usernamee = document.getElementById("usernamee").value;
 var passwordd = document.getElementById("passwordd").value;
 var email = document.getElementById("email").value;
 var phone = document.getElementById("phone").value;
 if (usernamee==""|| passwordd==""|| email==""|| phone=="") {
 return false;}
  else {
  google.script.run.AddRecord(usernamee,passwordd,email,phone);
  document.getElementById("page2_id1").className = "page2_id1-off";
  document.getElementById("page3_id1").className = "page3_id1";}}

  function LoginUser(){
  var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
   google.script.run.withSuccessHandler(function(output) 
{
  if(output == 'TRUE')
  {
     var url1 = 'https://stackoverflow.com';
     var winRef = window.open(url1);
     winRef ? google.script.host.close() : window.onload=function(){document.getElementById('url').href = url1;}}
     else if(output == 'FALSE'){
    document.getElementById("errorMessage").innerHTML = "Usuario o contraseña invalida!"; }  }).checkLogin(username, password);}

 function function1(){
 document.getElementById("page1_id1").className = "page1_class1-off";
 document.getElementById("page2_id1").className = "page2_id1";}

 function function3(){ 
 document.getElementById("page3_id1").className = "page3_id1-off";
 document.getElementById("page1_id1").className = "page1_id1";}

 </script>
 <style>

 /*page1*/
 .page1_class1-off{
 display: none;}

 /*page2*/
 .page2_class1{
 display: none;}

 .page2_id1-off{
 display:none;}

 /*page3*/
 .page3_class1{
 display:none;}
 .page3_id1-off{
 display:none;}

 input[type=text]:hover{
 border-bottom:2px solid black;}
 input[type=number]:hover{
 border-bottom:2px solid black;}
 input[type=password]:hover{
 border-bottom:2px solid black;}

 .user{
 display: inline-block;
 width: 75px;
 height: 75px;
 border: 8px solid black;
 border-radius: 50%;
 position: relative;
 overflow: hidden;
 box-sizing: border-box;}

 /*the head/*/
 .user::before{
 content: '';
 display: inline-block;
 width: 24px;
 height: 24px;
 background: black;
 border-radius: 50%;
 position: absolute;
 left: calc(50% - 11px);
 top: 10px;}

 /*the body*/
 .user::after{
 content: '';
 display: inline-block;
 width:50px;
 height:40px;
 background: black;
 border-radius: 50%;
 position: absolute;
 left: calc(50% - 24px);
 top: 39px;}

 </style>
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
 <br><br>
 <!--page1-->
 <center>
 <div class="page1_class1" id="page1_id1" style="background:#E3E0DF;border:2px solid gray;border-radius: 20px;width: 400px;padding-top: 20px;padding-bottom: 30px;padding-left: 30px;padding-right: 30px;"> 
 <h1>Acceso a Panel de Empresa</h1>
 <br>
 <input type="text" id="username" placeholder="Usuario" style="border-top: none;border-right: none;border-left: none;outline: none; text-align: center;font-size:0.9em ;width: 50%;font-weight:bold;background:#FEFEFE"/><br>
 <br>
 <input type="password" id="password" placeholder="Contraseña" style="border-top: none;border-right: none;border-left: none;outline: none; text-align: center;font-size:0.9em ;width: 50%;font-weight:bold;"/>
 <br><span id="errorMessage" style="color: red" ></span><br>
 <input type="submit" value="Inicio" onclick="LoginUser()"  style="float: center;padding-top: 1px;padding-bottom: 3px;padding-left: 10px;padding-right: 10px;font-size: 0.9em;font-weight:bold;" /><br>
 <br><br></br>
 <b>¿ Aún no tienes cuenta ?</b><br></br><input type="button" onClick="function1()" value="Crea una Cuenta" style="margin-top: 10px;font-weight:bold;" />
 </div>

 <!--page2-->
 <div class="page2_class1" id="page2_id1" style="background:none;border:2px solid gray;border-radius: 20px;width: 300px;padding-top: 15px;padding-bottom: 30px;padding-left: 30px;padding-right: 30px;background:#F2F8B1">
 <h1>Crea una Cuenta</h1>
 <input type="text" id="usernamee" placeholder="Nombre Usuario" style="border-top: none;border-right: none;border-left: none;outline: none; text-align: center;font-size:0.9em ;width: 50%;font-weight:bold;"/><br>
 <br>
 <input type="password" id="passwordd" placeholder="Crea Contraseña" style="border-top: none;border-right: none;border-left: none;outline: none; text-align: center;font-size: 0.9;width: 50%;font-weight:bold;" /><br>
 <br>
 <input type="text" id="email" placeholder="Email" style="border-top: none;border-right: none;border-left: none;outline: none; text-align: center;font-size:0.9em ;width: 50%;font-weight:bold;"/><br>
 <br>
 <input type="number" id="phone" placeholder="Teléfono celular." style="border-top: none;border-right: none;border-left: none;outline: none; text-align: center;font-size:0.9em ;width: 50%;font-weight:bold;" /><br><br><br></br>
 <b style="color:red;">La contraseña debe contener letras y números. No funcionará sin letras y números.</b><br><br>
 <input type="submit" value="Crear" onclick="AddRow()" style="float: right;padding-top: 1px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;font-size: 0.9em;font-weight:bold;" />
 <br><br></br>
 </div>

 <!--page3-->
 <div class="page3_class1" id="page3_id1" style="background:none;border:2px solid gray;border-radius: 20px;width: 250px;padding-top: 10px;padding-bottom: 20px;padding-left: 20px;padding-right: 20px;background:#7CF76C"><center>
 <h2> Su cuenta ha sido creada satisfactoriamente. Ingrese a su cuenta</h2>
 <input type="submit"  onClick="function3()" value="Login" style="font-weight:bold;"><br>
 </div> 

 </center>
 </body>
 </html>

Por favor, accede o regístrate para responder a esta pregunta.

Otras Preguntas y Respuestas


...

Bienvenido a entre Desarrolladores, donde puedes realizar preguntas y recibir respuestas de otros miembros de la comunidad.

Conecta