/**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     try {
         $resp = new Maestrano_Saml_Response($_POST['SAMLResponse']);
         // Check if the Saml response is valid
         if ($resp->isValid()) {
             // Get the user as well as the user group
             $mnoUser = new Maestrano_Sso_User($resp);
             // intilize the user Model
             $userModel = new Maestrano_Sso_Model_User();
             // Find user in db by email if not exist then create locally
             $userResp = $userModel->findOrCreate($mnoUser);
             if ($userResp['id_employee'] > 0) {
                 //update the Cookie for prestashop
                 $cookie = new Cookie('psAdmin');
                 $cookie->id_employee = $userResp['id_employee'];
                 $cookie->email = $mnoUser->email;
                 $cookie->profile = $userResp['id_profile'];
                 $cookie->passwd = $userResp['passwd'];
                 $cookie->remote_addr = (int) ip2long(Tools::getRemoteAddr());
                 $cookie->last_activity = time();
                 // write the cookie in Prestashop session
                 $cookie->write();
                 // Once the user is created/identified, we store the maestrano session.
                 // This session will be used for single logout
                 $mnoSession = new Maestrano_Sso_Session($_SESSION, $mnoUser);
                 $mnoSession->save();
                 // If logged in redirect to admin dashboard startup page
                 if ($cookie->id_employee) {
                     $cookie = new Cookie('psAdDir');
                     Tools::redirect(Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . $cookie->admin_directory);
                 }
             }
         } else {
             echo '<p>There was an error during the authentication process.</p><br/>';
             echo '<p>Please try again. If issue persists please contact support@maestrano.com<p>';
             exit;
         }
     } catch (Exception $ex) {
         echo $ex;
         exit;
     }
 }
Esempio n. 2
0
}
session_unset();
session_destroy();
// Restart session and inject previous url if defined
session_start();
if (isset($previous_url)) {
    $_SESSION['mno_previous_url'] = $previous_url;
}
// Options variable
if (!isset($opts)) {
    $opts = array();
}
// Build SAML response
$samlResponse = new Maestrano_Saml_Response($_POST['SAMLResponse']);
try {
    if ($samlResponse->isValid()) {
        // Get the user as well as the user group
        $user = new Maestrano_Sso_User($samlResponse);
        // Get Maestrano User
        $sso_user = new MnoSsoUser($samlResponse, $opts);
        // Find or create the User
        $sso_user->findOrCreate();
        // Once the user is created/identified, we store the maestrano session.
        // This session will be used for single logout
        $mnoSession = new Maestrano_Sso_Session($_SESSION, $user);
        $mnoSession->save();
        // Redirect the user to previous or home page
        if (isset($_SESSION['mno_previous_uri'])) {
            header('Location: ' . $_SESSION['mno_previous_uri']);
        } else {
            header('Location: /wp-admin');