From 0d8b3c0223278ade586ad471fde3ff9966cddb19 Mon Sep 17 00:00:00 2001 From: Pablo Marco del Pont Date: Wed, 10 Oct 2018 16:28:38 -0300 Subject: [PATCH] =?UTF-8?q?Primera=20versi=C3=B3n=20estable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++ .jshintrc | 64 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ gulpfile.js | 62 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 55 ++++++++++++++++++++++++++++++++++++++++ src/js/app.js | 11 ++++++++ src/js/controller.js | 21 ++++++++++++++++ src/js/route.js | 15 +++++++++++ src/js/service.js | 11 ++++++++ src/views/foca-login.html | 15 +++++++++++ 10 files changed, 260 insertions(+) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 README.md create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/js/app.js create mode 100644 src/js/controller.js create mode 100644 src/js/route.js create mode 100644 src/js/service.js create mode 100644 src/views/foca-login.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d22e37 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/node_modules +/dist +/tmp +package-lock\.json diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..dd429f7 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,64 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + "browser": true, + + // Define globals exposed by jQuery. + "jquery": true, + + // Define globals exposed by Node.js. + "node": true, + + // Allow ES6. + "esversion": 6, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + "camelcase": true, + + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, + + // Enforce tab width of 2 spaces. + "indent": 4, + + // Prohibit use of a variable before it is defined. + "latedef": true, + + // Enforce line length to 100 characters + "maxlen": 100, + + // Require capitalized names for constructor functions. + "newcap": true, + + // Enforce use of single quotation marks for strings. + "quotmark": "single", + + // Enforce placing 'use strict' at the top function scope + "strict": false, + + // Prohibit use of explicitly undeclared variables. + "undef": true, + + // Warn when variables are defined but never used. + "unused": true, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f7fd75 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Login +===== diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..76c615a --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,62 @@ +const templateCache = require('gulp-angular-templatecache'); +const concat = require('gulp-concat'); +const clean = require('gulp-clean'); +const htmlmin = require('gulp-htmlmin'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify-es').default; +const gulp = require('gulp'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); + +var paths = { + srcJS: 'src/js/*.js', + srcViews: 'src/views/*.html', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('templates', function() { + return pump( + [ + gulp.src(paths.srcViews), + htmlmin(), + templateCache('views.js', { + module: 'focaLogin', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-login.js'), + gulp.dest(paths.tmp), + rename('foca-login.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('clean', function(){ + return gulp.src(['tmp', 'dist'], {read: false}) + .pipe(clean()); +}); + +gulp.task('pre-commit', function() { + pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..0ff5f6a --- /dev/null +++ b/package.json @@ -0,0 +1,55 @@ +{ + "name": "foca-login", + "version": "1.0.0", + "description": "Login", + "main": "dist/foca-login.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "gulp uglify", + "pre-commit": [ + "gulp-pre-commit" + ], + "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js" + }, + "repository": { + "type": "git", + "url": "https://192.168.0.11/modulos-npm/foca-login.git" + }, + "author": "Foca Software", + "license": "ISC", + "peerDependencies": { + "angular": "^1.7.x", + "bootstrap": "^4.1.x", + "jquery": "^3.3.x", + "font-awesome": "^4.7.x", + "gulp": "^3.9.x", + "gulp-concat": "2.6.x", + "gulp-jshint": "^2.1.x", + "gulp-rename": "^1.4.x", + "gulp-replace": "^1.0.x", + "gulp-uglify-es": "^1.0.x", + "jshint": "^2.9.x", + "pump": "^3.0.x" + }, + "devDependencies": { + "gulp-connect": "^5.6.1", + "jasmine-core": "3.2.1", + "pre-commit": "^1.2.2" + }, + "dependencies": { + "angular": "1.7.4", + "bootstrap": "4.1.3", + "font-awesome": "4.7.0", + "gulp-angular-templatecache": "2.2.1", + "gulp-clean": "0.4.0", + "gulp-htmlmin": "5.0.1", + "gulp-jshint": "2.1.0", + "gulp-rename": "1.4.0", + "gulp-replace": "1.0.0", + "gulp-sequence": "1.0.0", + "gulp-uglify-es": "1.0.4", + "jquery": "3.3.1", + "jshint": "2.9.6", + "pump": "3.0.0" + } +} diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..6b2b51f --- /dev/null +++ b/src/js/app.js @@ -0,0 +1,11 @@ +angular.module('focaLogin', []) + .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) { + $rootScope.$on('$locationChangeStart', function() { + var idUsuario = $cookies.get('idUsuario'); + if(!idUsuario) { + if($location.path() !== '/login') { + $location.path('/login'); + } + } + }); + }]); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..6be89af --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,21 @@ +angular.module('focaLogin') + .controller('focaLoginController', [ + '$scope', 'focaLoginService', '$location', '$cookies', + function($scope, focaLoginService, $location, $cookies) { + $scope.enviar = function() { + focaLoginService.login($scope.usuario).then(function(datos) { + $cookies.put('idUsuario', $scope.usuario.idUsuario); + $cookies.put('token', datos.data.token); + $location.path('/'); + }); + }; + } + ]) + .controller('focaLogoutController', [ + '$cookies', '$location', + function($cookies, $location) { + $cookies.remove('idUsuario'); + $cookies.remove('token'); + $location.path('/login'); + } + ]); diff --git a/src/js/route.js b/src/js/route.js new file mode 100644 index 0000000..b8295a2 --- /dev/null +++ b/src/js/route.js @@ -0,0 +1,15 @@ +angular.module('focaLogin') + .config([ + '$routeProvider', + function($routeProvider) { + $routeProvider + .when('/login', { + controller: 'focaLoginController', + templateUrl: 'foca-login.html' + }) + .when('/logout', { + controller: 'focaLogoutController', + template: '' + }); + } + ]); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..ea27842 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,11 @@ +angular.module('focaLogin') + .service('focaLoginService', [ + '$http', 'API_ENDPOINT', + function($http, API_ENDPOINT) { + return { + login: function(usuario) { + return $http.post(API_ENDPOINT.URL + '/usuario/login', usuario); + } + }; + } + ]); diff --git a/src/views/foca-login.html b/src/views/foca-login.html new file mode 100644 index 0000000..d5b8a94 --- /dev/null +++ b/src/views/foca-login.html @@ -0,0 +1,15 @@ +
+
+ + + +
+
-- 1.9.1