Commit 0d8b3c0223278ade586ad471fde3ff9966cddb19

Authored by Pablo Marco del Pont
0 parents
Exists in master

Primera versión estable.

... ... @@ -0,0 +1,4 @@
  1 +/node_modules
  2 +/dist
  3 +/tmp
  4 +package-lock\.json
... ... @@ -0,0 +1,64 @@
  1 +{
  2 + /*
  3 + * ENVIRONMENTS
  4 + * =================
  5 + */
  6 +
  7 + // Define globals exposed by modern browsers.
  8 + "browser": true,
  9 +
  10 + // Define globals exposed by jQuery.
  11 + "jquery": true,
  12 +
  13 + // Define globals exposed by Node.js.
  14 + "node": true,
  15 +
  16 + // Allow ES6.
  17 + "esversion": 6,
  18 +
  19 + /*
  20 + * ENFORCING OPTIONS
  21 + * =================
  22 + */
  23 +
  24 + // Force all variable names to use either camelCase style or UPPER_CASE
  25 + // with underscores.
  26 + "camelcase": true,
  27 +
  28 + // Prohibit use of == and != in favor of === and !==.
  29 + "eqeqeq": true,
  30 +
  31 + // Enforce tab width of 2 spaces.
  32 + "indent": 4,
  33 +
  34 + // Prohibit use of a variable before it is defined.
  35 + "latedef": true,
  36 +
  37 + // Enforce line length to 100 characters
  38 + "maxlen": 100,
  39 +
  40 + // Require capitalized names for constructor functions.
  41 + "newcap": true,
  42 +
  43 + // Enforce use of single quotation marks for strings.
  44 + "quotmark": "single",
  45 +
  46 + // Enforce placing 'use strict' at the top function scope
  47 + "strict": false,
  48 +
  49 + // Prohibit use of explicitly undeclared variables.
  50 + "undef": true,
  51 +
  52 + // Warn when variables are defined but never used.
  53 + "unused": true,
  54 +
  55 + // Para que funcione en angular
  56 + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"],
  57 + /*
  58 + * RELAXING OPTIONS
  59 + * =================
  60 + */
  61 +
  62 + // Suppress warnings about == null comparisons.
  63 + "eqnull": true
  64 +}
... ... @@ -0,0 +1,2 @@
  1 +Login
  2 +=====
... ... @@ -0,0 +1,62 @@
  1 +const templateCache = require('gulp-angular-templatecache');
  2 +const concat = require('gulp-concat');
  3 +const clean = require('gulp-clean');
  4 +const htmlmin = require('gulp-htmlmin');
  5 +const rename = require('gulp-rename');
  6 +const uglify = require('gulp-uglify-es').default;
  7 +const gulp = require('gulp');
  8 +const pump = require('pump');
  9 +const jshint = require('gulp-jshint');
  10 +
  11 +var paths = {
  12 + srcJS: 'src/js/*.js',
  13 + srcViews: 'src/views/*.html',
  14 + tmp: 'tmp',
  15 + dist: 'dist/'
  16 +};
  17 +
  18 +gulp.task('templates', function() {
  19 + return pump(
  20 + [
  21 + gulp.src(paths.srcViews),
  22 + htmlmin(),
  23 + templateCache('views.js', {
  24 + module: 'focaLogin',
  25 + root: ''
  26 + }),
  27 + gulp.dest(paths.tmp)
  28 + ]
  29 + );
  30 +});
  31 +
  32 +gulp.task('uglify', ['templates'], function() {
  33 + return pump(
  34 + [
  35 + gulp.src([
  36 + paths.srcJS,
  37 + 'tmp/views.js'
  38 + ]),
  39 + concat('foca-login.js'),
  40 + gulp.dest(paths.tmp),
  41 + rename('foca-login.min.js'),
  42 + uglify(),
  43 + gulp.dest(paths.dist)
  44 + ]
  45 + );
  46 +});
  47 +
  48 +gulp.task('clean', function(){
  49 + return gulp.src(['tmp', 'dist'], {read: false})
  50 + .pipe(clean());
  51 +});
  52 +
  53 +gulp.task('pre-commit', function() {
  54 + pump(
  55 + [
  56 + gulp.src(paths.srcJS),
  57 + jshint('.jshintrc'),
  58 + jshint.reporter('default'),
  59 + jshint.reporter('fail')
  60 + ]
  61 + );
  62 +});
... ... @@ -0,0 +1,55 @@
  1 +{
  2 + "name": "foca-login",
  3 + "version": "1.0.0",
  4 + "description": "Login",
  5 + "main": "dist/foca-login.js",
  6 + "scripts": {
  7 + "test": "echo \"Error: no test specified\" && exit 1",
  8 + "compile": "gulp uglify",
  9 + "pre-commit": [
  10 + "gulp-pre-commit"
  11 + ],
  12 + "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js"
  13 + },
  14 + "repository": {
  15 + "type": "git",
  16 + "url": "https://192.168.0.11/modulos-npm/foca-login.git"
  17 + },
  18 + "author": "Foca Software",
  19 + "license": "ISC",
  20 + "peerDependencies": {
  21 + "angular": "^1.7.x",
  22 + "bootstrap": "^4.1.x",
  23 + "jquery": "^3.3.x",
  24 + "font-awesome": "^4.7.x",
  25 + "gulp": "^3.9.x",
  26 + "gulp-concat": "2.6.x",
  27 + "gulp-jshint": "^2.1.x",
  28 + "gulp-rename": "^1.4.x",
  29 + "gulp-replace": "^1.0.x",
  30 + "gulp-uglify-es": "^1.0.x",
  31 + "jshint": "^2.9.x",
  32 + "pump": "^3.0.x"
  33 + },
  34 + "devDependencies": {
  35 + "gulp-connect": "^5.6.1",
  36 + "jasmine-core": "3.2.1",
  37 + "pre-commit": "^1.2.2"
  38 + },
  39 + "dependencies": {
  40 + "angular": "1.7.4",
  41 + "bootstrap": "4.1.3",
  42 + "font-awesome": "4.7.0",
  43 + "gulp-angular-templatecache": "2.2.1",
  44 + "gulp-clean": "0.4.0",
  45 + "gulp-htmlmin": "5.0.1",
  46 + "gulp-jshint": "2.1.0",
  47 + "gulp-rename": "1.4.0",
  48 + "gulp-replace": "1.0.0",
  49 + "gulp-sequence": "1.0.0",
  50 + "gulp-uglify-es": "1.0.4",
  51 + "jquery": "3.3.1",
  52 + "jshint": "2.9.6",
  53 + "pump": "3.0.0"
  54 + }
  55 +}
... ... @@ -0,0 +1,11 @@
  1 +angular.module('focaLogin', [])
  2 + .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) {
  3 + $rootScope.$on('$locationChangeStart', function() {
  4 + var idUsuario = $cookies.get('idUsuario');
  5 + if(!idUsuario) {
  6 + if($location.path() !== '/login') {
  7 + $location.path('/login');
  8 + }
  9 + }
  10 + });
  11 + }]);
src/js/controller.js
... ... @@ -0,0 +1,21 @@
  1 +angular.module('focaLogin')
  2 + .controller('focaLoginController', [
  3 + '$scope', 'focaLoginService', '$location', '$cookies',
  4 + function($scope, focaLoginService, $location, $cookies) {
  5 + $scope.enviar = function() {
  6 + focaLoginService.login($scope.usuario).then(function(datos) {
  7 + $cookies.put('idUsuario', $scope.usuario.idUsuario);
  8 + $cookies.put('token', datos.data.token);
  9 + $location.path('/');
  10 + });
  11 + };
  12 + }
  13 + ])
  14 + .controller('focaLogoutController', [
  15 + '$cookies', '$location',
  16 + function($cookies, $location) {
  17 + $cookies.remove('idUsuario');
  18 + $cookies.remove('token');
  19 + $location.path('/login');
  20 + }
  21 + ]);
... ... @@ -0,0 +1,15 @@
  1 +angular.module('focaLogin')
  2 + .config([
  3 + '$routeProvider',
  4 + function($routeProvider) {
  5 + $routeProvider
  6 + .when('/login', {
  7 + controller: 'focaLoginController',
  8 + templateUrl: 'foca-login.html'
  9 + })
  10 + .when('/logout', {
  11 + controller: 'focaLogoutController',
  12 + template: ''
  13 + });
  14 + }
  15 + ]);
... ... @@ -0,0 +1,11 @@
  1 +angular.module('focaLogin')
  2 + .service('focaLoginService', [
  3 + '$http', 'API_ENDPOINT',
  4 + function($http, API_ENDPOINT) {
  5 + return {
  6 + login: function(usuario) {
  7 + return $http.post(API_ENDPOINT.URL + '/usuario/login', usuario);
  8 + }
  9 + };
  10 + }
  11 + ]);
src/views/foca-login.html
... ... @@ -0,0 +1,15 @@
  1 +<div class="login">
  2 + <form name="login">
  3 + <div class="login-titulo">
  4 + <span>Ingreso de usuario</span>
  5 + </div>
  6 + <div class="login-campo">
  7 + <label>Usuario</label>
  8 + <input type="text" ng-model="usuario.idUsuario" />
  9 + </div>
  10 + <div class="login-campo">
  11 + <label>Contraseña</label>
  12 + <input type="password" ng-model="usuario.clave" ng-keyup="$event.keyCode == 13 && enviar()" />
  13 + </div>
  14 + </form>
  15 +</div>