Compare commits
60 Commits
settingUpT
...
genericAss
| Author | SHA1 | Date | |
|---|---|---|---|
| 1500aef977 | |||
| 112f78c1de | |||
| 08702b2cdf | |||
| 21013cf6ac | |||
| 7cf083a612 | |||
| d4135188bd | |||
| 6d29ac3f23 | |||
| 0449f202ef | |||
| 23868b60ee | |||
| 8a2d5b2afa | |||
| 7ceb2aad93 | |||
| 3902435690 | |||
| f16e9fe72c | |||
| d2b9163537 | |||
| 403541580d | |||
| 663ea7cc3e | |||
| f93b41f14e | |||
| 24f1ce1ed7 | |||
| b25346e3d5 | |||
| f2237d9209 | |||
| 7fc9ca8c75 | |||
| 97fca1d7d3 | |||
| 058e19a49a | |||
| bffeb6e9f4 | |||
| 9a3e876afe | |||
| dadea504d0 | |||
| 1390427ec0 | |||
| 6c4e42e337 | |||
| f4d1ce1ab7 | |||
| ba307555f0 | |||
| 57ee1fbd72 | |||
| 63a7186464 | |||
| 4a8df33184 | |||
| 0deb89ed53 | |||
| f441696b96 | |||
| 666b17c0dc | |||
| 30420975c4 | |||
| 2d3f52372c | |||
| 3d7a574396 | |||
| 90f11867a5 | |||
| 69b636620a | |||
| 304e3045c7 | |||
| 692f52b533 | |||
| 6b289695c7 | |||
| 120e07b315 | |||
| 59472e5650 | |||
| fea0587ceb | |||
| 882a9ccad1 | |||
| e033e1ce58 | |||
| 1a4440a99f | |||
| 816b1e356a | |||
| d7be1f1d9c | |||
| 09f11ebe49 | |||
| 2920fdd89b | |||
| 52a77c9029 | |||
| 8b09f75d3a | |||
| 3fe49d894d | |||
| 2773092cfc | |||
| 5ef983b4cc | |||
| 9f3ff51798 |
5
api-payroll/.dockerignore
Normal file
5
api-payroll/.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
||||
Dockerfile
|
||||
README.md
|
||||
buildspec.yml
|
||||
CONTRIBUTING.md
|
||||
docker-compose.yml
|
||||
1
api-payroll/.htaccess
Normal file
1
api-payroll/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
Options -Indexes
|
||||
43
api-payroll/Dockerfile
Normal file
43
api-payroll/Dockerfile
Normal file
@@ -0,0 +1,43 @@
|
||||
FROM ubuntu:16.04
|
||||
|
||||
# Updating
|
||||
RUN apt-get -y update && apt-get -y upgrade
|
||||
|
||||
# Installing php, apache and supplementary software
|
||||
RUN apt-get -y install apache2 php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zip curl git unzip composer
|
||||
|
||||
# Enable apache mods
|
||||
RUN a2enmod php7.0
|
||||
RUN a2enmod rewrite
|
||||
|
||||
# Update the PHP.ini file, enable <? ?> tags and quieten logging
|
||||
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
|
||||
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini
|
||||
|
||||
# Manually set up the apache environment variables
|
||||
ENV APACHE_RUN_USER www-data
|
||||
ENV APACHE_RUN_GROUP www-data
|
||||
ENV APACHE_LOG_DIR /var/log/apache2
|
||||
ENV APACHE_LOCK_DIR /var/lock/apache2
|
||||
|
||||
# Expose apache
|
||||
EXPOSE 80
|
||||
|
||||
# Copy this repo into place.
|
||||
ADD . /var/www/site
|
||||
WORKDIR /var/www/site
|
||||
|
||||
# Testing permisions
|
||||
RUN chmod 777 -R .
|
||||
|
||||
# Installing dependencies
|
||||
RUN composer install
|
||||
|
||||
# Unit tests
|
||||
RUN composer test
|
||||
|
||||
# Update the default apache site with the config we created.
|
||||
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
|
||||
|
||||
# By default start up apache in the foreground, override with /bin/bash for interative
|
||||
CMD /usr/sbin/apache2ctl -D FOREGROUND
|
||||
15
api-payroll/apache-config.conf
Normal file
15
api-payroll/apache-config.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin me@mydomain.com
|
||||
DocumentRoot /var/www/site
|
||||
|
||||
<Directory /var/www/site/>
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride All
|
||||
Order deny,allow
|
||||
Allow from all
|
||||
</Directory>
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
|
||||
</VirtualHost>
|
||||
@@ -14,8 +14,9 @@ phases:
|
||||
- echo Entered the build phase...
|
||||
- echo Build started on `date`
|
||||
- composer test
|
||||
- sudo docker-compose up --build -d
|
||||
post_build:
|
||||
commands:
|
||||
- echo Entered the post_build phase...
|
||||
- sudo docker-compose down --rmi all -v
|
||||
- echo Build completed on `date`
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
"php": ">=5.5.0",
|
||||
"slim/slim": "^3.1",
|
||||
"slim/php-view": "^2.0",
|
||||
"monolog/monolog": "^1.17"
|
||||
"monolog/monolog": "^1.17",
|
||||
"respect/validation": "^1.1",
|
||||
"tuupola/cors-middleware": "^0.5.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=4.8 < 6.0"
|
||||
@@ -25,6 +27,12 @@
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\Service\\": "src/service",
|
||||
"App\\Application\\": "src/application"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"process-timeout" : 0
|
||||
},
|
||||
|
||||
245
api-payroll/composer.lock
generated
245
api-payroll/composer.lock
generated
@@ -4,8 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "bea55e49da1d79bf5a4874824904525d",
|
||||
"content-hash": "5e16cb7781829836a704bd8767830833",
|
||||
"hash": "93a9656f4e6eb0e25be1bad59ac6f487",
|
||||
"content-hash": "a3fc18885cc45d2733b77fa2081bdc72",
|
||||
"packages": [
|
||||
{
|
||||
"name": "container-interop/container-interop",
|
||||
@@ -116,6 +116,61 @@
|
||||
],
|
||||
"time": "2017-06-19 01:22:40"
|
||||
},
|
||||
{
|
||||
"name": "neomerx/cors-psr7",
|
||||
"version": "v1.0.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/neomerx/cors-psr7.git",
|
||||
"reference": "2556e2013f16a55532c95928455257d5b6bbc6e2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/neomerx/cors-psr7/zipball/2556e2013f16a55532c95928455257d5b6bbc6e2",
|
||||
"reference": "2556e2013f16a55532c95928455257d5b6bbc6e2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6.0",
|
||||
"psr/http-message": "^1.0",
|
||||
"psr/log": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0",
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"scrutinizer/ocular": "^1.1",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Neomerx\\Cors\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "neomerx",
|
||||
"email": "info@neomerx.com"
|
||||
}
|
||||
],
|
||||
"description": "Framework agnostic (PSR-7) CORS implementation (www.w3.org/TR/cors/)",
|
||||
"homepage": "https://github.com/neomerx/cors-psr7",
|
||||
"keywords": [
|
||||
"Cross Origin Resource Sharing",
|
||||
"Cross-Origin Resource Sharing",
|
||||
"cors",
|
||||
"neomerx",
|
||||
"psr-7",
|
||||
"psr7",
|
||||
"w3.org",
|
||||
"www.w3.org"
|
||||
],
|
||||
"time": "2018-05-23 16:10:11"
|
||||
},
|
||||
{
|
||||
"name": "nikic/fast-route",
|
||||
"version": "v1.3.0",
|
||||
@@ -358,6 +413,69 @@
|
||||
],
|
||||
"time": "2016-10-10 12:19:37"
|
||||
},
|
||||
{
|
||||
"name": "respect/validation",
|
||||
"version": "1.1.22",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Respect/Validation.git",
|
||||
"reference": "19d6ec893994912d21b390c43d287816ab070772"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Respect/Validation/zipball/19d6ec893994912d21b390c43d287816ab070772",
|
||||
"reference": "19d6ec893994912d21b390c43d287816ab070772",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4",
|
||||
"symfony/polyfill-mbstring": "^1.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"egulias/email-validator": "~1.2",
|
||||
"mikey179/vfsstream": "^1.5",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"symfony/validator": "~2.6.9",
|
||||
"zendframework/zend-validator": "~2.3"
|
||||
},
|
||||
"suggest": {
|
||||
"egulias/email-validator": "Strict (RFC compliant) email validation",
|
||||
"ext-bcmath": "Arbitrary Precision Mathematics",
|
||||
"ext-mbstring": "Multibyte String Functions",
|
||||
"friendsofphp/php-cs-fixer": "Fix PSR2 and other coding style issues",
|
||||
"symfony/validator": "Use Symfony validator through Respect\\Validation",
|
||||
"zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Respect\\Validation\\": "library/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD Style"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Respect/Validation Contributors",
|
||||
"homepage": "https://github.com/Respect/Validation/graphs/contributors"
|
||||
}
|
||||
],
|
||||
"description": "The most awesome validation engine ever created for PHP",
|
||||
"homepage": "http://respect.github.io/Validation/",
|
||||
"keywords": [
|
||||
"respect",
|
||||
"validation",
|
||||
"validator"
|
||||
],
|
||||
"time": "2018-08-01 13:06:54"
|
||||
},
|
||||
{
|
||||
"name": "slim/php-view",
|
||||
"version": "2.2.0",
|
||||
@@ -477,6 +595,115 @@
|
||||
"router"
|
||||
],
|
||||
"time": "2018-04-19 19:29:08"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "3296adf6a6454a050679cde90f95350ad604b171"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171",
|
||||
"reference": "3296adf6a6454a050679cde90f95350ad604b171",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.8-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2018-04-26 10:06:28"
|
||||
},
|
||||
{
|
||||
"name": "tuupola/cors-middleware",
|
||||
"version": "0.5.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tuupola/cors-middleware.git",
|
||||
"reference": "db69d8e67b99570b16e8cd5f78c423ed1167cb21"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/tuupola/cors-middleware/zipball/db69d8e67b99570b16e8cd5f78c423ed1167cb21",
|
||||
"reference": "db69d8e67b99570b16e8cd5f78c423ed1167cb21",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"neomerx/cors-psr7": "^1.0",
|
||||
"php": "^5.5 || ^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8",
|
||||
"squizlabs/php_codesniffer": "^2.5",
|
||||
"zendframework/zend-diactoros": "^1.3"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Tuupola\\Middleware\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mika Tuupola",
|
||||
"email": "tuupola@appelsiini.net",
|
||||
"homepage": "http://www.appelsiini.net/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 CORS Middleware",
|
||||
"homepage": "https://github.com/tuupola/cors-middleware",
|
||||
"keywords": [
|
||||
"cors",
|
||||
"middleware",
|
||||
"slim"
|
||||
],
|
||||
"time": "2016-08-12 13:12:58"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
@@ -733,16 +960,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
"version": "1.7.6",
|
||||
"version": "1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpspec/prophecy.git",
|
||||
"reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712"
|
||||
"reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
|
||||
"reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
|
||||
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06",
|
||||
"reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -754,12 +981,12 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^2.5|^3.2",
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5"
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.7.x-dev"
|
||||
"dev-master": "1.8.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@@ -792,7 +1019,7 @@
|
||||
"spy",
|
||||
"stub"
|
||||
],
|
||||
"time": "2018-04-18 13:57:24"
|
||||
"time": "2018-08-05 17:53:17"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
|
||||
6
api-payroll/public/css/bootstrap.min.css
vendored
Normal file
6
api-payroll/public/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
81
api-payroll/public/css/login.css
Normal file
81
api-payroll/public/css/login.css
Normal file
@@ -0,0 +1,81 @@
|
||||
body {
|
||||
background: url(../imagenes/grey_background.jpg);
|
||||
background-size: cover;
|
||||
font-family: Montserrat;
|
||||
}
|
||||
@media only screen and (min-device-width: 480px) {
|
||||
body {
|
||||
background: url('../imagenes/grey_background.jpg') no-repeat fixed center center;
|
||||
}
|
||||
}
|
||||
.logo {
|
||||
width: 213px;
|
||||
height: 60px;
|
||||
margin: 30px auto;
|
||||
}
|
||||
.login-block {
|
||||
width: 320px;
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
border-radius: 5px;
|
||||
border-top: 5px solid #bdb035;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.login-block h1 {
|
||||
text-align: center;
|
||||
color: #000;
|
||||
font-size: 18px;
|
||||
text-transform: uppercase;
|
||||
margin-top: 0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.login-block input {
|
||||
width: 100%;
|
||||
height: 42px;
|
||||
box-sizing: border-box;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #ccc;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
font-family: Montserrat;
|
||||
padding: 0 20px 0 50px;
|
||||
outline: none;
|
||||
}
|
||||
.login-block input#user {
|
||||
background: #fff url('../imagenes/login_username.png') 20px top no-repeat;
|
||||
background-size: 16px 80px;
|
||||
}
|
||||
.login-block input#user:focus {
|
||||
background: #fff url('../imagenes/login_username.png') 20px bottom no-repeat;
|
||||
background-size: 16px 80px;
|
||||
}
|
||||
.login-block input#password {
|
||||
background: #fff url('../imagenes/login_password.png') 20px top no-repeat;
|
||||
background-size: 16px 80px;
|
||||
}
|
||||
.login-block input#password:focus {
|
||||
background: #fff url('../imagenes/login_password.png') 20px bottom no-repeat;
|
||||
background-size: 16px 80px;
|
||||
}
|
||||
.login-block input:active, .login-block input:focus {
|
||||
border: 1px solid #bdb035;
|
||||
}
|
||||
.login-block #loginButon {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
background: #bdb035;
|
||||
box-sizing: border-box;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #6d661c;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
font-family: Montserrat;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.login-block button:hover {
|
||||
background: #c7b935;
|
||||
border: 1px solid #6d661c;
|
||||
}
|
||||
44
api-payroll/public/html/login.php
Normal file
44
api-payroll/public/html/login.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="../css/bootstrap.min.css">
|
||||
|
||||
<!-- jQuery library -->
|
||||
<script src="../js/jquery.min.js"></script>
|
||||
|
||||
<!-- Latest compiled JavaScript -->
|
||||
<script src="../js/bootstrap.min.js"></script>
|
||||
|
||||
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
|
||||
<div class="container">
|
||||
<div class="logo"></div>
|
||||
<div class="login-block">
|
||||
<form action="" method="post" name="Login_Form" class="login">
|
||||
<h1>Login</h1>
|
||||
<input type="text" value="" placeholder="User" id="userName" name="user" required="" autofocus=""/>
|
||||
<input type="password" value="" placeholder="Password" id="password" name="password" required=""/>
|
||||
<a href="#" class="btn btn-lg btn-warning btn-default" id="loginButon" name="login" value="Login" onclick="processLogin();">Login</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modalLoginError" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" id="modalLoginErrorHeader">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="modalLoginErrorBody"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/login.js"></script>
|
||||
<link href="../css/login.css" rel="stylesheet">
|
||||
BIN
api-payroll/public/imagenes/grey_background.jpg
Normal file
BIN
api-payroll/public/imagenes/grey_background.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
BIN
api-payroll/public/imagenes/login_password.png
Normal file
BIN
api-payroll/public/imagenes/login_password.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
api-payroll/public/imagenes/login_username.png
Normal file
BIN
api-payroll/public/imagenes/login_username.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -17,6 +17,20 @@ session_start();
|
||||
$settings = require __DIR__ . '/../src/settings.php';
|
||||
$app = new \Slim\App($settings);
|
||||
|
||||
// Custom error handling
|
||||
$c = $app->getContainer();
|
||||
$c['errorHandler'] = function ($c) {
|
||||
return function ($request, $response, $exception) use ($c) {
|
||||
$data = [
|
||||
'status' => 'error',
|
||||
'message' => $exception->getMessage()
|
||||
];
|
||||
return $c['response']->withStatus(500)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($data));
|
||||
};
|
||||
};
|
||||
|
||||
// Set up dependencies
|
||||
require __DIR__ . '/../src/dependencies.php';
|
||||
|
||||
|
||||
7
api-payroll/public/js/bootstrap.min.js
vendored
Normal file
7
api-payroll/public/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
api-payroll/public/js/jquery.min.js
vendored
Normal file
2
api-payroll/public/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
38
api-payroll/public/js/login.js
Normal file
38
api-payroll/public/js/login.js
Normal file
@@ -0,0 +1,38 @@
|
||||
function getbaseUrl(uriPath){
|
||||
var url = window.location.href;
|
||||
return url.substring(0, url.indexOf(uriPath));
|
||||
}
|
||||
|
||||
function processLogin() {
|
||||
console.log(getbaseUrl('html/'));
|
||||
var parametros = {
|
||||
"userName":$('#userName').val(),
|
||||
"password":$('#password').val()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: getbaseUrl('/html/') + '/index.php/api/session/login',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: parametros,
|
||||
success:function(data){
|
||||
console.log(JSON.stringify(data));
|
||||
if(data["status"] == "success"){
|
||||
redirect("http://stackoverflow.com");
|
||||
}else if(data["status"] == "success" || (data["status"] === undefined)){
|
||||
$('#modalLoginError').modal('show');
|
||||
document.getElementById('modalLoginErrorBody').innerHTML = "The server didn't respond in time, please try again or refresh this page.";
|
||||
}
|
||||
},
|
||||
error:function(x) {
|
||||
if (x.status==500){
|
||||
$('#modalLoginError').modal('show');
|
||||
document.getElementById('modalLoginErrorBody').innerHTML = "The user or password didnt match, please try again";
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function redirect(url){
|
||||
window.location.replace(url);
|
||||
}
|
||||
515
api-payroll/src/application/EmployeeApplication.php
Normal file
515
api-payroll/src/application/EmployeeApplication.php
Normal file
@@ -0,0 +1,515 @@
|
||||
<?php
|
||||
namespace App\Application;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
|
||||
class EmployeeApplication{
|
||||
private $pdo;
|
||||
private $cryptographyService;
|
||||
private $asserts;
|
||||
private $settings;
|
||||
|
||||
function __construct($employeeSettings, $mysql, $cryptographyService, $asserts){
|
||||
$this->settings = $employeeSettings;
|
||||
|
||||
$this->cryptographyService = $cryptographyService;
|
||||
$this->pdo = $mysql;
|
||||
$this->asserts = $asserts;
|
||||
|
||||
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function listEmployeeTypes(){
|
||||
$stmt = $this->pdo->prepare("SELECT
|
||||
id, name
|
||||
FROM
|
||||
employeeType
|
||||
WHERE
|
||||
status = 'ACTIVE'");
|
||||
$stmt->execute();
|
||||
|
||||
$results = $stmt->fetchAll();
|
||||
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
|
||||
$employeeTypes = array();
|
||||
foreach($results as $row){
|
||||
$employeeTypes[] = array('id' => (int)$row['id'], 'name' => $row['name']);
|
||||
}
|
||||
|
||||
return $employeeTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $firstName binary
|
||||
* @param $middleName binary
|
||||
* @param $lastName binary or null
|
||||
* @param $birthDate date yyyy-mm-dd
|
||||
* @param $email string
|
||||
* @param $phone string
|
||||
* @return integer
|
||||
*/
|
||||
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
||||
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
||||
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
||||
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
|
||||
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
|
||||
VALUES (:firstName, :middleName, :lastName, :birthDate, :email, :phone)");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
|
||||
':birthDate' => $birthDate, ':email' => $email, ':phone' => $phone));
|
||||
$id = $this->pdo->lastInsertId();
|
||||
$this->pdo->commit();
|
||||
|
||||
return $id;
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
throw new Exception('There was an error while trying to save a new person.');
|
||||
$this->logger->warning("There was an error in the EmployeeApplication->saveNewPerson caused by: $e ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idEmployeeType integer
|
||||
* @param $idPerson integer
|
||||
* @param $code string
|
||||
* @param $contractType string
|
||||
* @return mixed
|
||||
*/
|
||||
function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){
|
||||
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
|
||||
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
|
||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
|
||||
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':idPerson' => $idPerson, ':code' => $code,
|
||||
':contractType' => $contractType));
|
||||
$id = $this->pdo->lastInsertId();
|
||||
$this->pdo->commit();
|
||||
|
||||
return $id;
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
throw new Exception('There was an error while trying to save a new employee.');
|
||||
$this->logger->warning("There was an error in the EmployeeApplication->savePersonAsEmployee caused by: $e ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $requestData object
|
||||
* @return array
|
||||
*/
|
||||
function saveNewEmployee($requestData){
|
||||
// Getting and validating the data
|
||||
$firstName = $requestData['firstName'];
|
||||
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
||||
$this->asserts->isString($firstName, "The first name must be a string.");
|
||||
$this->asserts->betweenLength($firstName, 1, 50, "The first name must have a length between 1 and 50 characters.");
|
||||
|
||||
$middleName = $requestData['middleName'];
|
||||
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
||||
$this->asserts->isString($middleName, "The middle name must be a string.");
|
||||
$this->asserts->betweenLength($middleName, 1, 50, "The middle name must have a length between 1 and 50 characters.");
|
||||
|
||||
$lastName = isset($requestData['lastName'])
|
||||
? $requestData['lastName']
|
||||
: null;
|
||||
|
||||
$birthDate = $requestData['birthDate'];
|
||||
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
|
||||
|
||||
$email = $requestData['email'];
|
||||
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
||||
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
|
||||
|
||||
$phone = $requestData['phone'];
|
||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
|
||||
|
||||
$idEmployeeType = $requestData{'idEmployeeType'};
|
||||
$contractType = $requestData{'contractType'};
|
||||
|
||||
// Encrypting the sensitive data
|
||||
$securedFirstName = $this->cryptographyService->encryptString($firstName);
|
||||
$securedMiddleName = $this->cryptographyService->encryptString($middleName);
|
||||
|
||||
if (isset($lastName)) {
|
||||
$securedLastName = $this->cryptographyService->encryptString($lastName);
|
||||
} else {
|
||||
$securedLastName = null;
|
||||
}
|
||||
|
||||
$securedEmail = $this->cryptographyService->encryptString($email);
|
||||
|
||||
// Here begins the saving process
|
||||
$idNewPerson = $this->saveNewPerson($securedFirstName, $securedMiddleName, $securedLastName,
|
||||
$birthDate, $securedEmail, $phone);
|
||||
|
||||
$employeeCode = $this->cryptographyService->pseudoRandomStringOpenssl($this->settings['codeLength']);
|
||||
$idEmployee = $this->savePersonAsEmployee($idEmployeeType, $idNewPerson, $employeeCode, $contractType);
|
||||
|
||||
$response = array(
|
||||
"fullName" => "$firstName $middleName $lastName",
|
||||
"employeeCode" => $employeeCode,
|
||||
"idEmployee" => $idEmployee,
|
||||
"email" => $email,
|
||||
"phone" => $phone
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idEmployee
|
||||
* @return Integer
|
||||
*/
|
||||
function getIdPersonByIdEmployee($idEmployee){
|
||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT
|
||||
COALESCE((SELECT
|
||||
idPerson
|
||||
FROM
|
||||
employees
|
||||
WHERE
|
||||
id = :idEmployee),
|
||||
0) AS id");
|
||||
|
||||
$stmt->execute(array(':idEmployee' => $idEmployee));
|
||||
$results = $stmt->fetchAll();
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
|
||||
return $results[0]['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code string
|
||||
* @return integer
|
||||
*/
|
||||
function getIdEmployeeTypeByCode($code){
|
||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT COALESCE((SELECT
|
||||
et.id
|
||||
FROM
|
||||
employees e
|
||||
INNER JOIN
|
||||
employeeType et ON et.id = e.idEmployeeType
|
||||
WHERE
|
||||
e.code = :code), 0) AS id");
|
||||
|
||||
$stmt->execute(array(':code' => $code));
|
||||
$results = $stmt->fetchAll();
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
|
||||
return $results[0]['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data associated with the employee
|
||||
*
|
||||
* @param $idEmployee
|
||||
* @return array
|
||||
*/
|
||||
function getEmployeeDataById($idEmployee){
|
||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT
|
||||
p.id AS idPerson,
|
||||
p.firstName,
|
||||
p.middleName,
|
||||
IFNULL(p.lastName, '') AS lastName,
|
||||
p.email,
|
||||
p.phone,
|
||||
e.code,
|
||||
e.contractType
|
||||
FROM
|
||||
employees e
|
||||
INNER JOIN
|
||||
persons p ON p.id = e.idPerson
|
||||
WHERE
|
||||
e.id = :idEmployee");
|
||||
|
||||
$stmt->execute(array(':idEmployee' => $idEmployee));
|
||||
$results = $stmt->fetchAll();
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Acts as a man in the middle for the getEmployeeDataById method to decrypt the contents
|
||||
* and make the necesary data manipulations
|
||||
*
|
||||
* @param $idEmployee
|
||||
* @return array
|
||||
*/
|
||||
function proxyGetEmployeeDataById($idEmployee){
|
||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||
|
||||
$employeeData = $this->getEmployeeDataById($idEmployee);
|
||||
|
||||
$response = array(
|
||||
"idPerson" => (int)$employeeData['idPerson'],
|
||||
"firstName" => $this->cryptographyService->decryptString($employeeData['firstName']),
|
||||
"middleName" => $this->cryptographyService->decryptString($employeeData['middleName']),
|
||||
|
||||
"lastName" => strlen($employeeData['lastName']) > 0
|
||||
? $this->cryptographyService->decryptString($employeeData['lastName'])
|
||||
: '',
|
||||
|
||||
"email" => $this->cryptographyService->decryptString($employeeData['email']),
|
||||
"phone" => $employeeData['phone'],
|
||||
"code" => $employeeData['code'],
|
||||
"contractType" => $employeeData['contractType']
|
||||
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code string
|
||||
* @return array
|
||||
*/
|
||||
function getEmployeeDataByCode($code){
|
||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||
|
||||
$idEmployee = $this->getIdEmployeeTypeByCode($code);
|
||||
|
||||
return $this->proxyGetEmployeeDataById($idEmployee);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idPerson integer
|
||||
* @param $firstName binary
|
||||
* @param $middleName binary
|
||||
* @param $lastName binary
|
||||
* @param $birthDate date
|
||||
* @param $email binary
|
||||
* @param $phone string
|
||||
*/
|
||||
function updatePerson($idPerson, $firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
||||
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
|
||||
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
||||
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
||||
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
|
||||
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE persons
|
||||
SET
|
||||
firstName = :firstName,
|
||||
middleName = :middleName,
|
||||
lastName = :lastName,
|
||||
birthDate = :birthDate,
|
||||
email = :email,
|
||||
phone = :phone
|
||||
WHERE
|
||||
id = :idPerson");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
|
||||
':birthDate' => $birthDate, ':email' => $email, ':phone' => $phone, ':idPerson' => $idPerson));
|
||||
$this->pdo->commit();
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idEmployee integer
|
||||
* @param $code string
|
||||
* @param $idEmployeeType integer
|
||||
* @param $contractType string
|
||||
*/
|
||||
function updateEmployee($idEmployee, $code, $idEmployeeType, $contractType){
|
||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
|
||||
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE employees
|
||||
SET
|
||||
idEmployeeType = :idEmployeeType,
|
||||
code = :code,
|
||||
contractType = :contractType
|
||||
WHERE
|
||||
id = :idEmployee");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':code' => $code, ':contractType' => $contractType,
|
||||
':idEmployee' => $idEmployee));
|
||||
$this->pdo->commit();
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $requestData object
|
||||
* @return array
|
||||
*/
|
||||
function updateEmployeeData($requestData){
|
||||
// Getting and validating the data
|
||||
$idEmployee = $requestData['idEmployee'];
|
||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||
|
||||
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
|
||||
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
|
||||
|
||||
$code = $requestData['code'];
|
||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||
|
||||
$firstName = $requestData['firstName'];
|
||||
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
||||
$this->asserts->isString($firstName, "The first name must be a string.");
|
||||
$this->asserts->betweenLength($firstName, 1, 50, "The first name must have a length between 1 and 50 characters.");
|
||||
|
||||
$middleName = $requestData['middleName'];
|
||||
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
||||
$this->asserts->isString($middleName, "The middle name must be a string.");
|
||||
$this->asserts->betweenLength($middleName, 1, 50, "The middle name must have a length between 1 and 50 characters.");
|
||||
|
||||
$lastName = isset($requestData['lastName']) ? $requestData['lastName'] : null;
|
||||
|
||||
$birthDate = $requestData['birthDate'];
|
||||
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
|
||||
|
||||
$email = $requestData['email'];
|
||||
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
||||
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
|
||||
|
||||
$phone = $requestData['phone'];
|
||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
|
||||
|
||||
$idEmployeeType = $requestData{'idEmployeeType'};
|
||||
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
|
||||
|
||||
$contractType = $requestData{'contractType'};
|
||||
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||
|
||||
// Encrypting the sensitive data
|
||||
$securedFirstName = $this->cryptographyService->encryptString($firstName);
|
||||
$securedMiddleName = $this->cryptographyService->encryptString($middleName);
|
||||
|
||||
if (isset($lastName)) {
|
||||
$securedLastName = $this->cryptographyService->encryptString($lastName);
|
||||
} else {
|
||||
$securedLastName = null;
|
||||
}
|
||||
|
||||
$securedEmail = $this->cryptographyService->encryptString($email);
|
||||
|
||||
// Update process
|
||||
$this->updatePerson($idPerson, $securedFirstName, $securedMiddleName, $securedLastName,
|
||||
$birthDate, $securedEmail, $phone);
|
||||
|
||||
$this->updateEmployee($idEmployee, $code, $idEmployeeType, $contractType);
|
||||
|
||||
$response = array(
|
||||
"fullName" => "$firstName $middleName $lastName",
|
||||
"idEmployee" => $idEmployee,
|
||||
"email" => $email,
|
||||
"phone" => $phone,
|
||||
"birthDate" => $birthDate,
|
||||
"idEmployeeType" => $idEmployeeType,
|
||||
"contractType" => $contractType
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function disableEmployeeRecord($idEmployee){
|
||||
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE employees
|
||||
SET
|
||||
status = 'INACTIVE'
|
||||
WHERE
|
||||
id = :idEmployee");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':idEmployee' => $idEmployee));
|
||||
$this->pdo->commit();
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended for internal use
|
||||
*
|
||||
* This method will bring a list of ids of all the employees that are
|
||||
* currently active in the system
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getIdEmployeeFromAllActiveEmployees(){
|
||||
$stmt = $this->pdo->prepare("SELECT
|
||||
id
|
||||
FROM
|
||||
employees
|
||||
WHERE
|
||||
status = 'ACTIVE';");
|
||||
$stmt->execute();
|
||||
|
||||
$results = $stmt->fetchAll();
|
||||
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function listAllActiveEmployees(){
|
||||
$ids = $this->getIdEmployeeFromAllActiveEmployees();
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach($ids as $row){
|
||||
$result[] = $this->proxyGetEmployeeDataById($row['id']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
127
api-payroll/src/application/SessionApplication.php
Normal file
127
api-payroll/src/application/SessionApplication.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
namespace App\Application;
|
||||
|
||||
use Exception;
|
||||
|
||||
class SessionApplication{
|
||||
private $pdo;
|
||||
private $cryptographyService;
|
||||
private $asserts;
|
||||
|
||||
function __construct($mysql, $cryptographyService, $asserts){
|
||||
$this->cryptographyService = $cryptographyService;
|
||||
$this->pdo = $mysql;
|
||||
$this->asserts = $asserts;
|
||||
|
||||
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function verifySession(){
|
||||
return isset($_SESSION['userName']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function checkCurrentSession(){
|
||||
$session = array();
|
||||
|
||||
$session['loggedIn'] = $this->verifySession();
|
||||
|
||||
if($this->verifySession()){
|
||||
$session['userName'] = $_SESSION['userName'];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userName string
|
||||
* @return mixed
|
||||
*/
|
||||
function getPassword($userName){
|
||||
$this->asserts->isNotEmpty($userName, "The username can't be empty");
|
||||
$this->asserts->isString($userName, "The username must be a string.");
|
||||
$this->asserts->betweenLength($userName, 1, 50, "The username must have a length between 1 and 50 characters.");
|
||||
|
||||
$stmt = $this->pdo->prepare("SELECT password FROM users WHERE name = :userName");
|
||||
$stmt->execute(array(':userName' => $userName));
|
||||
$results = $stmt->fetchAll();
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
return $results[0]['password'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userName string
|
||||
* @param $password string
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
function newSession($userName, $password){
|
||||
$this->asserts->isNotEmpty($userName, "The username can't be empty");
|
||||
$this->asserts->isString($userName, "The username must be a string.");
|
||||
$this->asserts->betweenLength($userName, 1, 50, "The username must have a length between 1 and 50 characters.");
|
||||
$this->asserts->isNotEmpty($password, "The password can't be empty");
|
||||
$this->asserts->isString($password, "The password must be a string.");
|
||||
$this->asserts->betweenLength($password, 1, 50, "The password must have a length between 1 and 50 characters.");
|
||||
|
||||
$storedPassword = $this->getPassword($userName);
|
||||
|
||||
// If the credentials don't match anything in the the records
|
||||
if(!isset($storedPassword)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// Already has a session
|
||||
if($this->verifySession()){
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->cryptographyService->decryptPassword($password, $storedPassword)){
|
||||
$_SESSION['userName'] = $userName;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
throw new Exception('The user or password didnt match, please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userName
|
||||
* @param $password
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
function login($userName, $password){
|
||||
$this->asserts->isNotEmpty($userName, "The username can't be empty");
|
||||
$this->asserts->isString($userName, "The username must be a string.");
|
||||
$this->asserts->betweenLength($userName, 1, 50, "The username must have a length between 1 and 50 characters.");
|
||||
$this->asserts->isNotEmpty($password, "The password can't be empty");
|
||||
$this->asserts->isString($password, "The password must be a string.");
|
||||
$this->asserts->betweenLength($password, 1, 50, "The password must have a length between 1 and 50 characters.");
|
||||
|
||||
|
||||
if($this->newSession($userName, $password)){
|
||||
return array('status' => 'success', 'message' => 'Logged in successfully.');
|
||||
}
|
||||
else{
|
||||
throw new Exception('The user or password didnt match, please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function destroySession(){
|
||||
session_destroy();
|
||||
|
||||
return "Sucessfully logged out.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -17,3 +17,57 @@ $container['logger'] = function ($c) {
|
||||
$logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level']));
|
||||
return $logger;
|
||||
};
|
||||
|
||||
// Mysql connection
|
||||
$container['mysql'] = function ($c) {
|
||||
$mysqlSettings = $c->get('settings')['mysql'];
|
||||
|
||||
// The database parameters
|
||||
$host = $mysqlSettings['host'];
|
||||
$port = $mysqlSettings['port'];
|
||||
$database = $mysqlSettings['database'];
|
||||
$user = $mysqlSettings['user'];
|
||||
$password = $mysqlSettings['password'];
|
||||
$charset = $mysqlSettings['charset'];
|
||||
$pdoConnectionOptions = $mysqlSettings['pdoConnectionOptions'];
|
||||
|
||||
// Generic error messages
|
||||
$databaseConnectionErrorMessage = $mysqlSettings['databaseConnectionErrorMessage'];
|
||||
|
||||
// Initiate the connection
|
||||
$dsn = "mysql:host=$host;port=$port;dbname=$database;charset=$charset";
|
||||
try {
|
||||
$pdo = new PDO($dsn, $user, $password, $pdoConnectionOptions);
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
exit($databaseConnectionErrorMessage);
|
||||
}
|
||||
return $pdo;
|
||||
};
|
||||
|
||||
// Cryto functions
|
||||
$container['cryptographyService'] = function ($c) {
|
||||
$cryptographySettings = $c->get('settings')['cryptography'];
|
||||
$cryptographyService = new App\Service\CryptographyService($cryptographySettings);
|
||||
return $cryptographyService;
|
||||
};
|
||||
|
||||
// Assert functions
|
||||
$container['asserts'] = function ($c) {
|
||||
$asserts = new App\Service\Asserts();
|
||||
return $asserts;
|
||||
};
|
||||
|
||||
// The session application
|
||||
$container['sessionApplication'] = function ($c) {
|
||||
$sessionApplication = new App\Application\SessionApplication($c['mysql'], $c['cryptographyService'], $c['asserts']);
|
||||
return $sessionApplication;
|
||||
};
|
||||
|
||||
// The employee application
|
||||
$container['employeeApplication'] = function ($c) {
|
||||
$employeeSettings = $c->get('settings')['employee'];
|
||||
$employeeApplication = new App\Application\EmployeeApplication($employeeSettings,
|
||||
$c['mysql'], $c['cryptographyService'], $c['asserts']);
|
||||
return $employeeApplication;
|
||||
};
|
||||
|
||||
@@ -2,3 +2,21 @@
|
||||
// Application middleware
|
||||
|
||||
// e.g: $app->add(new \Slim\Csrf\Guard);
|
||||
|
||||
// Enable cors
|
||||
$app->add(new \Tuupola\Middleware\Cors([
|
||||
"origin" => ["*"],
|
||||
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||
"headers.allow" => ["Accept", "Content-Type"],
|
||||
"headers.expose" => [],
|
||||
"credentials" => false,
|
||||
"cache" => 0,
|
||||
"logger" => $container['logger'],
|
||||
"error" => function ($request, $response, $arguments) {
|
||||
$data["status"] = "error";
|
||||
$data["message"] = $arguments["message"];
|
||||
return $response
|
||||
->withHeader("Content-Type", "application/json")
|
||||
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||
}
|
||||
]));
|
||||
@@ -12,3 +12,85 @@ $app->get('/[{name}]', function (Request $request, Response $response, array $ar
|
||||
// Render index view
|
||||
return $this->renderer->render($response, 'index.phtml', $args);
|
||||
});
|
||||
|
||||
$app->get('/api/session', function (Request $request, Response $response, array $args) {
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->sessionApplication->checkCurrentSession()));
|
||||
});
|
||||
|
||||
$app->post('/api/session/login', function ($request, $response) {
|
||||
$requestData = $request->getParsedBody();
|
||||
|
||||
$data = $this->sessionApplication->login($requestData['userName'], $requestData['password']);
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($data));
|
||||
});
|
||||
|
||||
$app->get('/api/session/logout', function (Request $request, Response $response, array $args) {
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->sessionApplication->destroySession()));
|
||||
});
|
||||
|
||||
$app->get('/api/employee/types', function (Request $request, Response $response, array $args) {
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->listEmployeeTypes()));
|
||||
});
|
||||
|
||||
$app->get('/api/employee/all', function (Request $request, Response $response, array $args) {
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->listAllActiveEmployees()));
|
||||
});
|
||||
|
||||
$app->post('/api/employee', function ($request, $response) {
|
||||
$requestData = $request->getParsedBody();
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->saveNewEmployee($requestData)));
|
||||
});
|
||||
|
||||
$app->put('/api/employee', function ($request, $response) {
|
||||
$requestData = $request->getParsedBody();
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->updateEmployeeData($requestData)));
|
||||
});
|
||||
|
||||
$app->DELETE('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) {
|
||||
$idEmployee = $args['idEmployee'];
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->disableEmployeeRecord($idEmployee)));
|
||||
});
|
||||
|
||||
$app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) {
|
||||
$code = $args['code'];
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code)));
|
||||
});
|
||||
|
||||
$app->get('/api/employee/id/{idEmployee}', function (Request $request, Response $response, array $args) {
|
||||
$idEmployee = $args['idEmployee'];
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->proxyGetEmployeeDataById($idEmployee)));
|
||||
});
|
||||
|
||||
$app->get('/api/employee/code/{code}', function (Request $request, Response $response, array $args) {
|
||||
$code = $args['code'];
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->getEmployeeDataByCode($code)));
|
||||
});
|
||||
60
api-payroll/src/service/Asserts.php
Normal file
60
api-payroll/src/service/Asserts.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace App\Service;
|
||||
|
||||
use Exception;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
class Asserts{
|
||||
/**
|
||||
* @param $string string
|
||||
* @param $errorMessage string
|
||||
* @throws Exception
|
||||
*/
|
||||
function isString($string, $errorMessage){
|
||||
$validation = v::stringType()->validate($string);
|
||||
|
||||
if(!$validation){
|
||||
throw new Exception($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
* @param $errorMessage string
|
||||
* @throws Exception
|
||||
*/
|
||||
function isNotEmpty($string, $errorMessage){
|
||||
$validation = v::notEmpty()->validate($string);
|
||||
|
||||
if(!$validation){
|
||||
throw new Exception($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
* @param $min integer
|
||||
* @param $max integer
|
||||
* @param $errorMessage string
|
||||
* @throws Exception
|
||||
*/
|
||||
function betweenLength($string, $min, $max, $errorMessage){
|
||||
$validation = v::length($min, $max)->validate($string);
|
||||
|
||||
if(!$validation){
|
||||
throw new Exception($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $number integer
|
||||
* @param $errorMessage string
|
||||
* @throws Exception
|
||||
*/
|
||||
function higherThanZero($number, $errorMessage){
|
||||
if($number <= 0){
|
||||
throw new Exception($errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
102
api-payroll/src/service/CryptographyService.php
Normal file
102
api-payroll/src/service/CryptographyService.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace App\Service;
|
||||
|
||||
/**
|
||||
* A collection of functions to securely handling sensitive data,
|
||||
* passwords as well as making use of other crypto needs within
|
||||
* the project
|
||||
*
|
||||
* @property settings
|
||||
*/
|
||||
|
||||
class CryptographyService{
|
||||
|
||||
function __construct($cryptographySettings) {
|
||||
$this->settings = $cryptographySettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a string using the predefined algorithm, the resulting string will contain the
|
||||
* concatenated iv used for salting as well as the cipher text, both in hex format
|
||||
*
|
||||
* @param $text string
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
function encryptString($text){
|
||||
try {
|
||||
$iv = random_bytes($this->settings['ivSize']);
|
||||
$ivInHex = bin2hex($iv);
|
||||
|
||||
$encryptedMessage = openssl_encrypt($text, $this->settings['encryptionAlgorithm'],
|
||||
$this->settings['encryptionPassword'], 1, $iv);
|
||||
|
||||
$hexedCipherText = bin2hex($encryptedMessage);
|
||||
|
||||
return "$ivInHex$hexedCipherText";
|
||||
} catch (Exception $e) {
|
||||
throw new Exception('There was an error encrypting the string, contact the system administrator.');
|
||||
$this->logger->warning("There was an error in the cryptographyService->encryptString caused by: $e ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a string using the predefined algorithm
|
||||
*
|
||||
* This method assumes that an iv with the length taken from the setting ivSize is present
|
||||
* at the beginning of the string and this will be used to decrypt the cipher text
|
||||
*
|
||||
* @param $cipherText string
|
||||
* @return string
|
||||
*/
|
||||
function decryptString($cipherText) {
|
||||
$cipherText = hex2bin($cipherText);
|
||||
|
||||
$totalCharaters = strlen($cipherText);
|
||||
$iv = substr($cipherText, 0, $this->settings['ivSize']);
|
||||
$cipherTextWithIv = substr($cipherText, $this->settings['ivSize'], $totalCharaters);
|
||||
|
||||
return openssl_decrypt($cipherTextWithIv, $this->settings['encryptionAlgorithm'],
|
||||
$this->settings['encryptionPassword'], 1, $iv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Securely hashes a password for its coldstorage
|
||||
*
|
||||
* @param $password string
|
||||
* @return string
|
||||
*/
|
||||
function encryptPassword($password) {
|
||||
$options = [
|
||||
'cost' => $this->settings['passwordHashCost'],
|
||||
];
|
||||
|
||||
return password_hash($password, PASSWORD_BCRYPT, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares a password given in plain text against the encrypted veersion to determined if they're
|
||||
* the same password
|
||||
*
|
||||
* @param $plainPassword string
|
||||
* @param $encryptedPassword string
|
||||
* @return bool
|
||||
*/
|
||||
function decryptPassword($plainPassword, $encryptedPassword) {
|
||||
return password_verify($plainPassword, $encryptedPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a psudo random string using openssl
|
||||
*
|
||||
* @param $length integer
|
||||
* @return string
|
||||
*/
|
||||
function pseudoRandomStringOpenssl($length){
|
||||
|
||||
$string = openssl_random_pseudo_bytes($length);
|
||||
$string = bin2hex($string);
|
||||
|
||||
return substr($string, 0, $length);
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,36 @@ return [
|
||||
'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log',
|
||||
'level' => \Monolog\Logger::DEBUG,
|
||||
],
|
||||
|
||||
// Cryptography settings
|
||||
'cryptography' => [
|
||||
'encryptionAlgorithm' => 'AES-256-CBC',
|
||||
'encryptionPassword' => '7de431684c34cf2c898268cff71392f38c4175dde050c9ee69502b81571484e0',
|
||||
'passwordHashCost' => '12',
|
||||
'ivSize' => 16, // 128 bits
|
||||
],
|
||||
|
||||
// Datanase settings
|
||||
'mysql' => [
|
||||
'host' => 'mysql',
|
||||
'port' => '3307',
|
||||
'database' => 'payroll',
|
||||
'user' => 'root',
|
||||
'password' => '12345678',
|
||||
'charset' => 'utf8',
|
||||
'pdoConnectionOptions' => [
|
||||
PDO::ATTR_EMULATE_PREPARES => true, // The querys will be prepared by pdo instead of the dbms
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Errors will be returned as exceptions
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Data will be returned in associative arrays
|
||||
],
|
||||
'databaseConnectionErrorMessage' => 'Unable to connect to the database.',
|
||||
'databaseSelectQueryErrorMessage' => 'There was an error fetching the data.',
|
||||
'databaseInsertQueryErrorMessage' => 'There was an error inserting the record.',
|
||||
],
|
||||
|
||||
// Employee settings
|
||||
'employee' => [
|
||||
'codeLength' => '3',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
1
database/.dockerignore
Normal file
1
database/.dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
Dockerfile
|
||||
7
database/Dockerfile
Normal file
7
database/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM mysql:5.7
|
||||
|
||||
# Starting scripts
|
||||
ADD . /docker-entrypoint-initdb.d
|
||||
|
||||
# Config
|
||||
ADD my.cnf /etc/mysql
|
||||
75
database/database.sql
Normal file
75
database/database.sql
Normal file
@@ -0,0 +1,75 @@
|
||||
DROP DATABASE IF EXISTS payroll;
|
||||
|
||||
CREATE DATABASE payroll;
|
||||
USE payroll;
|
||||
|
||||
DROP TABLE IF EXISTS persons;
|
||||
CREATE TABLE IF NOT EXISTS `persons` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`firstName` varbinary(500) NOT NULL comment 'The name of the person',
|
||||
`middleName` varbinary(500) NOT NULL comment 'The midle name of the person',
|
||||
`lastName` varbinary(500) comment 'The last name of the person',
|
||||
`birthDate` DATE NOT NULL DEFAULT '1900-01-01' comment 'Date of birth of the person',
|
||||
`email` varbinary(500) NOT NULL comment 'The email adress of the person',
|
||||
`phone` INT(10) UNSIGNED NOT NULL comment 'The phone number of the person should be the mobile one but leaves room for home ones',
|
||||
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE (`phone`)
|
||||
);
|
||||
|
||||
INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
|
||||
VALUES (
|
||||
'0524a1848795041c2259ad658897913d25bc36e7ce54fa8465de767a03be8aaa957591c84d51dd85f1b58fc0826db835',
|
||||
'b5293d82e3ebc1f36eb70f8c0007aaa2aa1cd3f1e2903e1e36fb35137e967d3a',
|
||||
'b04e81e22a98c1abfcb85688926aa5fa12aea511f600424c25a7e9b14a0ac6f8',
|
||||
'1991-06-06',
|
||||
'205fbeba023a9b846a11492bfc6e039619bb6068030bcc13e45d30e638f6c51b4099911dee2b5644d55b43a38e8591f32f579ba0df9bd710b9e6bf66e0544184',
|
||||
'0123456789');
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`idPerson` INT UNSIGNED NOT NULL comment 'Id of the person, this contains the name and other personal data',
|
||||
`name` VARCHAR(50) NOT NULL comment 'Username',
|
||||
`password` VARCHAR(500) NOT NULL comment 'Hashed password',
|
||||
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY (idPerson) REFERENCES persons(id),
|
||||
UNIQUE (`name`)
|
||||
);
|
||||
|
||||
INSERT INTO users (idPerson, name, password)
|
||||
VALUES (1, 'sloth', '$2y$12$51mfESaLEGXDT4u9Bd9kiOHEpaJ1Bx4SEcVwsU5K6jVPMNkrnpJAa');
|
||||
|
||||
DROP TABLE IF EXISTS employeeType;
|
||||
CREATE TABLE IF NOT EXISTS `employeeType` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(100) NOT NULL comment 'Type or rol that the employee can be',
|
||||
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE (`name`)
|
||||
);
|
||||
|
||||
INSERT INTO employeeType (name) VALUES ('Chofer'),
|
||||
('Cargador'),
|
||||
('Auxiliar');
|
||||
|
||||
DROP TABLE IF EXISTS employees;
|
||||
CREATE TABLE IF NOT EXISTS `employees` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`idEmployeeType` INT UNSIGNED NOT NULL comment 'Defines the rol within the company',
|
||||
`idPerson` INT UNSIGNED NOT NULL comment 'Defines the rol within the company',
|
||||
`code` VARCHAR(100) NOT NULL comment 'A code to reference the employee',
|
||||
`contractType` ENUM('INTERNO', 'EXTERNO') NOT NULL comment 'The type of contract',
|
||||
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE (`code`)
|
||||
);
|
||||
20
database/my.cnf
Normal file
20
database/my.cnf
Normal file
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
[mysqld]
|
||||
port = 3307
|
||||
|
||||
!includedir /etc/mysql/conf.d/
|
||||
!includedir /etc/mysql/mysql.conf.d/
|
||||
28
docker-compose.yml
Normal file
28
docker-compose.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
version: '3'
|
||||
services:
|
||||
api:
|
||||
container_name: payroll_api
|
||||
build: api-payroll/
|
||||
ports:
|
||||
- "8085:80"
|
||||
volumes:
|
||||
- api-payroll:/var/www/site
|
||||
depends_on:
|
||||
- mysql
|
||||
mysql:
|
||||
container_name: payroll_mysql
|
||||
restart: always
|
||||
build: database
|
||||
expose:
|
||||
- "3307"
|
||||
ports:
|
||||
- "3307:3307"
|
||||
volumes:
|
||||
- my-datavolume:/var/lib/mysql
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: '12345678'
|
||||
MYSQL_USER: 'sloth'
|
||||
MYSQL_PASS: '12345678'
|
||||
volumes:
|
||||
api-payroll:
|
||||
my-datavolume:
|
||||
Reference in New Issue
Block a user