clean code and fix bugs (to cont.)

This commit is contained in:
David Drapeau 2020-11-27 14:10:57 +01:00
parent bfb0c5f91a
commit abf81ef36d
8 changed files with 215 additions and 209 deletions

View File

@ -14,29 +14,6 @@ DROP TABLE IF EXISTS core_lang;
DROP TABLE IF EXISTS core_currency; DROP TABLE IF EXISTS core_currency;
DROP TABLE IF EXISTS core_theme; DROP TABLE IF EXISTS core_theme;
--create table erp_config to link user frontend with backend
DROP TABLE IF EXISTS erp_config;
CREATE TABLE erp_config(
id SERIAL,
create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
k VARCHAR(128) NOT NULL,
v VARCHAR(128) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
comment TEXT NOT NULL DEFAULT '',
CONSTRAINT erConfig_id_pk PRIMARY KEY(id),
CONSTRAINT erpConfig_k_uk UNIQUE(k)
);
INSERT INTO erp_config(k, v)
VALUES('url', 'http://localhost:8069/'),
('db', 'wodoo_backend'),
('admin_user', 'admin@backend'),
('admin_password', 'admin'),
('host', 'localhost'),
('pg_user', 'odoo11'),
('pg_password', 'odoo11');
CREATE TABLE core_theme ( CREATE TABLE core_theme (
id SERIAL, id SERIAL,
create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@ -316,7 +293,7 @@ CREATE TABLE core_feature (
/* OFFICIAL DATA */ /* OFFICIAL DATA */
INSERT INTO core_theme(code, name, is_prod_available) VALUES('default', 'Default', TRUE); INSERT INTO core_theme(code, name, is_prod_available) VALUES('default', 'Default', TRUE),('materialize', 'MaterializeCSS', TRUE);
INSERT INTO core_currency(code, name, symbol, rounding, priority) VALUES ('usd', 'USD', '$', '0.01', 3); INSERT INTO core_currency(code, name, symbol, rounding, priority) VALUES ('usd', 'USD', '$', '0.01', 3);
INSERT INTO core_currency(code, name, symbol, rounding) VALUES ('vef', 'VEF', 'Bs.F', '0.0001'); INSERT INTO core_currency(code, name, symbol, rounding) VALUES ('vef', 'VEF', 'Bs.F', '0.0001');
@ -861,10 +838,10 @@ CREATE TABLE user_user (
phone VARCHAR(32) NOT NULL DEFAULT '', phone VARCHAR(32) NOT NULL DEFAULT '',
postcode VARCHAR(32) NOT NULL DEFAULT '', postcode VARCHAR(32) NOT NULL DEFAULT '',
city VARCHAR(128) NOT NULL DEFAULT '', city VARCHAR(128) NOT NULL DEFAULT '',
core_lang_id INTEGER, core_lang_id INTEGER DEFAULT NULL,
core_country_id INTEGER, core_country_id INTEGER DEFAULT NULL,
core_currency_id INTEGER, core_currency_id INTEGER DEFAULT NULL,
core_theme_id INTEGER, core_theme_id INTEGER DEFAULT NULL,
is_backend_access BOOLEAN NOT NULL DEFAULT FALSE, is_backend_access BOOLEAN NOT NULL DEFAULT FALSE,
is_active BOOLEAN NOT NULL DEFAULT FALSE, is_active BOOLEAN NOT NULL DEFAULT FALSE,
is_validated BOOLEAN DEFAULT FALSE, is_validated BOOLEAN DEFAULT FALSE,

View File

@ -8,16 +8,6 @@ $oTrans = new ClassTranslation();
$oUser = new ClassUser(); $oUser = new ClassUser();
$oForm = new ClassForm(); $oForm = new ClassForm();
$url = $_SESSION['erp']['url'];
$db = $_SESSION['erp']['db'];
$username = $_SESSION['erp']['admin_user'];
$password = $_SESSION['erp']['admin_password'];
$admin_connection = new ClassXMLRPC($url, $db, $username, $password);
$countries = $admin_connection->execute('res.country', 'search_read', [[]], ['fields'=>['id', 'name', 'code']]);
// Creating user in ERP and in WEFRA // Creating user in ERP and in WEFRA
// .. // ..
if(isset($_POST['formRegisterButtonSubmit'])){ if(isset($_POST['formRegisterButtonSubmit'])){
@ -30,43 +20,9 @@ if(isset($_POST['formRegisterButtonSubmit'])){
} }
} }
$name = $_POST['formRegisterFieldFirstname'].' '.$_POST['formRegisterFieldLastname'];
//create user in ERP
$company_id = $admin_connection->execute('res.company', 'search', [[]], [])[0];
$ext_id = $admin_connection->execute('res.users', 'create',
[['name'=>$name,
'email'=>$_POST['formRegisterFieldEmail'],
'login'=>$_POST['formRegisterFieldEmail'], //yes, the login IS the email, there is no mistake here
'company_id'=>$company_id,
'client'=>true
]],
[]
);
//if user created in ERP, then create it in Wefra with password linked
if(isset($ext_id) and !is_array($ext_id)){
//create user in Wefra and link the user to ERP //create user in Wefra and link the user to ERP
$user = $oUser->createUser($_POST, $ext_id); $res = $oUser->createUser($_POST);
print_r($res);
if($user){
//update the password for user in ERP
//..
$getUser = $oUser->getUser($user['user_id']);
$admin_connection->execute('res.users', 'write', [[$ext_id], ['password'=>$getUser['password'], 'password_uncrypted'=>$_POST['formRegisterFieldPassword']]], []);
//..
//that way, ERP rights will be checked everytime Wodoo will use ORM to allow user to to actions which will have an influence in the ERP (ie. get a task which will be assigned to his ERP's user related)
}
//display a confirmation message that everything went well
$message['status']="teal";
$message['content'] = "<h3>Great job!</h3><br><br> <p>You are now part of JMDN Consulting Team.</p> <p>We will come back to you very soon.</p>";
} else {
//if user not created in ERP, displaying a warning message to ask for a new try
$message['status']="orange";
$message['content'] = "we have failed to register your profile. Please try again or contact the team contact@jmdn-solutions.com with title: Cannot create account via Wodoo";
}
} }
// .. // ..
// ENDOF creating user in ERP and in WeFra // ENDOF creating user in ERP and in WeFra

View File

@ -19,13 +19,8 @@ class ClassUser extends ClassConfig {
$execSQL = $oPDOLink->prepare($sql); $execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array(':user_id'=>$this->_userId, ':feature_code'=>$this->_featureCode)); $execSQL->execute(array(':user_id'=>$this->_userId, ':feature_code'=>$this->_featureCode));
} }
//ENDOF _addFeatureToUser()
private function _setFeaturesToUser($user_id){
$this->_userId = $user_id;
ClassUser::_addFeatureToUser($this->_userId, 'home');
ClassUser::_addFeatureToUser($this->_userId, 'portfolio');
ClassUser::_addFeatureToUser($this->_userId, 'logout');
}
public function getUserIdByLogin($user_login){ public function getUserIdByLogin($user_login){
$this->_userLogin = $user_login; $this->_userLogin = $user_login;
@ -36,6 +31,7 @@ class ClassUser extends ClassConfig {
$row = $execSQL->fetch(PDO::FETCH_ASSOC); $row = $execSQL->fetch(PDO::FETCH_ASSOC);
return $row['id']; return $row['id'];
} }
//ENDOF getUserIdByLogin()
private function _checkIfVipOfferActive(){ private function _checkIfVipOfferActive(){
$config = ClassConfig::getConfig(); $config = ClassConfig::getConfig();
@ -46,6 +42,7 @@ class ClassUser extends ClassConfig {
return false; return false;
} }
} }
//ENDOF _checkIfVipOfferActive()
private function _checkIfEverythingForFreeActive(){ private function _checkIfEverythingForFreeActive(){
$config = ClassConfig::getConfig(); $config = ClassConfig::getConfig();
@ -56,58 +53,71 @@ class ClassUser extends ClassConfig {
return false; return false;
} }
} }
//ENDOF _checkIfEverythingForFreeActive()
public function createUser($data, $ext_id){ private function _checkEmailConfirmation($email, $email_confirmation){
$this->_data = $data;
$this->_extId = $ext_id;
$config = ClassConfig::getConfig(); $config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect(); $oPDOLink = ClassConfig::databaseConnect();
//IF password and confirmPassword are not identical, displaying an error message //IF password and confirmPassword are not identical, displaying an error message
if($this->_data['formRegisterFieldPassword'] != $this->_data['formRegisterFieldConfirmPassword']){ if($email == $email_confirmation){
$message['state']='failed'; return true;
$message['css_class']='failed'; } else {
$message['translation_code'] = 'checkRegisterForm_notSamePassword'; return false;
return $message;
} }
else { }
//ENDOF _checkEmailConfirmation()
private function _createUserUser($data){
$this->_data = $data;
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
$activation_code = rand(); $activation_code = rand();
$sql=" $sql="
INSERT INTO user_user(email, password, activation_code, firstname, lastname, INSERT INTO user_user(email, password, activation_code,
core_lang_id, core_country_id, core_currency_id, core_theme_id, core_lang_id, core_country_id, core_currency_id, core_theme_id,
is_backend_access, is_active, is_employee,
comment comment
) VALUES ( ) VALUES (
:email, :password, :activation_code, :email, :password, :activation_code,
:firstname, :lastname,
(SELECT id FROM core_lang WHERE code='en_gb'), (SELECT id FROM core_lang WHERE code='en_gb'),
(SELECT id FROM core_country WHERE code='ch'), (SELECT id FROM core_country WHERE code='ch'),
(SELECT id FROM core_currency WHERE code='chf'), 1, (SELECT id FROM core_currency WHERE code='chf'),
false, true, false, (SELECT id FROM core_theme WHERE code='materialize'),
'user registered online via Wodoo frontend' 'user registered online via Wefra frontend'
) )
"; ";
$execSQL = $oPDOLink->prepare($sql); $execSQL = $oPDOLink->prepare($sql);
if($execSQL->execute(array( $res = $execSQL->execute([
':email'=>$this->_data['formRegisterFieldEmail'], ':email'=>$this->_data['formRegisterFieldEmail'],
':password'=>sha1($this->_data['formRegisterFieldPassword'].'-k3P[8x&'), ':password'=>sha1($this->_data['formRegisterFieldPassword'].'-k3P[8x&'),
':activation_code'=>$activation_code, ':activation_code'=>$activation_code
':firstname'=>$this->_data['formRegisterFieldFirstname'], ]);
':lastname'=>$this->_data['formRegisterFieldLastname'] if($res == true || $res == 1){
))){ $user_id = $oPDOLink->lastInsertId('user_user_id_seq');
$newUserId = $oPDOLink->lastInsertId('user_user_id_seq'); return $user_id;
} else {
return false;
}
}
//ENDOF _createUserUser()
private function _createUserDetail($user_id){
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
//$isVipOfferActive = $this->_checkIfVipOfferActive();
//$isEverythingForFreeActive = $this->_checkIfEverythingForFreeActive();
// core user detail
$sql=" $sql="
INSERT INTO user_detail(user_id, ext_id) INSERT INTO user_detail(user_id)
VALUES (:user_id, :ext_id) VALUES (:user_id)
"; ";
$execSQL = $oPDOLink->prepare($sql); $execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array(':user_id'=>$newUserId, ':ext_id'=>$this->_extId)); return $execSQL->execute(array(':user_id'=>$user_id));
}
//ENDOF _createUserDetail()
private function _setFeaturesToUser($user_id){
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
// get features for user // get features for user
$sql="SELECT id FROM core_feature WHERE is_user_feature=TRUE;"; $sql="SELECT id FROM core_feature WHERE is_user_feature=TRUE;";
@ -118,7 +128,7 @@ class ClassUser extends ClassConfig {
$sql=" $sql="
INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) INSERT INTO useruser_corefeature_rel(user_id, core_feature_id)
VALUES ( VALUES (
(SELECT id FROM user_user WHERE email=:email LIMIT 1), :user_id,
:feature_id :feature_id
); );
"; ";
@ -126,26 +136,120 @@ class ClassUser extends ClassConfig {
//set features to user //set features to user
foreach($features as $feature){ foreach($features as $feature){
$execSQL->execute(array(':email'=>$this->_data['formRegisterFieldEmail'], ':feature_id'=>$feature['id'])); $execSQL->execute(array(':user_id'=>$user_id, ':feature_id'=>$feature['id']));
} }
return true;
}
//ENDOF _setFeaturesToUser()
$message['user_id'] = $newUserId; public function createUser($data){
$message['activation_code'] = $activation_code; $this->_data = $data;
$message['status'] = "success"; $resEC = $this->_checkEmailConfirmation($this->_data['formRegisterFieldPassword'], $this->_data['formRegisterFieldConfirmPassword']);
$message['css_class'] = 'success-message';
//TODO change confirmation_registration by register_form_success when registrations will need an activation by clic on link in an email
//$message['translation_code'] = 'register_form_success'; //'confirmation_registration';
//TODO send an email to admin to indicate that there is a new registration if($resEC == true){
return $message; $user_id = $this->_createUserUser($this->_data);
if(is_numeric($user_id) == true){
$resCUD = $this->_createUserDetail((integer) $user_id);
if($resCUD){
$resSFTU = $this->_setFeaturesToUser($user_id);
return 'success_creation_user';
} else { } else {
$message['status']='failed'; return 'error_create_user_detail';
$message['css_class'] = 'failed-message'; }
//$message['translation_code'] = 'register_form_failed'; } else {
return $message; return 'error_create_user_user';
} }
} else {
return 'email_diff_confirm_email';
} }
} }
//ENDOF createUser()
// public function createUser($data){
// $this->_data = $data;
// $config = ClassConfig::getConfig();
// $oPDOLink = ClassConfig::databaseConnect();
//
//
// //IF password and confirmPassword are not identical, displaying an error message
// if($this->_data['formRegisterFieldPassword'] != $this->_data['formRegisterFieldConfirmPassword']){
// $message['state']='failed';
// $message['css_class']='failed';
// $message['translation_code'] = 'checkRegisterForm_notSamePassword';
// return $message;
// }
//
// $activation_code = rand();
// $sql="
// INSERT INTO user_user(email, password, activation_code
// core_lang_id, core_country_id, core_currency_id, core_theme_id,
// comment
// ) VALUES (
// :email, :password, :activation_code,
// (SELECT id FROM core_lang WHERE code='en_gb'),
// (SELECT id FROM core_country WHERE code='ch'),
// (SELECT id FROM core_currency WHERE code='chf'),
// (SELECT id FROM core_theme WHERE code='materialize'),
// 'user registered online via Wefra frontend'
// )
// ";
//
// $execSQL = $oPDOLink->prepare($sql);
// if($execSQL->execute(array(
// ':email'=>$this->_data['formRegisterFieldEmail'],
// ':password'=>sha1($this->_data['formRegisterFieldPassword'].'-k3P[8x&'),
// ':activation_code'=>$activation_code,
// ))){
// $newUserId = $oPDOLink->lastInsertId('user_user_id_seq');
//
// //$isVipOfferActive = $this->_checkIfVipOfferActive();
// //$isEverythingForFreeActive = $this->_checkIfEverythingForFreeActive();
// // core user detail
// $sql="
// INSERT INTO user_detail(user_id)
// VALUES (:user_id)
// ";
// $execSQL = $oPDOLink->prepare($sql);
// $execSQL->execute(array(':user_id'=>$newUserId));
//
// // get features for user
// $sql="SELECT id FROM core_feature WHERE is_user_feature=TRUE;";
// $getFeatures = $oPDOLink->prepare($sql);
// $getFeatures->execute(array());
// $features = $getFeatures->fetchAll(PDO::FETCH_ASSOC);
//
// $sql="
// INSERT INTO useruser_corefeature_rel(user_id, core_feature_id)
// VALUES (
// (SELECT id FROM user_user WHERE email=:email LIMIT 1),
// :feature_id
// );
// ";
// $execSQL = $oPDOLink->prepare($sql);
//
// //set features to user
// foreach($features as $feature){
// $execSQL->execute(array(':email'=>$this->_data['formRegisterFieldEmail'], ':feature_id'=>$feature['id']));
// }
//
// $message['user_id'] = $newUserId;
// $message['activation_code'] = $activation_code;
// $message['status'] = "success";
// $message['css_class'] = 'success-message';
// //TODO change confirmation_registration by register_form_success when registrations will need an activation by clic on link in an email
// //$message['translation_code'] = 'register_form_success'; //'confirmation_registration';
//
// //TODO send an email to admin to indicate that there is a new registration
// return $message;
// } else {
// $message['user_id'] = "null";
// $message['activation_code'] = "null";
// $message['status']='error';
// $message['css_class'] = 'failed-message';
// //$message['translation_code'] = 'register_form_failed';
// return $message;
// }
// }
public function activateUser($activation_code){ public function activateUser($activation_code){

View File

@ -1,10 +1,10 @@
<?php <?php
interface InterfaceConfig { interface InterfaceConfig {
//URLs & paths kernel //URLs & paths kernel
const PATH_ROOT = "/var/www/html/wodoo/"; const PATH_ROOT = "/var/www/html/wefra/";
const URL_ROOT = "/wodoo/"; const URL_ROOT = "/wefra/";
const URL_SCRIPT = "/wodoo/scripts/"; const URL_SCRIPT = "/wefra/scripts/";
// URLs & paths customs // URLs & paths customs
const PATH_CUSTOM = "/var/www/html/customs/wodoo-custom/"; // <== CONFIG the path to your custom directory const PATH_CUSTOM = "/var/www/html/customs/wefra-custom/"; // <== CONFIG the path to your custom directory
} }

View File

@ -2,7 +2,7 @@
interface InterfacePostgreSQL { interface InterfacePostgreSQL {
const PG_SERVER = 'localhost'; const PG_SERVER = 'localhost';
const PG_PORT = '5432'; const PG_PORT = '5432';
const PG_DBNAME = 'wodoo_framework'; const PG_DBNAME = 'wefra';
const PG_USER = 'odoo11'; const PG_USER = 'odoo11';
const PG_PASSWORD = 'odoo11'; const PG_PASSWORD = 'odoo11';

View File

@ -1,4 +1,4 @@
var urlRoot = "/wodoo/"; var urlRoot = "/wefra/";
// needed for AJAX calls within D3JS // needed for AJAX calls within D3JS
var config_requestArguments = { var config_requestArguments = {

View File

@ -2,5 +2,9 @@
session_start(); session_start();
session_destroy(); session_destroy();
include("../modules/InterfaceConfig.php");
include("../modules/InterfacePostgreSQL.php");
include("../modules/ClassConfig.php");
$oConf = new ClassConfig(); $oConf = new ClassConfig();
header('Location:'.$oConf->getURLRoot()); header('Location:'.$oConf->getURLRoot());

View File

@ -1,18 +1,3 @@
<!--<div id="index-banner" class="parallax-container">
<div class="section no-pad-bot">
<div class="container">
<br><br>
<h1 class="header center teal-text text-darken-2">Get your tasks done!</h1>
<div class="row center">
<h5 class="header col s12 red-text text-darken-4">Register now and you can start straight after.</h5>
</div>
<br><br>
</div>
</div>
<div class="parallax"><img src="< ?php echo $oConf->getURLRoot('images/geneva-xl-01-banner.jpg'); ?>" alt="Unsplashed background img 2"></div>
</div>
-->
<?php <?php
if(isset($message)){ if(isset($message)){
?> ?>
@ -21,23 +6,13 @@ if(isset($message)){
<div class="section"> <div class="section">
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
<?php if($message['frontend']['status']==true && $message['backend']['status']==true){ ?> <?php if($user == true){ ?>
<div class="card-panel green"> <div class="card-panel green">
<span class="white-text">Your profile has been created with success. You can now login and fully use Globsi platform.</span> <span class="white-text">Your profile has been created with success.</span>
</div>
<?php } elseif($message['frontend']['status']==false && $message['backend']['status']==true){ ?>
<div class="card-panel orange">
<span class="white-text">Please copy paste this message below and send it by email to clients@globsi.com</span>
<p>Something went wrong on the FE side.</p>
</div>
<?php } elseif($message['frontend']['status']==true && $message['backend']['status']==false){ ?>
<div class="card-panel orange">
<span class="white-text">Please copy paste this message below and send it by email to clients@globsi.com</span>
<p>Something went wrong on the BE side.</p>
</div> </div>
<?php } else { ?> <?php } else { ?>
<div class="card-panel orange"> <div class="card-panel orange">
<span class="white-text">Please copy paste this message below and send it by email to clients@globsi.com</span> <span class="white-text">Please copy paste this message below and send it by email to <?php echo $_SESSION['config']['email_info']; ?></span>
<p>Something went wrong while trying to register.</p> <p>Something went wrong while trying to register.</p>
</div> </div>
<?php } ?> <?php } ?>
@ -48,7 +23,7 @@ if(isset($message)){
<?php <?php
} }
if( !isset($message) or $message['backend']['status']==false or $message['frontend']['status']==false){ if( !isset($message) or $message['status'] != true){
?> ?>
<div class="container"> <div class="container">
@ -64,17 +39,7 @@ if( !isset($message) or $message['backend']['status']==false or $message['fronte
<div class="col s12"> <div class="col s12">
<b>Contact</b> <b>Contact</b>
<div class="row"> <div class="row">
<div class="input-field col s12 m6"> <div class="input-field col s12">
<i class="material-icons prefix">account_circle</i>
<input class="validate" required="" aria-required="true" id="formRegisterFieldFirstname" name="formRegisterFieldFirstname" type="text" >
<label for="formRegisterFieldFirstname">Firstname</label>
</div>
<div class="input-field col s12 m6">
<i class="material-icons prefix"></i>
<input class="validate" required="" aria-required="true" id="formRegisterFieldLastname" name="formRegisterFieldLastname" type="text" >
<label for="formRegisterFieldLastname">Lastname</label>
</div>
<div class="input-field col s12 m6">
<i class="material-icons prefix">email</i> <i class="material-icons prefix">email</i>
<input class="validate" required="" aria-required="true" id="formRegisterFieldEmail" name="formRegisterFieldEmail" type="email" > <input class="validate" required="" aria-required="true" id="formRegisterFieldEmail" name="formRegisterFieldEmail" type="email" >
<label for="formRegisterFieldEmail">Email</label> <label for="formRegisterFieldEmail">Email</label>