You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
289 lines
14 KiB
289 lines
14 KiB
<?php if ( !defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
use app\core\auth\Registration as UserRegistration;
|
|
use app\core\auth\Subscription;
|
|
use app\libraries\Axepta;
|
|
class Registration extends MY_Controller {
|
|
|
|
protected $registration;
|
|
public function __construct()
|
|
{
|
|
$this->frontoffice_parent_controller();
|
|
$this->setCspHeader(true);
|
|
$this->load_language_frontoffice();
|
|
$this->load->helper('cookie');
|
|
$this->load->model('User_registration_model');
|
|
|
|
$this->registration = new UserRegistration();
|
|
$this->subscription = new Subscription();
|
|
}
|
|
/**
|
|
* Get subscriber roles and display in registration page
|
|
*/
|
|
public function index() {
|
|
/**
|
|
* Display dynamic banner
|
|
*/
|
|
$this->load->model('personalization_model');
|
|
$this->registration->deleteCookies();
|
|
$new_banner = $this->personalization_model->upload_get_banner();
|
|
$white_label = $new_banner['description'];
|
|
$banner = (isset($new_banner['image']) && !empty($new_banner['image'])) ? $new_banner['image'] : '';
|
|
$this->data['page_banner_bg'] = $banner;
|
|
$this->data['page_banner_description'] = $white_label;
|
|
|
|
$this->data['user_roles'] = $this->User_registration_model->get_subscriber_roles();
|
|
$this->data['page_title'] = 'Adhésion';
|
|
$this->data['content'] = 'frontoffice/registration/registration_main_view';
|
|
$this->load->view('frontoffice_view', $this->data);
|
|
}
|
|
|
|
/**
|
|
* Post user type
|
|
*/
|
|
public function user_type(string $type='regular') {
|
|
/**
|
|
* Display dynamic banner
|
|
*/
|
|
$this->load->model('personalization_model');
|
|
$new_banner = $this->personalization_model->upload_get_banner();
|
|
$white_label = $new_banner['description'];
|
|
$banner = (isset($new_banner['image']) && !empty($new_banner['image'])) ? $new_banner['image'] : '';
|
|
$this->data['page_banner_bg'] = $banner;
|
|
$this->data['page_banner_description'] = $white_label;
|
|
|
|
$this->registration->deleteCookies();
|
|
$role = $this->registration->getUserTypeInfo($type);
|
|
// Save selected subscription type in cookie
|
|
$this->registration->setUserSubscriptionTypeCookie($role[0]);
|
|
|
|
// $this->data['page_title'] = 'Registration | ' . ucfirst($type);
|
|
|
|
if (ucfirst($type) === 'Regular') {
|
|
$this->data['page_title'] = 'Adhésion de soutien';
|
|
} elseif (ucfirst($type) === 'Shareholder') {
|
|
$this->data['page_title'] = 'Adhésion préférentielle actionnaire';
|
|
} elseif (ucfirst($type) === 'Sponsored') {
|
|
$this->data['page_title'] = 'Adhésion parrainée';
|
|
}
|
|
else {
|
|
$this->data['page_title'] = 'Adhésion étudiant';
|
|
}
|
|
$this->data['user_role'] = $role[0];
|
|
$this->data['content'] = 'frontoffice/registration/registration_user_type_view';
|
|
$this->data['sub_content'] = $this->registration->getViewByRole($role[0]['name']);
|
|
$this->data['load_scripts'] = array(
|
|
'<script src="' . auto_version(app_bundle() . 'frontoffice/registration.js').'" type="text/javascript"></script>'
|
|
);
|
|
$this->load->view('frontoffice_view', $this->data);
|
|
}
|
|
|
|
public function registration_details() {
|
|
/**
|
|
* Display dynamic banner
|
|
*/
|
|
$this->load->model('personalization_model');
|
|
$new_banner = $this->personalization_model->upload_get_banner();
|
|
$white_label = $new_banner['description'];
|
|
$banner = (isset($new_banner['image']) && !empty($new_banner['image'])) ? $new_banner['image'] : '';
|
|
$this->data['page_banner_bg'] = $banner;
|
|
$this->data['page_banner_description'] = $white_label;
|
|
|
|
$cookieData = $this->registration->getUserSubscriptionTypeCookie();
|
|
$this->registration->validateUriSegment($this->uri->segment(2), $cookieData->name);
|
|
|
|
//If role is not regular, save user predata in cookie
|
|
if($cookieData->name != 'Regular') {
|
|
if($cookieData->name == 'Student') {
|
|
//Load upload library
|
|
$fileName = $_FILES['student_file']['name'];
|
|
if(!empty($fileName)) {
|
|
$config = $this->registration->uploadConfig($fileName);
|
|
$this->load->library('upload', $config);
|
|
$this->upload->initialize($config);
|
|
mkUploadsDirectory();
|
|
if (! $this->upload->do_upload('student_file')) {
|
|
$this->data['upload_error_message'] = $this->upload->display_errors();
|
|
$this->registration->setUserPreInfoCookie(array(
|
|
'student_id' => $this->input->post('student_id')
|
|
));
|
|
} else {
|
|
$this->registration->setUserPreInfoCookie(array(
|
|
'student_file' => $this->upload->data()['file_name'],
|
|
'student_id' => $this->input->post('student_id')
|
|
));
|
|
}
|
|
} else {
|
|
$this->registration->setUserPreInfoCookie(array(
|
|
'student_id' => $this->input->post('student_id')
|
|
));
|
|
}
|
|
} else {
|
|
$this->registration->setUserPreInfoCookie($this->input->post());
|
|
}
|
|
}
|
|
$userDetails = $this->registration->getUserDetailsCookie();
|
|
if(!empty($userDetails) || !is_null($userDetails)) {
|
|
$this->data['user_details'] = $userDetails;
|
|
}
|
|
$this->data['countries'] = $this->registration->getAllCountries();
|
|
$this->data['states'] = $this->registration->getStatesByCountry('France');
|
|
// $this->data['page_title'] = 'Registration | '.$cookieData->name;
|
|
if ($cookieData->name === 'Regular') {
|
|
$this->data['page_title'] = 'Adhésion de soutien';
|
|
} elseif ($cookieData->name === 'Shareholder') {
|
|
$this->data['page_title'] = 'Adhésion préférentielle actionnaire';
|
|
} elseif ($cookieData->name === 'Sponsored') {
|
|
$this->data['page_title'] = 'Adhésion parrainée';
|
|
}
|
|
else {
|
|
$this->data['page_title'] = 'Adhésion étudiant';
|
|
}
|
|
|
|
$this->data['user_role'] = $cookieData;
|
|
$this->data['content'] = 'frontoffice/registration/registration_details_view';
|
|
$this->data['load_scripts'] = array
|
|
(
|
|
'<script src="' . auto_version(app_bundle() . 'frontoffice/registration.js').'" type="text/javascript"></script>'
|
|
);
|
|
$this->load->view('frontoffice_view', $this->data);
|
|
}
|
|
|
|
/**
|
|
* Post payment method and redirect to mercanet page
|
|
*/
|
|
public function payment() {
|
|
$modeOfPayment = $this->input->post('mode_of_payment');
|
|
$mop = $this->registration->checkModeOfPayment($modeOfPayment);
|
|
$cookieData = $this->registration->getUserSubscriptionTypeCookie();
|
|
if($mop == 'card') {
|
|
$this->registration->deleteUserDetailsCookie();
|
|
$this->registration->setUserDetailsCookie($this->input->post());
|
|
/* ========================== Start Axepta ============================= */
|
|
$paymentRequest = $this->registration->configurePayment($cookieData);
|
|
$paymentRequest->validate();
|
|
|
|
// compute
|
|
$mac = $paymentRequest->getShaSign();
|
|
$axeptaData = $paymentRequest->getBfishCrypt(); // run Crypt & retrieve Data
|
|
$len = $paymentRequest->getLen();
|
|
/* ========================== End Axepta ============================= */
|
|
$this->data['sub_content'] = "<form name=\"redirectForm\" method=\"GET\" action=\"" . $paymentRequest->getUrl() . "\">" .
|
|
"<input type=\"hidden\" name=\"MerchantID\" value=\"". $paymentRequest->getMerchantID() . "\">" .
|
|
"<input type=\"hidden\" name=\"Len\" value=\"". $paymentRequest->getLen() . "\">" .
|
|
"<input type=\"hidden\" name=\"Data\" value=\"". $paymentRequest->getBfishCrypt() . "\">" .
|
|
"<input type=\"hidden\" name=\"URLBack\" value=\"". $paymentRequest->getURLBack() . "\">" .
|
|
"<input type=\"hidden\" name=\"CustomField1\" value=\"". $paymentRequest->getAmount()/100 . "\">" .
|
|
"<input type=\"hidden\" name=\"CustomField2\" value=\"". $paymentRequest->getTransID() . "\">" .
|
|
"<input type=\"hidden\" name=\"CustomField8\" value=\"". $this->input->post('firstname') . ' ' . $this->input->post('lastname') . "\">" .
|
|
"<noscript><input type=\"submit\" name=\"Go\" value=\"Click to continue\"/></noscript> </form>" .
|
|
"<input type=\"hidden\" name=\"Background\" value=\"https://www.myshnop.fr/graphic/background.jpg\">" .
|
|
"<script type=\"text/javascript\">document.redirectForm.submit(); </script>";
|
|
$this->data['content'] = 'frontoffice/registration/mercanet_view';
|
|
$this->data['page_title'] = "Adhésion | Paiement";
|
|
} else {
|
|
// User select cheque payment
|
|
$userDetails = $this->input->post(); //array
|
|
$userPreInfo = (array)$this->registration->getUserPreInfoCookie();
|
|
if($cookieData->name != 'Regular') {
|
|
|
|
if($cookieData->name == 'Student' && array_key_exists('student_file', $userPreInfo)) {
|
|
copyUploadedFile($userPreInfo['student_file']);
|
|
deleteTmpUploadedFile($userPreInfo['student_file']);
|
|
}
|
|
}
|
|
//Save subscription
|
|
$user = $this->registration->saveSubscription($userDetails, $userPreInfo, (array) $cookieData, null);
|
|
//Create notification
|
|
$this->load->model('Notification_model');
|
|
$notification = array(
|
|
'user_id' => $user->userData['userId'],
|
|
'type' => 'registration',
|
|
'status' => 0
|
|
);
|
|
$this->Notification_model->save_notification($notification);
|
|
//Clear all cookies
|
|
$this->registration->deleteCookies();
|
|
|
|
$isLoggedIn = $this->registration->autoLogin($user);
|
|
|
|
redirect(base_url($isLoggedIn ? '/home' : '/registration'));
|
|
// $this->data['page_title'] = 'Adhésion étudiant';
|
|
// $this->data['inputs'] = $isLoggedIn;
|
|
// $this->data['content'] = 'frontoffice/registration/registration_payment_receipt_view';
|
|
}
|
|
$this->load->view('frontoffice_view', $this->data);
|
|
}
|
|
|
|
public function payment_receipt() {
|
|
$cookieData = $this->registration->getUserSubscriptionTypeCookie();
|
|
$userDetails = $this->registration->getUserDetailsCookie();
|
|
//Redirect to registration step 1 if user details is empty
|
|
if(empty($userDetails) || is_null($userDetails)) {
|
|
redirect(base_url('/registration'));
|
|
}
|
|
|
|
$paymentResponse = new Axepta(MERCANET['HMAC']);
|
|
$paymentResponse->setCryptKey(MERCANET['Blowfish']);
|
|
$paymentResponse->setResponse($_POST);
|
|
$userPreInfo = (array)$this->registration->getUserPreInfoCookie();
|
|
try {
|
|
if($paymentResponse->isValid() && $paymentResponse->isSuccessful()) {
|
|
// all response parameters access with "get" prefix method
|
|
$receipt = array(
|
|
'payId' => $paymentResponse->getPayID(),
|
|
'transactionReference' =>$paymentResponse->getTransID(),
|
|
'PCNr' => $paymentResponse->getPCNr(),
|
|
'CCBrand' => $paymentResponse->getCCBrand(),
|
|
'transactionDateTime' => date('Y-m-d')
|
|
);
|
|
if($cookieData->name != 'Regular') {
|
|
if($cookieData->name == 'Student' && array_key_exists('student_file', $userPreInfo)) {
|
|
copyUploadedFile($userPreInfo['student_file']);
|
|
deleteTmpUploadedFile($userPreInfo['student_file']);
|
|
}
|
|
}
|
|
//Save subscription
|
|
$user = $this->registration->saveSubscription((array) $userDetails, $userPreInfo, (array) $cookieData, $receipt);
|
|
//Clear all cookies
|
|
$this->registration->deleteCookies();
|
|
|
|
// Login user
|
|
$isLoggedIn = $this->registration->autoLogin($user);
|
|
|
|
redirect(base_url($isLoggedIn ? '/home' : '/registration'));
|
|
} else {
|
|
$this->registration->setFailurePamentCookie('Authentication protocol error');
|
|
redirect(base_url('/registration/'.lcfirst($cookieData->name).'/details'));
|
|
}
|
|
} catch(Exception $e) {
|
|
$this->registration->setFailurePamentCookie('Authentication protocol error');
|
|
redirect(base_url('/registration/'.lcfirst($cookieData->name).'/details'));
|
|
}
|
|
}
|
|
public function payment_cancel() {
|
|
$cookieData = $this->registration->getUserSubscriptionTypeCookie();
|
|
$this->registration->setFailurePamentCookie('Cancelled payment');
|
|
redirect(base_url('/registration/'.lcfirst($cookieData->name).'/details'));
|
|
}
|
|
|
|
/**
|
|
* Get states of a country
|
|
*/
|
|
public function get_states() {
|
|
$country = $this->input->get('country');
|
|
$result=$this->registration->getStatesByCountry($country);
|
|
return output_to_json($this, $result);
|
|
}
|
|
|
|
public function check_failure_payment() {
|
|
//Check if has payment notification
|
|
$result = [];
|
|
$notif = $this->registration->getFailurePamentCookie();
|
|
if(!empty($notif) && !is_null($notif)) {
|
|
$result['failure_message'] = $notif->message;
|
|
$this->registration->deleteFailurePamentCookie();
|
|
}
|
|
return output_to_json($this, $result);
|
|
}
|
|
}
|