/** * Check if admin has Latch enabled * * @param string $latchId * @param Mage_Admin_Model_User $user * @return array */ public function getIfAdminLatchEnabled($latchId, $user) { $appId = $this->getApplicationId(); $appSecret = $this->getSecretKey(); $apiUrl = $this->getApiUrl(); if (!empty($latchId) && !empty($appId) && !empty($appSecret)) { require_once Mage::getBaseDir('lib') . '/Latch/latch.php'; if ($apiUrl) { $api = new Latch($appId, $appSecret, $apiUrl); } else { $api = new Latch($appId, $appSecret); } $apiResponse = $api->status($latchId); $responseData = $apiResponse->getData(); $responseError = $apiResponse->getError(); if (empty($apiResponse) || empty($responseData) && empty($responseError)) { return array("status" => 0, "message" => $this->__("Latch is not ready. Please try to log out and log in again.")); } else { if (!empty($responseError)) { if ($responseError->getCode() == 201) { $user->setData('latch_id', $latchId); try { $user->save(); } catch (Exception $ex) { return array("status" => 0, "message" => $this->__("Something was wrong, please try to log in again later: ") . $this->__($ex->getMessage())); } } else { return array("status" => 0, "message" => $this->__("Something was wrong, please try to log in again later.")); } } } if (!empty($responseData) && $responseData->{"operations"}->{$appId}->{"status"} === "on") { return array("status" => 0, "message" => ""); } else { return array("status" => 1, "message" => $this->__("Invalid login or password")); } } }
/** * Set the data from ini file to the user object and save. * * @param Mage_Admin_Model_User $user A user object * @return Mage_Admin_Model_User */ public function createUser(Mage_Admin_Model_User $user) { return $user->setData($this->data)->save(); }