Advertisement
Guest User

Untitled

a guest
Jun 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. var app = angular.module( 'loginApp',['login.loginService']);
  2. app.controller('mainCtrl', ['$scope', 'LoginService', function( $scope, LoginService ){
  3.  
  4. $scope.invalido = false;
  5. $scope.cargando = false;
  6. $scope.mensaje = "";
  7.  
  8. $scope.datos = {};
  9.  
  10. $scope.ingresar = function( datos ){
  11. if ( datos.usuario.length < 6) {
  12. $scope.invalido = true;
  13. $scope.mensaje = 'Minimo es de 6 Carateres, para el usuario';
  14. return;
  15. }else if ( datos.password.length < 8) {
  16. $scope.invalido = true;
  17. $scope.mensaje = 'Minimo es de 8 Carateres, para Password';
  18. return;
  19. }
  20.  
  21. $scope.invalido = false;
  22. $scope.cargando = true;
  23. console.log( datos );
  24.  
  25. LoginService.login( datos ).then( function( data ) {
  26. //TODO... continuar
  27. if ( data.err ) {
  28. $scope.invalido = true;
  29. $scope.cargando = false;
  30. $scope.mensaje = data.mensaje;
  31. }else{
  32. console.log( data.mensaje+" "+"desde APP.JS" );
  33. //window.location = data.url;
  34. }
  35. });
  36.  
  37. };
  38.  
  39. var app = angular.module('login.loginService',[]);
  40. app.factory('LoginService', ['$http','$q', function( $http, $q ){
  41. var self = {
  42.  
  43. login: function( datos ){
  44.  
  45. var d = $q.defer();
  46.  
  47. console.log("FUE LLAMADO DESDE EL LOGIN");
  48.  
  49. $http({
  50. method : 'POST',
  51. url : 'xxx-xxx-xxx',
  52. header: {'Content-Type':'application/json'},
  53. data : JSON.stringify(datos)
  54.  
  55. }).success(function(data) {
  56. console.log( data+" "+"Desde Service" );
  57. d.resolve( data );
  58. }).error(function( data ) {
  59. console.log( data+" "+"Desde Service ERROR" );
  60. });
  61. console.log("POST done");
  62. return d.promise;
  63. }
  64.  
  65. };
  66.  
  67. return self;
  68.  
  69.  
  70. }]);
  71.  
  72. Gson gson = new Gson();
  73. JsonParser parser = new JsonParser();
  74. JsonObject obj = (JsonObject) parser.parse(request.getReader());
  75.  
  76. String username = "";
  77. String password = "";
  78.  
  79. if (obj.get("usuario") != null & obj.get("password") != null) {
  80. username = obj.get("usuario").getAsString();
  81. password = obj.get("password").getAsString();
  82. }
  83.  
  84. System.out.println("Username :" + username);
  85. System.out.println("Password :" + password);
  86.  
  87. Usuario user = new Usuario(username,password);
  88. ControladorUsuario cu = new ControladorUsuario();
  89.  
  90. ModeloUsuario mu = new ModeloUsuario();
  91. try {
  92. System.out.println(mu.autenticar(username, password));
  93. } catch (SQLException ex) {
  94. Logger.getLogger(login_p2.class.getName()).log(Level.SEVERE, null, ex);
  95. }
  96. try {
  97. if (mu.autenticar(username, password)) {
  98. response.setContentType("text/plain");
  99. response.setCharacterEncoding("UTF-8");
  100. String responseJSON = gson.toJson(true);
  101. response.getWriter().write(responseJSON);
  102. }else{
  103. //response.sendRedirect("index.jsp");
  104. System.out.println("incorrecto");
  105. }
  106. } catch (SQLException ex) {
  107. Logger.getLogger(login_p2.class.getName()).log(Level.SEVERE, null, ex);
  108. }
  109.  
  110. processRequest(request, response);
  111. }
  112.  
  113. /**
  114. * Returns a short description of the servlet.
  115. *
  116. * @return a String containing servlet description
  117. */
  118. @Override
  119. public String getServletInfo() {
  120. return "Short description";
  121. }// </editor-fold>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement