This commit is contained in:
2017-12-27 13:46:56 +01:00
parent 0cc882060c
commit 73d95c3daf
22 changed files with 641 additions and 6 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class Login extends MY_Controller {
{
parent::__construct();
$this->load->library( 'beheer/CreateUserSession' );
$this->load->library( 'beheer/session/CreateUserSession' );
}
public function index()
@@ -30,4 +30,27 @@ class usersController extends MY_Controller {
$this->json( $users );
}
public function saveUser()
{
$userValidation = new UserValidation();
if ( ! $userValidation->getValidationResult() )
return $this->json( [
'success'=> false, 'messages' =>$userValidation->getErrorMessages()] );
$user = $this->input->post();
$userID = $user['id'];
unset($user['id']);
if( $userID == 0 )
{
createNewUser();
}
$userID = User::saveUser( $userID, $user);
$this->json( ['success' => TRUE] );
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ class MY_Controller extends CI_Controller {
{
parent::__construct();
$this->load->library( 'beheer/RetrieveUserSession' );
$this->load->library( 'beheer/session/RetrieveUserSession' );
$this->handle();
}
@@ -0,0 +1,16 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 26/12/2017
* Time: 12:39
*/
class CreateUser {
public function __construct()
{
}
}
@@ -0,0 +1,80 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 26/12/2017
* Time: 12:40
*/
class PasswordRecipe {
private $nakedPassword = false;
private $salt = false;
private $saltedPassword;
public function __construct()
{
$this->handle();
}
public function setNakedPassword( $nakedPassword )
{
$this->nakedPassword = $nakedPassword;
}
public function setSalt( $salt )
{
$this->salt = $salt;
}
private function handle()
{
$this->checkNakedPassword();
$this->checkSalt();
$this->setSaltedPassword();
}
private function checkNakedPassword()
{
if( ! $this->nakedPassword ) $this->createNakedPassword();
if( strlen($this->nakedPassword) < 6 ) return;
}
private function checkSalt()
{
if( ! $this->salt ) $this->createSalt();
}
private function createNakedPassword()
{
$pass = $this->getRandomString(8);
$this->nakedPassword = $pass;
}
private function createSalt()
{
$salt = $this->getRandomString(8);
$this->salt = $salt;
}
private function setSaltedPassword()
{
$this->saltedPassword = sha1($this->)
}
private function getRandomString( $length=8 )
{
$rand = '';
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $length; $i++) {
$n = rand(0, $alphaLength);
$rand.= $alphabet[$n];
}
}
}
@@ -0,0 +1,190 @@
<?php defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
/**
* Created by PhpStorm.
* User: imac-3
* Date: 04/06/16
* Time: 14:17
*/
class validation {
private $fieldValue;
private $validations;
private $validation;
private $validationResult;
private $errorMessages = [];
private $validationField;
private $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public function validate( $fieldValue, $validationField = FALSE )
{
$this->setValidationField( $validationField );
$this->setFieldValue( $fieldValue );
$this->handle();
}
public function setValidationField( $validationfield )
{
$this->validationField = $validationfield;
}
public function getErrorMessages()
{
return $this->errorMessages;
}
public function getValidationResult()
{
return $this->validationResult;
}
private function handle()
{
$this->setValidations();
$this->checkValidations();
$this->setValidationResult();
}
private function setValidations()
{
$this->validations = explode( '|', $this->validationField['validations'] );
}
private function setFieldValue( $fieldValue )
{
$this->fieldValue = $fieldValue;
}
private function setValidationResult()
{
if ( count( $this->errorMessages ) == 0 ) return $this->validationResult = TRUE;
$this->validationResult = FALSE;
}
private function checkValidations()
{
foreach ( $this->validations as $this->validation )
{
if ( $this->validation == 'required' ) $this->checkRequired();
if ( $this->validation == 'alpha' ) $this->checkAlfa();
if ( $this->validation == 'alphaNumeric' ) $this->checkAlfanumeric();
if ( $this->validation == 'alphaNumericSpaces' ) $this->checkAlphaNumericSpaces();
if ( $this->validation == 'alphaDash' ) $this->checkAlphaDash();
if ( $this->validation == 'numeric' ) $this->checkNumeric();
if ( $this->validation == 'integer' ) $this->checkInteger();
if ( $this->validation == 'decimal' ) $this->checkDecimal();
if ( $this->validation == 'email' ) $this->checkEmail();
if ( $this->validation == 'unique' ) $this->checkUnique();
if ( substr( $this->validation, 0, 9 ) == 'minlength' ) $this->checkMinlength();
if ( substr( $this->validation, 0, 9 ) == 'maxlength' ) $this->checkMaxlength();
}
}
public function checkRequired()
{
if ( ! $this->fieldValue || empty( $this->fieldValue ) || strlen( $this->fieldValue ) == 0 )
$this->errorMessages[] = 'veld is verplicht';
}
public function checkAlfa()
{
$value = ctype_alpha( $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters toegestaan';
}
public function checkAlfaNumeric()
{
$value = ctype_alnum( (string) $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters en cijfers toegestaan';
return $value;
}
public function checkAlphaNumericSpaces()
{
$value = (bool) preg_match( '/^[A-Z0-9 ]+$/i', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters, cijfers en spaties toegestaan';
}
public function checkAlphaDash()
{
$value = (bool) preg_match( '/^[a-z0-9_-]+$/i', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters, cijfers en streepjes toegestaan';
}
public function checkNumeric()
{
$value = (bool) preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen getallen toegestaan';
}
public function checkInteger()
{
$value = (bool) preg_match( '/^[\-+]?[0-9]+$/', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen gehele getallen toegestaan';
}
public function checkDecimal()
{
$value = (bool) preg_match( '/^[\-+]?[0-9]+\.[0-9]+$/', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen getallen toegestaan';
}
public function checkEmail()
{
if ( ! $this->fieldValue || empty( $this->fieldValue ) || strlen( $this->fieldValue ) == 0 ) return;
$value = (bool) filter_var( $this->fieldValue, FILTER_VALIDATE_EMAIL );
if ( ! $value ) $this->errorMessages[] = 'ongeldig emailadres';
}
public function checkUnique()
{
$recordID = $this->ci->input->post( 'id' );
$model = $this->validationField['model'];
$field = $this->validationField['field'];
$value = $this->ci
->$model
->checkUnique( $recordID, $field, $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'invoer moet uniek zijn';
}
private function checkMinlength()
{
$length = explode( '-', $this->validation );
if ( strlen( $this->fieldValue ) < $length[1] )
$this->errorMessages[] = 'moet minimaal uit ' . $length[1] . ' karakters bestaan';
}
private function checkMaxlength()
{
$length = explode( $this->validation, '-' );
if ( strlen( $this->fieldValue ) > $length[1] )
$this->errorMessages[] = 'mag maximaal uit ' . $length[1] . ' karakters bestaan';
}
}
@@ -0,0 +1,91 @@
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Created by PhpStorm.
* User: imac-3
* Date: 26/06/16
* Time: 21:17
*/
require_once( APPPATH . 'libraries/validation/Validation.php' );
class BaseValidation {
protected $validationField;
protected $key;
protected $fieldValue;
protected $errorMessages = [];
protected $validation;
protected $fieldname;
protected $ci;
protected $validationResult;
public function __construct()
{
$this->ci =& get_instance();
$this->validateInput();
}
public function getValidationResult()
{
return $this->validationResult;
}
public function validateInput()
{
$this->loopFields();
}
public function getErrorMessages( )
{
return $this->errorMessages;
}
private function loopFields()
{
foreach ( $this->validationFields as $this->key => $this->validationField )
{
$this->validation = new Validation();
$this->setInputfield();
$this->validateFieldvalue();
$this->setFieldname();
$this->setValidationResult();
$this->setErrorMesagges();
}
}
private function setInputfield()
{
$this->fieldValue = $this->ci->input->post( $this->key );
}
private function validateFieldvalue()
{
$this->validation->validate( $this->fieldValue, $this->validationField );
}
private function setFieldname()
{
$this->fieldname = $this->validationField['fieldname'];
}
private function setErrorMesagges()
{
$this->errorMessages[ $this->fieldname ] = $this->validation->getErrorMessages();
}
private function setValidationResult()
{
if( $this->validationResult === FALSE ) return;
$this->validationResult = $this->validation->getValidationResult();
}
}
@@ -0,0 +1,28 @@
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Created by PhpStorm.
* User: imac-3
* Date: 26/06/16
* Time: 21:13
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class LoginValidation extends BaseValidation {
protected $validationFields = [
'username' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'gebruikersnaam'
],
'password' => [
'validations' => 'required',
'fieldname' => 'wachtwoord'
]
];
public function __construct()
{
parent::__construct();
}
}
@@ -0,0 +1,47 @@
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Created by Pensare Software
* User: Theo Weijmer
* Date: 26/06/16
* Time: 20:39
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class OrganisationValidation extends BaseValidation {
protected $validationFields = [
'brin' => [
'validations' => 'required|alphaNumeric',
'fieldname' => 'brinnummer'
],
'naam' => [
'validations' => 'required',
'fieldname' => 'Organisatienaam'
],
'naamkort' => [
'validations' => 'required',
'fieldname' => 'Organisatienaam (kort)'
],
'vestiging' => [
'validations' => 'required|alphaNumeric|unique',
'fieldname' => 'vestigingsnummer',
'model' => 'organisations_model',
'field' => 'vestiging'
],
'email' => [
'validations' => 'email',
'fieldname' => 'email'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}
@@ -0,0 +1,28 @@
<?php
/**
* Created by PhpStorm.
* User: imac-3
* Date: 26/06/16
* Time: 21:13
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class PasswordRequestValidation extends BaseValidation {
protected $validationFields = [
'username' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'gebruikersnaam'
],
'email' => [
'validations' => 'required|email',
'fieldname' => 'email'
]
];
public function __construct()
{
parent::__construct();
}
}
@@ -0,0 +1,44 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/07/16
* Time: 13:35
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class UserValidation extends BaseValidation {
protected $validationFields = [
'firstname' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'firstname'
],
'lastname' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'lastname'
],
'email' => [
'validations' => 'required|email|unique',
'fieldname' => 'email',
'model' => 'User_model',
'field' => 'email'
],
'username' => [
'validations' => 'required|alphanumeric|minlength-4|unique',
'fieldname' => 'username',
'model' => 'User_model',
'field' => 'username'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}
+15
View File
@@ -23,4 +23,19 @@ class User_model extends MY_Model {
return $user;
}
public function checkUnique($recordID, $field, $fieldValue)
{
$this->sql = "
SELECT *
FROM users
WHERE ucase( {$field} ) = '{strtoupper($fieldValue)}'
AND id != {$recordID} ";
$result = $this->get_query_row();
if( ! $result ) return TRUE;
return FALSE;
}
}
+16
View File
@@ -45,5 +45,21 @@ class User extends BaseModel {
return TRUE;
}
public static function saveUser( $userID, $user )
{
if( $userID == 0)
{
$user = User::create($user);
}
else
{
$user = User::whereId($userID);
$user->update($user);
}
return $user->id;
}
}
+30
View File
@@ -0,0 +1,30 @@
<div class="dbo-page">
<div class="row">
<?php foreach ( $pages as $page ): ?>
<div class="col-md-4">
<div class="panel panel-primary panel-line">
<div class="panel-heading">
<h3 class="panel-title">
<?= $page->pagename ?>
</h3>
</div>
<div class="panel-body">
<div class="row">
<?php foreach ( $page->subpages as $subpage ): ?>
<div class="col-md-6">
<div class="panel panel-success panel-line">
<div class="panel-heading">
<h5 class="panel-title">
<?= $subpage->pagename ?>
</h5>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
+3
View File
@@ -0,0 +1,3 @@
<nav class="site-navbar navbar navbar-default navbar-fixed-top navbar-mega navbar-inverse">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
+2 -1
View File
@@ -18,7 +18,8 @@
},
"autoload": {
"classmap": [
"application/models/eloquent"
"application/models/eloquent",
"application/libraries/validation"
]
},
"suggest": {
@@ -27,6 +27,13 @@ dbo.userDataService = {
console.log( data );
callback( data );
} )
},
saveUser: function ( submitDATA, callback ) {
$.post( 'index.php/beheer/usersController/saveUser', submitDATA, 'json' )
.done( function ( data ) {
callback( data );
} )
}
+1 -1
View File
@@ -55,7 +55,7 @@ dbo.loginService = {
},
notifyWrongPassword: function () {
notifyMe( {
tellMe( {
title : 'Login fout',
message: 'Gebruikersnaam / wachtwoord komen niet overeen'
} );
+17 -1
View File
@@ -45,6 +45,7 @@ $( function () {
dbo.userDataService.checkUsername()
var submitDATA = {
id : vm.id,
firstname : vm.firstname(),
middlename: vm.middlename(),
lastname : vm.lastname(),
@@ -53,7 +54,22 @@ $( function () {
role : vm.role()
}
dbo.userDataService.saveUser( submitDATA, function ( data ) {
if ( data.succes ) {
tellMe( {
title : 'gebruiker aangemaakt',
message : 'gebuiker is succesvol aangemaakt',
modalClass: 'modal-success'
} );
return;
}
tellMe({
title : 'fout aanmaken gebruiker',
message : data.errorMessages,
modalClass: 'modal-danger'
});
} )
},
@@ -62,7 +78,7 @@ $( function () {
var vm = dbo.editUserModal;
vm.id = user.id || 0;
vm.vm.firstname( user.firstname || '' );
vm.firstname( user.firstname || '' );
vm.lastname( user.firstname || '' );
vm.middlename( user.firstname || '' );
vm.username( user.username || '' );
@@ -5,7 +5,7 @@
* Time: 17:08
*/
var notifyMe = function ( options, callback ) {
var tellMe = function ( options, callback ) {
dbo.notifyModel.init( options, callback );
}