public function isValid($value) { $isValid = true; $valueString = (string) $value; $this->_setValue($valueString); $tbl = new DbTable_Account(); $Account = Service_Auth::getAccount(); $select = $tbl->select()->where('username = ?', $Account->username); $select->where('password = ?', md5($value)); $row = $tbl->fetchRow($select); if ($row === null) { $isValid = false; $this->_error(self::UNKNOWN); } return $isValid; }
public function useCouponAction() { // Load cac model can thiet Zend_Loader::loadClass('UserModel'); Zend_Loader::loadClass('CouponModel'); $user_model = new UserModel(); $params = $this->_arrParam; if ($this->_request->isPost()) { if (!empty($params['coupon_value'])) { try { if (!empty($this->_user)) { $coupon_model = new CouponModel(); $result = $coupon_model->getCoupon($params); $where = "user_id = " . $this->_user->user_id; if (!empty($result)) { switch ($result['code']) { case "1": $money = 15000; break; case "2": $money = 30000; break; case "5": $money = 75000; break; case "10": $money = 150000; break; default: $money = 15000; break; } $user_model->update(array("user_gome" => new Zend_Db_Expr("user_gome + " . $money)), $where); $coupon_model->update(array("status" => 0, "use_user" => $this->_user->user_id, "use_time" => date("Y-m-d H:i:s", time())), "id=" . $result['id']); $user = $user_model->getUserById($this->_user->user_id); $data = array("code" => 1, "content" => array("user_gome" => $user['user_gome'])); } else { $user = $user_model->getUserById($this->_user->user_id); if ($user['wrong_coupon_day'] == date("Y-m-d")) { $user_model->update(array("wrong_coupon" => new Zend_Db_Expr("wrong_coupon + 1")), $where); } else { $user_model->update(array("wrong_coupon" => 1, "wrong_coupon_day" => date("Y-m-d")), $where); } $message = "Invalid coupon"; // cap nhat luot block $user = $user_model->getUserById($this->_user->user_id); if ($user['wrong_coupon'] >= 3) { if ($user['block_month'] == date("Y-m")) { // xet xem lan block nay co cung mot thang ko? $user_model->update(array("status" => BLOCK_STATUS, "active_time" => time() + 86400, "number_block" => new Zend_Db_Expr("number_block + 1")), $where); } else { $user_model->update(array("status" => BLOCK_STATUS, "active_time" => time() + 86400, "number_block" => 1, "block_month" => date("Y-m")), $where); } $auth = new Service_Auth(); $auth->logout(); $message = "Enter invalid coupon over 3 times. This account is temporarily blocked"; } // xet xem co bi xoa vinh vien $user = $user_model->getUserById($this->_user->user_id); if ($user['number_block'] >= 3) { $user_model->update(array("status" => DELETE_FOREVER_STATUS), $where); $user_model->addBlacklist($user); $message = "Blocked over 3 times. This account has been permanently deleted"; } $data = array("code" => 0, "content" => $message); } } else { $data = array("code" => 0, "content" => "Authentication failed"); } } catch (exception $e) { $data = array("code" => 0, "content" => "Error in server"); } } else { $data = array("code" => 0, "content" => "Invalid parameters"); } echo json_encode($data); } exit; }
public function checkLogin($params) { $auth = new Service_Auth(); return $auth->login($params); }