Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <title>TODO supply a title</title>
  10. <meta charset="UTF-8">
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  12. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  13. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  14. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  15. <style>
  16. #teveo, #fueraForm{
  17. visibility: hidden;
  18. }
  19. input{
  20. margin: 0 20px 0 9px;
  21. }
  22. form{
  23. margin: 20px 0 20px 0;
  24. }
  25. #elh2{
  26. display: inline-block;
  27. }
  28. #logout{
  29. margin: 0 0 12px 15px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34.  
  35. <div class="container">
  36. <div class="col-lg-12">
  37.  
  38. <div class="page-header">
  39. <h1>LoginMaven con sesiones</h1>
  40. </div>
  41.  
  42. <div id="adios"></div>
  43.  
  44. <form id="fueraForm" class="form-inline">
  45. <div class="form-group">
  46. <label for="user">User:</label>
  47. <input type="text" class="form-control" id="user" name="user" placeholder="Usuario...">
  48. </div>
  49.  
  50. <div class="form-group">
  51. <label for="pass">Password:</label>
  52. <input type="password" class="form-control" id="pass" name="pass" placeholder="Password...">
  53. </div>
  54. <button id="loguear" type="submit" class="btn btn-primary">Logueate</button>
  55. </form>
  56.  
  57. <div id="errores"></div>
  58.  
  59.  
  60. <div id="teveo">
  61. <span id="elh2"></span>
  62. <button id="logout" type="submit" class="btn btn-primary">Logout</button>
  63. </div>
  64.  
  65. </div>
  66. </div>
  67.  
  68.  
  69.  
  70.  
  71. <script>
  72. $(document).ready(function () {
  73. $.ajax({
  74. url: 'http://localhost:8080/mavenlogin/session?op=check',
  75. type: 'GET',
  76. datatype: 'json',
  77. success: function (data) {
  78. //si existe una sesion, se esconde el formulario de login.
  79. if (data.user != null) {
  80. visualizarSesion();
  81. $("#elh2").empty().append("<h2>Bienvenido: " + data.user + "!</h2>");
  82. } else {
  83. visualizarLogin();
  84. }
  85. $("#loguear").click(function () {
  86. event.preventDefault();
  87. nomUser = $("#user").val();
  88. nomPass = $("#pass").val();
  89. function asd(nomUser, nomPass) {
  90. $.ajax({
  91. url: 'http://localhost:8080/mavenlogin/session?op=login&user=' + nomUser + '&pass=' + nomPass,
  92. type: 'GET',
  93. datatype: 'json',
  94. success: function (data) {
  95.  
  96. if (data.status == 200) {
  97. visualizarSesion();
  98. $("#elh2").empty().append("<h2>Bienvenido: " + data.user + "!</h2>");
  99.  
  100. } else {
  101. $("#errores").html('<p>Error, revise la contrasenya</p>');
  102. }
  103. },
  104. error: function () {
  105. $("#errores").html("<p>Error.</p>");
  106. }
  107. });
  108. }
  109. asd(nomUser, nomPass);
  110.  
  111.  
  112. });
  113.  
  114. $("#logout").click(function () {
  115. event.preventDefault();
  116. $.ajax({
  117. url: 'http://localhost:8080/mavenlogin/session?op=logout',
  118. type: 'GET',
  119. datatype: 'json',
  120. success: function (data) {
  121. if (data.status == 200) {
  122. visualizarLogin();
  123. $("#adios").html("<h3>Has sido desconectado correctamente</h3>");
  124. }
  125. },
  126. error: function () {
  127. $("#errores").html("<p>Error.</p>");
  128. }
  129. });
  130. });
  131.  
  132. function visualizarSesion() {
  133. $("#fueraForm").css("display", "none");
  134. $("#fueraForm").css("visibility", "hidden");
  135. $("#teveo").css("visibility", "visible");
  136. $("#errores").empty();
  137. $("#adios").empty();
  138. }
  139.  
  140. function visualizarLogin() {
  141. $("#fueraForm").css("display", "block");
  142. $("#fueraForm").css("visibility", "visible");
  143. $("#teveo").css("visibility", "hidden");
  144. $("#elh2").empty();
  145. $("#errores").empty();
  146. }
  147. },
  148. error: function () {
  149. $("#errores").html("<p>Error.</p>");
  150. }
  151. });
  152.  
  153.  
  154. });
  155. </script>
  156.  
  157. </body>
  158. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement