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_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 (
id SERIAL,
create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@ -316,7 +293,7 @@ CREATE TABLE core_feature (
/* 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) VALUES ('vef', 'VEF', 'Bs.F', '0.0001');
@ -861,10 +838,10 @@ CREATE TABLE user_user (
phone VARCHAR(32) NOT NULL DEFAULT '',
postcode VARCHAR(32) NOT NULL DEFAULT '',
city VARCHAR(128) NOT NULL DEFAULT '',
core_lang_id INTEGER,
core_country_id INTEGER,
core_currency_id INTEGER,
core_theme_id INTEGER,
core_lang_id INTEGER DEFAULT NULL,
core_country_id INTEGER DEFAULT NULL,
core_currency_id INTEGER DEFAULT NULL,
core_theme_id INTEGER DEFAULT NULL,
is_backend_access BOOLEAN NOT NULL DEFAULT FALSE,
is_active BOOLEAN NOT NULL DEFAULT FALSE,
is_validated BOOLEAN DEFAULT FALSE,

View File

@ -8,16 +8,6 @@ $oTrans = new ClassTranslation();
$oUser = new ClassUser();
$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
// ..
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
$user = $oUser->createUser($_POST, $ext_id);
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";
}
//create user in Wefra and link the user to ERP
$res = $oUser->createUser($_POST);
print_r($res);
}
// ..
// ENDOF creating user in ERP and in WeFra

View File

@ -19,13 +19,8 @@ class ClassUser extends ClassConfig {
$execSQL = $oPDOLink->prepare($sql);
$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){
$this->_userLogin = $user_login;
@ -36,16 +31,18 @@ class ClassUser extends ClassConfig {
$row = $execSQL->fetch(PDO::FETCH_ASSOC);
return $row['id'];
}
//ENDOF getUserIdByLogin()
private function _checkIfVipOfferActive(){
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
$oPDOLink = ClassConfig::databaseConnect();
if($config['is_vip_offer_active']==='true'){
return true;
} else {
return false;
}
}
//ENDOF _checkIfVipOfferActive()
private function _checkIfEverythingForFreeActive(){
$config = ClassConfig::getConfig();
@ -56,96 +53,203 @@ class ClassUser extends ClassConfig {
return false;
}
}
//ENDOF _checkIfEverythingForFreeActive()
public function createUser($data, $ext_id){
$this->_data = $data;
$this->_extId = $ext_id;
private function _checkEmailConfirmation($email, $email_confirmation){
$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;
if($email == $email_confirmation){
return true;
} else {
return false;
}
else {
$activation_code = rand();
$sql="
INSERT INTO user_user(email, password, activation_code, firstname, lastname,
core_lang_id, core_country_id, core_currency_id, core_theme_id,
is_backend_access, is_active, is_employee,
comment
) VALUES (
:email, :password, :activation_code,
:firstname, :lastname,
(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'), 1,
false, true, false,
'user registered online via Wodoo frontend'
)
";
}
//ENDOF _checkEmailConfirmation()
$execSQL = $oPDOLink->prepare($sql);
if($execSQL->execute(array(
':email'=>$this->_data['formRegisterFieldEmail'],
':password'=>sha1($this->_data['formRegisterFieldPassword'].'-k3P[8x&'),
':activation_code'=>$activation_code,
':firstname'=>$this->_data['formRegisterFieldFirstname'],
':lastname'=>$this->_data['formRegisterFieldLastname']
))){
$newUserId = $oPDOLink->lastInsertId('user_user_id_seq');
private function _createUserUser($data){
$this->_data = $data;
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
$activation_code = rand();
//$isVipOfferActive = $this->_checkIfVipOfferActive();
//$isEverythingForFreeActive = $this->_checkIfEverythingForFreeActive();
// core user detail
$sql="
INSERT INTO user_detail(user_id, ext_id)
VALUES (:user_id, :ext_id)
";
$execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array(':user_id'=>$newUserId, ':ext_id'=>$this->_extId));
$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);
$res = $execSQL->execute([
':email'=>$this->_data['formRegisterFieldEmail'],
':password'=>sha1($this->_data['formRegisterFieldPassword'].'-k3P[8x&'),
':activation_code'=>$activation_code
]);
if($res == true || $res == 1){
$user_id = $oPDOLink->lastInsertId('user_user_id_seq');
return $user_id;
} else {
return false;
}
}
//ENDOF _createUserUser()
// 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);
private function _createUserDetail($user_id){
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
$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);
$sql="
INSERT INTO user_detail(user_id)
VALUES (:user_id)
";
$execSQL = $oPDOLink->prepare($sql);
return $execSQL->execute(array(':user_id'=>$user_id));
}
//ENDOF _createUserDetail()
//set features to user
foreach($features as $feature){
$execSQL->execute(array(':email'=>$this->_data['formRegisterFieldEmail'], ':feature_id'=>$feature['id']));
}
private function _setFeaturesToUser($user_id){
$config = ClassConfig::getConfig();
$oPDOLink = ClassConfig::databaseConnect();
$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';
// 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);
//TODO send an email to admin to indicate that there is a new registration
return $message;
$sql="
INSERT INTO useruser_corefeature_rel(user_id, core_feature_id)
VALUES (
:user_id,
:feature_id
);
";
$execSQL = $oPDOLink->prepare($sql);
//set features to user
foreach($features as $feature){
$execSQL->execute(array(':user_id'=>$user_id, ':feature_id'=>$feature['id']));
}
return true;
}
//ENDOF _setFeaturesToUser()
public function createUser($data){
$this->_data = $data;
$resEC = $this->_checkEmailConfirmation($this->_data['formRegisterFieldPassword'], $this->_data['formRegisterFieldConfirmPassword']);
if($resEC == true){
$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 {
return 'error_create_user_detail';
}
} else {
$message['status']='failed';
$message['css_class'] = 'failed-message';
//$message['translation_code'] = 'register_form_failed';
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){

View File

@ -1,10 +1,10 @@
<?php
interface InterfaceConfig {
//URLs & paths kernel
const PATH_ROOT = "/var/www/html/wodoo/";
const URL_ROOT = "/wodoo/";
const URL_SCRIPT = "/wodoo/scripts/";
const PATH_ROOT = "/var/www/html/wefra/";
const URL_ROOT = "/wefra/";
const URL_SCRIPT = "/wefra/scripts/";
// 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 {
const PG_SERVER = 'localhost';
const PG_PORT = '5432';
const PG_DBNAME = 'wodoo_framework';
const PG_DBNAME = 'wefra';
const PG_USER = 'odoo11';
const PG_PASSWORD = 'odoo11';

View File

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

View File

@ -2,5 +2,9 @@
session_start();
session_destroy();
include("../modules/InterfaceConfig.php");
include("../modules/InterfacePostgreSQL.php");
include("../modules/ClassConfig.php");
$oConf = new ClassConfig();
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
if(isset($message)){
?>
@ -21,23 +6,13 @@ if(isset($message)){
<div class="section">
<div class="row">
<div class="col s12">
<?php if($message['frontend']['status']==true && $message['backend']['status']==true){ ?>
<?php if($user == true){ ?>
<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>
</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>
<span class="white-text">Your profile has been created with success.</span>
</div>
<?php } else { ?>
<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>
</div>
<?php } ?>
@ -48,7 +23,7 @@ if(isset($message)){
<?php
}
if( !isset($message) or $message['backend']['status']==false or $message['frontend']['status']==false){
if( !isset($message) or $message['status'] != true){
?>
<div class="container">
@ -64,17 +39,7 @@ if( !isset($message) or $message['backend']['status']==false or $message['fronte
<div class="col s12">
<b>Contact</b>
<div class="row">
<div class="input-field col s12 m6">
<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">
<div class="input-field col s12">
<i class="material-icons prefix">email</i>
<input class="validate" required="" aria-required="true" id="formRegisterFieldEmail" name="formRegisterFieldEmail" type="email" >
<label for="formRegisterFieldEmail">Email</label>