Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module( 'loginApp',['login.loginService']);
- app.controller('mainCtrl', ['$scope', 'LoginService', function( $scope, LoginService ){
- $scope.invalido = false;
- $scope.cargando = false;
- $scope.mensaje = "";
- $scope.datos = {};
- $scope.ingresar = function( datos ){
- if ( datos.usuario.length < 6) {
- $scope.invalido = true;
- $scope.mensaje = 'Minimo es de 6 Carateres, para el usuario';
- return;
- }else if ( datos.password.length < 8) {
- $scope.invalido = true;
- $scope.mensaje = 'Minimo es de 8 Carateres, para Password';
- return;
- }
- $scope.invalido = false;
- $scope.cargando = true;
- console.log( datos );
- LoginService.login( datos ).then( function( data ) {
- //TODO... continuar
- if ( data.err ) {
- $scope.invalido = true;
- $scope.cargando = false;
- $scope.mensaje = data.mensaje;
- }else{
- console.log( data.mensaje+" "+"desde APP.JS" );
- //window.location = data.url;
- }
- });
- };
- var app = angular.module('login.loginService',[]);
- app.factory('LoginService', ['$http','$q', function( $http, $q ){
- var self = {
- login: function( datos ){
- var d = $q.defer();
- console.log("FUE LLAMADO DESDE EL LOGIN");
- $http({
- method : 'POST',
- url : 'xxx-xxx-xxx',
- header: {'Content-Type':'application/json'},
- data : JSON.stringify(datos)
- }).success(function(data) {
- console.log( data+" "+"Desde Service" );
- d.resolve( data );
- }).error(function( data ) {
- console.log( data+" "+"Desde Service ERROR" );
- });
- console.log("POST done");
- return d.promise;
- }
- };
- return self;
- }]);
- Gson gson = new Gson();
- JsonParser parser = new JsonParser();
- JsonObject obj = (JsonObject) parser.parse(request.getReader());
- String username = "";
- String password = "";
- if (obj.get("usuario") != null & obj.get("password") != null) {
- username = obj.get("usuario").getAsString();
- password = obj.get("password").getAsString();
- }
- System.out.println("Username :" + username);
- System.out.println("Password :" + password);
- Usuario user = new Usuario(username,password);
- ControladorUsuario cu = new ControladorUsuario();
- ModeloUsuario mu = new ModeloUsuario();
- try {
- System.out.println(mu.autenticar(username, password));
- } catch (SQLException ex) {
- Logger.getLogger(login_p2.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- if (mu.autenticar(username, password)) {
- response.setContentType("text/plain");
- response.setCharacterEncoding("UTF-8");
- String responseJSON = gson.toJson(true);
- response.getWriter().write(responseJSON);
- }else{
- //response.sendRedirect("index.jsp");
- System.out.println("incorrecto");
- }
- } catch (SQLException ex) {
- Logger.getLogger(login_p2.class.getName()).log(Level.SEVERE, null, ex);
- }
- processRequest(request, response);
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement