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.
111 lines
4.0 KiB
111 lines
4.0 KiB
<?php
|
|
namespace app\core\utils;
|
|
|
|
use app\core\auth\User as UserAuth;
|
|
|
|
class Response {
|
|
public static function backToHomepage() {
|
|
if (UserAuth::isBOUser())
|
|
return redirect(base_url('dashboard'));
|
|
if (UserAuth::isFOUser())
|
|
return redirect(base_url('home'));
|
|
|
|
return redirect(base_url('logout'));
|
|
}
|
|
|
|
public static function showPage404($page) {
|
|
if(UserAuth::isAuth() && UserAuth::isBOUser())
|
|
redirect(base_url("dashboard"));
|
|
}
|
|
|
|
public static function backToReferrerDefaultPage() {
|
|
// Get CodeIgniter instance
|
|
$CI =& get_instance();
|
|
|
|
$prevPage = $CI->agent->referrer();
|
|
|
|
if (!$prevPage) return redirect(base_url());
|
|
|
|
$prevPage = explode('/',str_replace(base_url(), "", $prevPage));
|
|
|
|
// Redirect to Frontoffice page
|
|
if (in_array($prevPage[0], FO_PAGES)) {
|
|
return redirect(base_url());
|
|
}
|
|
|
|
// Redirect to Backoffice Login page
|
|
return redirect(base_url("auth"));
|
|
}
|
|
|
|
/**
|
|
* All pages in Backoffice are authenticated, so unauthenticated user will be auto-logoff.
|
|
* While, some pages in the Frontoffice are accessible even when the user is not login
|
|
*
|
|
* For example, (UserAuth::isAuth() && !UserAuth::auth() && $disposition === "fo") this condition checks
|
|
* whether the session of the login user has expired on page load.
|
|
*/
|
|
public static function handleSessionTimeoutOnPageLoad($disposition = "fo") {
|
|
if ( (!UserAuth::isAuth() && $disposition === "bo") || (UserAuth::isAuth() && !UserAuth::auth() && $disposition === "fo") ) {
|
|
return json_encode(self::timeoutMessageArray($disposition));
|
|
}
|
|
|
|
return json_encode(array("mtype" => "active"));
|
|
}
|
|
|
|
public static function handleSessionTimeout($disposition="fo", $whiteListedPage = []) {
|
|
// Get CodeIgniter instance
|
|
$CI =& get_instance();
|
|
|
|
// Skip Auth check for whitelisted routes
|
|
if (countVal($whiteListedPage)) {
|
|
$currentURL = current_url();
|
|
foreach($whiteListedPage as $wlp) {
|
|
if (base_url($wlp) === $currentURL)
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!UserAuth::isAuth()) {
|
|
if($disposition !== "bo_redirect_now" && $disposition !== "fo_redirect_now") {
|
|
output_to_json($CI, self::timeoutMessageArray($disposition));
|
|
} else {
|
|
redirect(!UserAuth::isAuth()
|
|
? base_url("logout")
|
|
: base_url($disposition === "bo_redirect_now" ? "auth" : "login-user"));
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function timeoutMessageText($login_info) {
|
|
// Get CodeIgniter instance
|
|
$CI =& get_instance();
|
|
|
|
// SuperAdmin loggedin as subscriber
|
|
if($login_info && isset($login_info["token_id"]) && !empty($login_info['token_id'])) {
|
|
$CI->load->model('user_login_history_model');
|
|
$checker = $CI->user_login_history_model->check_user_is_logged_in($login_info["login_id"], $login_info["token_id"]);
|
|
if($checker == 1){
|
|
return "L'abonné est maintenant connecté. Vous serez redirigé vers la page de connexion sous peu.";
|
|
} else {
|
|
return " Votre session de connexion à la place de l’abonné a expiré.";
|
|
}
|
|
} else {
|
|
return $CI->lang->line("session_timeout");
|
|
}
|
|
}
|
|
|
|
public static function timeoutMessageArray($disposition) {
|
|
return array(
|
|
"mtype" => "session_timeout",
|
|
"message" => self::timeoutMessageText(UserAuth::auth()),
|
|
"mdetail" => array(
|
|
"redirect" => 4000,
|
|
"path" => (UserAuth::isAuth()
|
|
? base_url("logout")
|
|
// : base_url($disposition === "bo" ? "auth" : "login-user"),
|
|
: $disposition === base_url("bo")) ? base_url("auth") : "https://website.c-pay.me",
|
|
"login_window" => false
|
|
)
|
|
);
|
|
}
|
|
}
|