wefra/models/register.php

73 lines
3.0 KiB
PHP
Raw Normal View History

<?php
// -------------------------------------------------------- //
//TODO @BL or @DD: creating UT for the registration process //
// -------------------------------------------------------- //
$oConf = new ClassConfig();
$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'])){
//clean $_POST data from any hack try
foreach($_POST as $k=>$v){
if($_POST[$k]!="formRegisterFieldPassword" or $_POST[$k]!="formRegisterFieldConfirmPassword"){
$_POST[$k] = $oForm->cleanData($v);
} else {
continue;
}
}
$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";
}
}
// ..
// ENDOF creating user in ERP and in WeFra