Compare commits

...

27 Commits

Author SHA1 Message Date
1500aef977 [add] Higher than zero asserting 2018-08-09 23:26:25 -06:00
112f78c1de [del] Old asserts 2018-08-09 22:48:42 -06:00
08702b2cdf [add] Generic assers in employee application 2018-08-09 22:47:19 -06:00
21013cf6ac [add] Generic asserts with custom errors 2018-08-09 21:55:39 -06:00
7cf083a612 [add] Simple redirect 2018-08-09 02:33:21 -06:00
d4135188bd [add] Local bootstrap libraries 2018-08-09 02:30:39 -06:00
6d29ac3f23 [add] Error handling in the login 2018-08-09 02:26:16 -06:00
0449f202ef [add] Added wrapper for login method
Also changed the logout endpoint to get
2018-08-09 01:35:44 -06:00
23868b60ee [add] Login functionality 2018-08-09 01:28:36 -06:00
8a2d5b2afa Merge pull request #12 from PootisPenserHere/fixEmployeeTypesReturnsIdAsInt
[mod] Returning id as int
2018-08-08 23:07:37 -06:00
7ceb2aad93 [mod] Returning id as int 2018-08-08 23:06:38 -06:00
3902435690 Merge pull request #11 from PootisPenserHere/adaptingMysqlForOtherPort
Adapting mysql for other port
2018-08-08 21:35:55 -06:00
f16e9fe72c [add] Parametrizing 2018-08-08 16:15:45 -06:00
d2b9163537 [add] Configuring the mysql port 2018-08-08 15:58:55 -06:00
403541580d Merge pull request #10 from PootisPenserHere/dockerizing
Dockerizing
2018-08-08 01:46:39 -06:00
663ea7cc3e [add] Testing the docker build in CI 2018-08-08 07:41:29 +00:00
f93b41f14e [add] Index protection 2018-08-08 07:37:27 +00:00
24f1ce1ed7 [add] Docker ignore for php 2018-08-08 07:32:54 +00:00
b25346e3d5 [add] Database initiated along with container 2018-08-08 07:14:22 +00:00
f2237d9209 [add] Connecting to mysql from pdo 2018-08-08 05:24:02 +00:00
7fc9ca8c75 [add] Mysql container 2018-08-07 19:25:20 -06:00
97fca1d7d3 [add] Docker compose 2018-08-07 17:33:21 -06:00
058e19a49a [add] Apache conf for the docker container 2018-08-07 17:32:32 -06:00
bffeb6e9f4 [add] Dockerfile 2018-08-07 17:31:02 -06:00
9a3e876afe Merge pull request #9 from PootisPenserHere/employeeDataByCode
[add] Emṕloyee data by code
2018-08-06 15:22:05 -06:00
dadea504d0 [add] Emṕloyee data by code 2018-08-06 15:17:31 -06:00
1390427ec0 Merge pull request #8 from PootisPenserHere/listAllEmployees
[add] List of all active employees
2018-08-06 03:51:09 -06:00
24 changed files with 463 additions and 81 deletions

View File

@@ -0,0 +1,5 @@
Dockerfile
README.md
buildspec.yml
CONTRIBUTING.md
docker-compose.yml

1
api-payroll/.htaccess Normal file
View File

@@ -0,0 +1 @@
Options -Indexes

43
api-payroll/Dockerfile Normal file
View 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

View 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>

View File

@@ -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`

File diff suppressed because one or more lines are too long

View 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;
}

View 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">&times;</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">

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

File diff suppressed because one or more lines are too long

2
api-payroll/public/js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View 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);
}

View File

@@ -38,7 +38,12 @@ class EmployeeApplication{
}
$stmt = null;
return $results;
$employeeTypes = array();
foreach($results as $row){
$employeeTypes[] = array('id' => (int)$row['id'], 'name' => $row['name']);
}
return $employeeTypes;
}
/**
@@ -51,11 +56,11 @@ class EmployeeApplication{
* @return integer
*/
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
$this->asserts->firstName($firstName);
$this->asserts->middleName($middleName);
$this->asserts->birthDate($birthDate);
$this->asserts->email($email);
$this->asserts->phone($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)
@@ -84,6 +89,10 @@ class EmployeeApplication{
* @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)");
@@ -110,21 +119,29 @@ class EmployeeApplication{
function saveNewEmployee($requestData){
// Getting and validating the data
$firstName = $requestData['firstName'];
$this->asserts->firstName($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->middleName($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;
$lastName = isset($requestData['lastName'])
? $requestData['lastName']
: null;
$birthDate = $requestData['birthDate'];
$this->asserts->birthDate($birthDate);
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
$email = $requestData['email'];
$this->asserts->email($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->phone($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'};
@@ -164,6 +181,8 @@ class EmployeeApplication{
* @return Integer
*/
function getIdPersonByIdEmployee($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
idPerson
@@ -184,10 +203,12 @@ class EmployeeApplication{
}
/**
* @param $code
* @return mixed
* @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
@@ -214,6 +235,8 @@ class EmployeeApplication{
* @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,
@@ -248,6 +271,8 @@ class EmployeeApplication{
* @return array
*/
function proxyGetEmployeeDataById($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$employeeData = $this->getEmployeeDataById($idEmployee);
$response = array(
@@ -269,6 +294,18 @@ class EmployeeApplication{
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
@@ -279,6 +316,13 @@ class EmployeeApplication{
* @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
@@ -308,6 +352,11 @@ class EmployeeApplication{
* @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
@@ -334,28 +383,42 @@ class EmployeeApplication{
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->firstName($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->middleName($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->birthDate($birthDate);
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
$email = $requestData['email'];
$this->asserts->email($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->phone($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);
@@ -389,6 +452,8 @@ class EmployeeApplication{
}
function disableEmployeeRecord($idEmployee){
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
try {
$stmt = $this->pdo->prepare("UPDATE employees
SET
@@ -432,6 +497,9 @@ class EmployeeApplication{
return $results;
}
/**
* @return array
*/
function listAllActiveEmployees(){
$ids = $this->getIdEmployeeFromAllActiveEmployees();

View File

@@ -43,7 +43,9 @@ class SessionApplication{
* @return mixed
*/
function getPassword($userName){
$this->asserts->userName($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));
@@ -62,14 +64,18 @@ class SessionApplication{
* @throws Exception
*/
function newSession($userName, $password){
$this->asserts->userName($userName);
$this->asserts->password($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)){
throw new Exception('The user or password didnt match, please try again.');
return false;
}
// Already has a session
@@ -82,7 +88,30 @@ class SessionApplication{
return true;
}
else{
return false;
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.');
}
}

View File

@@ -24,6 +24,7 @@ $container['mysql'] = function ($c) {
// The database parameters
$host = $mysqlSettings['host'];
$port = $mysqlSettings['port'];
$database = $mysqlSettings['database'];
$user = $mysqlSettings['user'];
$password = $mysqlSettings['password'];
@@ -34,7 +35,7 @@ $container['mysql'] = function ($c) {
$databaseConnectionErrorMessage = $mysqlSettings['databaseConnectionErrorMessage'];
// Initiate the connection
$dsn = "mysql:host=$host;dbname=$database;charset=$charset";
$dsn = "mysql:host=$host;port=$port;dbname=$database;charset=$charset";
try {
$pdo = new PDO($dsn, $user, $password, $pdoConnectionOptions);
} catch (Exception $e) {
@@ -69,4 +70,4 @@ $container['employeeApplication'] = function ($c) {
$employeeApplication = new App\Application\EmployeeApplication($employeeSettings,
$c['mysql'], $c['cryptographyService'], $c['asserts']);
return $employeeApplication;
};
};

View File

@@ -22,14 +22,14 @@ $app->get('/api/session', function (Request $request, Response $response, array
$app->post('/api/session/login', function ($request, $response) {
$requestData = $request->getParsedBody();
$data = $this->sessionApplication->newSession($requestData['userName'], $requestData['password']);
$data = $this->sessionApplication->login($requestData['userName'], $requestData['password']);
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($data));
});
$app->post('/api/session/logout', function (Request $request, Response $response, array $args) {
$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()));
@@ -79,10 +79,18 @@ $app->get('/api/employee/type/{code}', function (Request $request, Response $res
->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code)));
});
$app->get('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) {
$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)));
});

View File

@@ -6,78 +6,54 @@ use Respect\Validation\Validator as v;
class Asserts{
/**
* @param $string
* @param $string string
* @param $errorMessage string
* @throws Exception
*/
function userName($string){
$validateFirstName = v::stringType()->notEmpty()->length(1, 50)->validate($string);
function isString($string, $errorMessage){
$validation = v::stringType()->validate($string);
if(!$validateFirstName){
throw new Exception('The user name must be a string between 1 and 50 characters');
if(!$validation){
throw new Exception($errorMessage);
}
}
/**
* @param $string
* @param $string string
* @param $errorMessage string
* @throws Exception
*/
function password($string){
$validateFirstName = v::stringType()->notEmpty()->length(1, 50)->validate($string);
function isNotEmpty($string, $errorMessage){
$validation = v::notEmpty()->validate($string);
if(!$validateFirstName){
throw new Exception('The password must be a string between 1 and 50 characters');
if(!$validation){
throw new Exception($errorMessage);
}
}
/**
* @param $string
* @param $string string
* @param $min integer
* @param $max integer
* @param $errorMessage string
* @throws Exception
*/
function firstName($string){
$validateFirstName = v::stringType()->notEmpty()->length(1, 100)->validate($string);
function betweenLength($string, $min, $max, $errorMessage){
$validation = v::length($min, $max)->validate($string);
if(!$validateFirstName){
throw new Exception('The first name must be a string between 1 and 100 characters');
if(!$validation){
throw new Exception($errorMessage);
}
}
/**
* @param $string
* @param $number integer
* @param $errorMessage string
* @throws Exception
*/
function middleName($string){
if(!v::stringType()->notEmpty()->length(1, 100)->validate($string)){
throw new Exception('The middle name must be a string between 1 and 100 characters');
}
}
/**
* @param $string
* @throws Exception
*/
function birthDate($string){
if(!v::date('Y-m-d')->notEmpty()->validate($string)){
throw new Exception('The birth date must be in the yyyy-mm-dd format');
}
}
/**
* @param $string
* @throws Exception
*/
function email($string){
if(!v::stringType()->notEmpty()->length(1, 100)->validate($string)){
throw new Exception('The email must be a string between 1 and 100 characters');
}
}
/**
* @param $string
* @throws Exception
*/
function phone($string){
if(!v::digit()->notEmpty()->length(10, 10)->validate($string)){
throw new Exception('The phone must be a numeric value of 10 digits');
function higherThanZero($number, $errorMessage){
if($number <= 0){
throw new Exception($errorMessage);
}
}
}

View File

@@ -26,7 +26,8 @@ return [
// Datanase settings
'mysql' => [
'host' => 'localhost',
'host' => 'mysql',
'port' => '3307',
'database' => 'payroll',
'user' => 'root',
'password' => '12345678',
@@ -43,7 +44,7 @@ return [
// Employee settings
'employee' => [
'codeLength' => '5',
'codeLength' => '3',
],
],
];

1
database/.dockerignore Normal file
View File

@@ -0,0 +1 @@
Dockerfile

7
database/Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM mysql:5.7
# Starting scripts
ADD . /docker-entrypoint-initdb.d
# Config
ADD my.cnf /etc/mysql

20
database/my.cnf Normal file
View 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
View 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: