Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. <script>
  2. //Control login.
  3. $(document).ready(function() {
  4.  
  5. $(document).on('submit', '#frm-login', function() {
  6. //Data form.
  7. var data = $(this).serialize();
  8. //Ajax
  9. $.ajax({
  10. type: 'POST',
  11. url : 'system/login/login.ini.php',
  12. data: data,
  13.  
  14. success: function(data) {
  15. $("#msg-frm-login").html(data);
  16. }
  17. });
  18. return false;
  19. });
  20.  
  21. });
  22. </script>
  23.  
  24. <form id="frm-login" method="POST">
  25. <?php
  26. //Sino recargo manual en el intento 6, no se activa la sesión...
  27. if (isset($_SESSION['captcha_control'])) {
  28. ?>
  29. <div class="input-captcha center">
  30. <img src='system/login/captcha_code.php' height="36" />
  31. </div>
  32. <input name='captcha_code' type='text' placeholder='Codigo captcha' />
  33. <?php
  34. }
  35. ?>
  36.  
  37. <input type="text" name="email" placeholder="Correo electrónico" />
  38. <input type="password" name="password" placeholder="Contraseña" />
  39.  
  40.  
  41. <button type="submit">Iniciar sesión</button>
  42. </form>
  43.  
  44. <div id="msg-frm-login"><!-- Respuesta AJAX --></div>
  45.  
  46. <?php
  47. //Conexión.
  48. require_once'../database/conect.ini.php';
  49. require_once'class.login.php';
  50.  
  51. $frm_email = $frm_password = NULL;
  52.  
  53. if (isset($_POST)) {
  54. //Obtengo datos formulario
  55. $frm_email = $_POST['email'] ?: '';
  56. $frm_password = $_POST['password'] ?: '';
  57. //En caso de existir la sesio, captcha obtenemos el dato captcha.
  58. if (isset($_SESSION['captcha_control'])) {
  59. $frm_captcha_code = $_POST['captcha_code'] ?: '';
  60. } else { //Resteamos a 0.
  61. $frm_captcha_code = NULL;
  62. }
  63.  
  64. //Nueva instancia, obteniendo valores para el constructor.
  65. $login = new Login($frm_email,$frm_password,$frm_captcha_code);
  66.  
  67. //Metodo.
  68. $login->validate_user();
  69.  
  70. //Mensaje
  71. echo $login->msg;
  72. }
  73. ?>
  74.  
  75. //Funcion - comprobamos intentos fallidos mediante el usario.
  76. protected function attempt() {
  77. //Conexion MySQL.
  78. $c = new Conexion();
  79.  
  80. $sql = "SELECT count(*) n FROM loginLog WHERE username = ? AND fecha > ? and msg = 'Error de password'";
  81. $stmt = $c->prepare($sql);
  82. $stmt->bind_param('ss', $this->email, $this->nowDiff);
  83. $stmt->execute();
  84. $resultado = $stmt->get_result();
  85.  
  86. if ($resultado) {
  87. $rows = $resultado->fetch_assoc();
  88.  
  89. // Si es igual a 6 muestramos captcha y devolvemos false
  90. if ($this->attempt_captcha == $rows['n']) {
  91.  
  92. $this->loginLog($this->email, $this->now, 'Verificar código captcha' );
  93. $_SESSION['captcha_control'] = true;
  94. // ///////////////////////////////////////////////////////////
  95. // Si no recargo no se activa la session captcha en login.php, existe alguna
  96. // manera para poder lograrlo sin un reload o location.
  97. //////////////////////////////////////////////////////////////
  98.  
  99. //Esto es lo que quiero evitar, ¿como podria devolvar al AJAX una sesión?
  100. // echo '<script>window.location="login.php"</script>';
  101.  
  102. return false;
  103.  
  104. } else {
  105. // Bloquamos acceso por un tiempo de 60seg. y devolvemos false.
  106. $this->loginLog($this->email, $this->now, 'Login bloqueado durante '.$this->attempt_time);
  107. return false;
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement