コード例 #1
0
ファイル: Logger.php プロジェクト: henvic/MediaLab
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #2
0
ファイル: LoginController.php プロジェクト: henvic/MediaLab
 public function indexAction()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $config = $registry->get("config");
     $sessionConfig = $config['resources']['session'];
     Ml_Model_AntiAttack::loadRules();
     $credential = Ml_Model_Credential::getInstance();
     $logger = Ml_Model_Logger::getInstance();
     if ($auth->hasIdentity()) {
         return $this->_forward("goback");
     }
     $request = $this->getRequest();
     $form = $credential->loginForm();
     if (Ml_Model_AntiAttack::ensureHuman()) {
         $ensureHuman = true;
     } else {
         $ensureHuman = false;
     }
     if ($request->isPost()) {
         ignore_user_abort(true);
         //A way to sign in only if captcha is right. This is a workaround to
         //signout if the captcha is wrong.
         //
         //I've decided to put the sign in code in the validator itself,
         //but couldn't find a way to make the password validator
         //load after the captcha one (but to let it come first in code,
         //and that's ugly on the screen) and get a result if the
         //validation worked. Notice that it is only useful when
         //the captcha is required.
         if ($form->isValid($request->getPost())) {
             //@see below
             $session = Ml_Model_Session::getInstance();
             //rememberMe and ForgetMe already regenerates the ID
             if ($form->getElement("remember_me")->isChecked()) {
                 Zend_Session::rememberMe($sessionConfig['cookie_lifetime']);
             } else {
                 Zend_Session::ForgetMe();
             }
             $session->associate($auth->getIdentity(), Zend_Session::getId());
             $logger->log(array("action" => "login", "username" => $form->getValue("username")));
             $this->_forward("goback");
         } else {
             //@see above
             if ($auth->hasIdentity()) {
                 $auth->clearIdentity();
             }
             $logger->log(array("action" => "login_denied", "username" => $form->getValue("username")));
             $this->view->errorlogin = true;
         }
         //@end of workaround
     }
     $challenge = $form->getElement("challenge");
     //don't show missing value in the first time that asks for the captcha
     if (!$ensureHuman && is_object($challenge)) {
         $challenge->setErrorMessages(array("missingValue" => ''));
     }
     $this->view->loginform = $form;
 }
コード例 #3
0
ファイル: Session.php プロジェクト: henvic/MediaLab
 public function remoteLogout()
 {
     $logger = Ml_Model_Logger::getInstance();
     $auth = Zend_Auth::getInstance();
     $logger->log(array("action" => "remote_logout_request"));
     $sessionsList = $this->listRecentSessionsMeta($auth->getIdentity());
     $currentSid = Zend_Session::getId();
     $this->removeSessions($sessionsList, $currentSid);
     $stmt = 'UPDATE ' . $this->_dbAdapter->quoteTableAs($this->_dbTable->getTableName()) . ' ' . 'SET `status` = ?, `end` = CURRENT_TIMESTAMP, `end_remote_addr` = ? ' . 'WHERE `status` = ? AND `uid` = ? AND `session` != ?';
     $this->_dbAdapter->query($stmt, array(self::CLOSE_REMOTE_STATUS, $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : null, self::OPEN_STATUS, $auth->getIdentity(), $currentSid));
 }
コード例 #4
0
ファイル: Credits.php プロジェクト: henvic/MediaLab
 /**
  * makes a coupon's based transaction
  * @param big int $uid
  * @param faken hexdec $coupon
  */
 public function couponTransaction($uid, $coupon)
 {
     $coupons = Ml_Model_Coupons::getInstance();
     $logger = Ml_Model_Logger::getInstance();
     $this->_dbAdapter->beginTransaction();
     $couponData = $coupons->get($coupon, true);
     if (is_array($couponData)) {
         if ($couponData['unique_use']) {
             $stateChange = $coupons->state($couponData['hash'], false);
             if (!$stateChange) {
                 $this->_dbAdapter->rollBack();
                 return false;
             }
         } else {
             if (!$couponData['unique_use']) {
                 //then checks if it was already used by this user:
                 //using fetchRow 'cause 1 result is enough
                 $isItUsed = $this->_dbTable->fetchRow($this->_dbTable->select()->where("binary `uid` = ?", $uid)->where("reason_type = ?", self::COUPON_REDEEM)->where("binary `reason_id` = ?", $couponData['id']));
                 if (is_object($isItUsed)) {
                     $this->_dbAdapter->rollBack();
                     return false;
                 }
             }
         }
         $this->insert(array("pid" => $this->makeUUId(), "uid" => $uid, "amount" => $couponData['amount'], "sack" => $couponData['sack'], "reason_type" => self::COUPON_REDEEM, "reason_id" => $couponData['id']));
         $transactionId = $this->_dbAdapter->lastInsertId();
         $logger->log(array("action" => "transaction", "transaction" => $transactionId));
         $this->_dbAdapter->commit();
         return $transactionId;
     }
 }