Example #1
0
 /**
  * 注册
  */
 public function registerAction()
 {
     $username = trim($this->getRequest()->getPost('username', ''));
     $password = trim($this->getRequest()->getPost('password', ''));
     $email = trim($this->getRequest()->getPost('email', ''));
     //校验参数是否为空
     if (empty($username) || empty($password) || empty($email)) {
         $this->getView->assign('message', '参数不能为空');
         $this->getView->render('/user/index.phtml');
     }
     $userModel = new UserModel();
     //校验用户名是否存在
     $isExistUsername = $userModel->getUserByUsername($username);
     if ($isExistUsername) {
         $this->getView->assign('message', '用户名已存在');
         $this->getView->render('/user/index.phtml');
     }
     //校验邮箱是否存在
     $isExistEmail = $userModel->getUserByEmail($email);
     if ($isExistEmail) {
         $this->getView()->assign('message', '邮箱已存在');
         $this->getView()->render('/user/index.phtml');
     }
     //进行注册
     $flag = $userModel->addUser($username, $password, $email);
     //如果成功,登录返回首页
     if ($flag) {
         Yaf_Session::getInstance()->set('userId', $flag);
         $this->getView()->render('/index/index.phtml');
     } else {
         $this->getView()->assign('message', '注册失败');
         $this->getView()->render('/user/index.phtml');
     }
 }
Example #2
0
 public function listAction()
 {
     $where = Yaf_Session::getInstance()->get("user_uuid");
     $favData = $this->_fav->selectAll($where);
     $this->getView()->assign("items", $favData);
     return true;
 }
Example #3
0
 public function _initSession($dispatcher)
 {
     /*
      * start a session 
      */
     Yaf_Session::getInstance()->start();
 }
Example #4
0
 public function listAction()
 {
     $where = Yaf_Session::getInstance()->get("order_serial");
     $orderData = $this->_order->selectAll($where);
     $this->getView()->assign("items", $orderData);
     return true;
 }
Example #5
0
 /**
  * 完成待办事项
  */
 public function finishTodoAction()
 {
     $result = array('status' => 'fail', 'message' => '操作失败');
     //判断是否登录
     $userId = Yaf_Session::getInstance()->get('userId');
     if (empty($userId)) {
         $result = '请您登陆';
         echo json_encode($result);
         exit;
     }
     //判断参数是否为空
     $id = trim($this->getRequest()->getPost('id', ''));
     if (empty($id)) {
         $result['message'] = '操作失败,参数不能为空';
     } else {
         $todoModel = new TodoModel();
         $todo = $todoModel->getTodoById($id);
         //判断是否是待办拥有者
         if (!empty($todo) && $userId == $todo['user_id']) {
             $flag = $todoModel->updateTodoStatus($id);
             if ($flag) {
                 $result['status'] = 'success';
                 $result['message'] = '操作成功';
             } else {
                 $result['message'] = '操作失败';
             }
         } else {
             $result['message'] = '操作失败,非事项所有者';
         }
     }
     echo json_encode($result);
     exit;
 }
Example #6
0
 /**
  * @runInSeparateProcess
  */
 public function testCase016()
 {
     $_SESSION["name"] = "Laruence";
     $age = 28;
     $this->session->age = $age;
     $this->assertEquals($age, $this->session->age);
     $this->assertEquals($_SESSION['age'], $this->session->age);
     $session2 = Yaf_Session::getInstance();
     $session2['company'] = 'Baidu';
     $this->assertTrue(isset($session2->age));
     $this->assertTrue($session2->has('age'));
     $this->assertTrue($session2->has('name'));
     $this->assertEquals(2, count($session2));
     $currentInSession = $_SESSION;
     foreach ($session2 as $key => $value) {
         $this->assertEquals($currentInSession[$key], $value);
     }
     unset($session2);
     $session3 = Yaf_Session::getInstance();
     $session3->del("name");
     $this->assertFalse($session3->has('name'));
     $this->assertFalse(isset($session3->name));
     unset($session3["company"]);
     unset($session3->age);
     $this->assertEquals(0, count($session3));
 }
Example #7
0
 public function loginAction()
 {
     if ($this->getRequest()->isPost()) {
         $username = $this->getRequest()->getPost('username');
         $pwd = $this->getRequest()->getPost('password');
         $ret = $this->_user->loginUser($username, sha1(trim($pwd)));
         if ($ret) {
             //$_SESSION['username']=$username."ddd"; //这种方式已经不使用了
             Yaf_Session::getInstance()->set("username", $username);
             //$ret如果是正确的,那么返回的是user_uuid
             Yaf_Session::getInstance()->set("user_uuid", $ret);
             $had_order_serial = Yaf_Session::getInstance()->get("order_serial");
             if (!$had_order_serial) {
                 $order_serial = date('U') . '98' . rand(10000, 99999);
                 Yaf_Session::getInstance()->set("order_serial", $order_serial);
             }
             var_dump(Yaf_Session::getInstance());
             // exit("登录成功!");
             exit($this->_util->ret_json(0, "登陆成功"));
         } else {
             //$this->getView()->assign("content",'登陆不成功!!');
             exit($this->_util->ret_json(1, "登陆失败"));
         }
     }
     return true;
 }
Example #8
0
 public function _init(Yaf_Dispatcher $dispatcher)
 {
     // auto start session
     Yaf_Session::getInstance()->start();
     // auto load config data
     $this->config = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('Config', $this->config);
     //auto load redis
     $redis = new Redis();
     $redis->connect($this->config->redis->host, $this->config->redis->port, $this->config->redis->timeout, $this->config->redis->reserved, $this->config->redis->interval);
     Yaf_Registry::set('Redis', $redis);
     //auto load mysql
     Yaf_Registry::set('DbRead', new Db('mysql:host=' . $this->config->mysql->read->host . ';dbname=' . $this->config->mysql->read->dbname . ';charset=' . $this->config->mysql->read->charset . ';port=' . $this->config->mysql->read->port . '', $this->config->mysql->read->username, $this->config->mysql->read->password));
     Yaf_Registry::set('DbWrite', new Db('mysql:host=' . $this->config->mysql->write->host . ';dbname=' . $this->config->mysql->write->dbname . ';charset=' . $this->config->mysql->write->charset . ';port=' . $this->config->mysql->write->port . '', $this->config->mysql->write->username, $this->config->mysql->write->password));
     // auto load model
     Yaf_Registry::set('I18n', new I18nModel($redis, $this->config->application->name, 'cn'));
     Yaf_Registry::set('Cache', new CacheModel($redis, $this->config->application->name));
     // auto load plugin
     $dispatcher->registerPlugin(new GlobalPlugin());
     // auto save request
     $request = $dispatcher->getRequest();
     // auto set ajax is no render
     if ($request->isXmlHttpRequest()) {
         $dispatcher->autoRender(false);
     }
     // auto set http protocol to action except http get protocol
     if (!$request->isGet()) {
         $dispatcher->setDefaultAction($request->getMethod());
     }
 }
Example #9
0
 public function indexAction()
 {
     $request = new Yaf_Request_Http();
     if ($request->isGet()) {
         return;
     }
     if ($request->isPost()) {
         $post = $request->getPost();
         $username = $post['username'];
         $password = $post['password'];
         if ($username == 'admin' && $password == 'admin') {
             Yaf_Session::getInstance()->offsetSet('username', $username);
             $this->redirect("Admin");
             // 跳转到login Actios->forward("login", array("from" => "Index")); // 跳转到login Action
             return FALSE;
         } else {
             $password = md5($password);
             $sql = 'SELECT * FROM user WHERE username=:username AND password=:password';
             $stmt = $this->dbo->prepare($sql);
             $stmt->bindValue(':username', $username);
             $stmt->bindValue(':password', $password);
             $stmt->execute();
             $rows = $stmt->fetch();
             if (empty($rows)) {
                 echo "用户名或密码错误";
             } else {
                 Yaf_Session::getInstance()->offsetSet('username', $username);
                 Yaf_Session::getInstance()->offsetSet('userid', $rows['id']);
                 $this->redirect('Admin');
                 return;
             }
         }
         exit;
     }
 }
Example #10
0
 public function init()
 {
     $this->_config = Yaf_Registry::get('config');
     $this->_req = $this->getRequest();
     $this->_session = Yaf_Session::getInstance();
     $this->_session->start();
 }
Example #11
0
File: Admin.php Project: xn1224/YOF
 public function checkLogin()
 {
     $adminID = Yaf_Session::getInstance()->__get('adminID');
     if (!$adminID) {
         jsRedirect('/admin/login');
     }
 }
Example #12
0
 /**
  * Retrieve singleton instance
  *
  * @return Yaf_Session
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
         self::start();
     }
     return self::$_instance;
 }
Example #13
0
 public function init()
 {
     $session = Yaf_Session::getInstance();
     $this->uid = $session->offsetGet('uid');
     $clazz = get_class($this);
     $this->logger = Logger::LOG($clazz);
     $this->_view->setRequest($this->getRequest());
     $this->client = HaloClient::singleton();
 }
Example #14
0
 public function init()
 {
     $this->catmodel = new CatModel();
     $this->session = Yaf_Session::getInstance();
     $actionname = $this->getRequest()->getActionName();
     if (!loginstatus() && !in_array($actionname, $this->nologin())) {
         $this->redirect(BASE_URL);
     }
 }
Example #15
0
 public function init()
 {
     $this->_config = Yaf_Registry::get('config');
     $this->_req = $this->getRequest();
     $this->_session = Yaf_Session::getInstance();
     $this->_session->start();
     if (!$this->_session->has('username')) {
         $this->redirect('/index/');
     }
 }
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $if_in_router_white = $this->check_router($request);
     if ($if_in_router_white) {
         contast_router::getInstance()->setIFrouterWhite(TRUE);
     }
     if (!Yaf_Session::getInstance()->get('userinfo') && !$if_in_router_white) {
         $request->setModuleName('Index');
         $request->setControllerName('Login');
         $request->setActionName('index');
     }
 }
Example #17
0
 public function addAction()
 {
     $posts['order_serial'] = Yaf_Session::getInstance()->get("order_serial");
     $posts['status'] = "已成功送到";
     //生成新的购物车序列号
     $order_serial = date('U') . '98' . rand(10000, 99999);
     Yaf_Session::getInstance()->set("order_serial", $order_serial);
     if ($this->_orderStatus->insert($posts)) {
         exit("结算成功");
     } else {
         exit("结算失败");
     }
     return false;
 }
Example #18
0
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     //print_r(Yaf_Application::app()->getModules());
     if (Yaf_Session::getInstance()->get("username")) {
         //echo "亲爱的用户 ".Yaf_Session::getInstance()->get("username")." 你好<br>";
     } else {
         if ($request->getControllerName() == "User") {
         } else {
             if ($request->getControllerName() == "Admin") {
             } else {
                 //header("Location:/user");
             }
         }
     }
 }
Example #19
0
 function init()
 {
     $this->userinfo = models_user::getInstance()->getUserInfo();
     $this->user_id = is_array($this->userinfo) && array_key_exists('user_id', $this->userinfo) ? $this->userinfo['user_id'] : 0;
     self::check_login();
     $this->db = db_contect::db();
     $this->check = rest_Check::instance();
     $this->quantity = rest_Quantity::instance();
     $this->rest = rest_Server::instance();
     $this->modified = rest_Modified::instance();
     $this->session = Yaf_Session::getInstance();
     $this->mkData = rest_Mkdata::instance();
     $this->setScaffoldConfig();
     $this->ScaffoldRoute();
     $this->setConfig();
 }
Example #20
0
 public function init()
 {
     $session = Yaf_Session::getInstance();
     $this->uid = $session->offsetGet('uid');
     if (empty($this->uid)) {
         $this->uid = false;
     }
     $this->_view->setRequest($this->getRequest());
     $this->view = $this->_view;
     $this->view->bodyId = $this->_request->controller . "_" . $this->_request->action;
     $this->view->uid = $this->uid;
     $this->view->title = 'CMS_Admin';
     $this->view->desc = 'YafCMS';
     $this->view->notAction = '无权限访问';
     $this->doInit();
 }
Example #21
0
 public static function isLogin()
 {
     if (isset($_REQUEST['login'])) {
         return $_REQUEST['login'];
     }
     if (!isset($_COOKIE['wrm_aid']) || !isset($_COOKIE['wrm_atype'])) {
         return false;
     } else {
         $cookieId = UidEncryptUtil::decryptUid($_COOKIE['wrm_aid']);
         $cookieType = $_COOKIE['wrm_atype'];
         $session = Yaf_Session::getInstance();
         $oauthId = $session->offsetGet('wrm_oauth_id');
         $oauthType = $session->offsetGet('wrm_oauth_type');
         $oauthExpire = intval($session->offsetGet('wrm_oauth_expire'));
         $oauthToken = $session->offsetGet("wrm_oauth_token");
         self::getClient($cookieType);
         if ($cookieId != $oauthId || $cookieType != $oauthType) {
             if (!empty($oauthId)) {
                 self::delSession();
             }
             return false;
             UserApi::getAccessToken($cookieId, $cookieType);
             $oauthToken = $session->offsetGet("wrm_oauth_token");
         }
         if (empty($oauthToken)) {
             self::delSession();
             self::delCookie();
             return false;
         }
         if ($oauthExpire > time()) {
             self::$client = null;
             self::getClient($cookieType);
             return true;
         } else {
             if (!empty($oauthId) && !empty($oauthType)) {
                 $client = self::getClient($oauthType);
                 $client->getAccessToken();
                 if ($client->expireTime > time()) {
                     return true;
                 }
             }
             self::delSession();
             self::delCookie();
             return false;
         }
     }
 }
Example #22
0
 public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $session = Yaf_Session::getInstance();
     $uid = $session->offsetGet('uid');
     $url = $request->getRequestUri();
     $controller_name = strtolower($request->getControllerName());
     $action_name = strtolower($request->getActionName());
     $request_type = $request->getParam('request_type', 'page');
     //        print_R($action_name);
     if (empty($uid)) {
         if (stripos($url, 'login') === false) {
             $this->headerLocation('/index/login');
         }
     } else {
         return true;
     }
 }
Example #23
0
 private function _checkPerm($module, $controller, $action)
 {
     $username = Yaf_Session::getInstance()->offsetGet('username');
     if ($username == 'admin') {
         return true;
     } else {
         $userid = Yaf_Session::getInstance()->offsetGet('userid');
         $sql = 'SELECT * FROM userrole ur LEFT JOIN role r ON ur.rid=r.id WHERE ur.uid=:uid AND lower(r.modulename)=:modulename AND lower(r.controllername)=:controllername AND lower(r.actioname)=:actioname';
         $stmt = $this->dbo->prepare($sql) or die(print_r($this->dbo->errorInfo()));
         $stmt->bindValue(':uid', $userid);
         $stmt->bindValue(':modulename', $module);
         $stmt->bindValue(':controllername', $controller);
         $stmt->bindValue(':actioname', $action);
         $stmt->execute();
         $row = $stmt->fetchAll();
         if (empty($row)) {
             return false;
         }
         return true;
     }
 }
Example #24
0
 public function _initSesson()
 {
     $sesson = Yaf_Session::getInstance();
     Yaf_Registry::set('sesson', $sesson);
 }
Example #25
0
 public function unsetSession($key)
 {
     return Yaf_Session::getInstance()->__unset($key);
 }
Example #26
0
 public static function getWeiboClient()
 {
     $key = __METHOD__;
     $res = Yaf_Registry::get($key);
     if (empty($res)) {
         $config = Yaf_Registry::get("config");
         $session = Yaf_Session::getInstance();
         $token = UserTokenModel::singleton()->getToken($session->offsetGet('obj_id'));
         //            var_dump($token);
         $res = new SaeTClientV2($config['weibo']['app_id'], $config['weibo']['app_key'], null, null, null, $token);
         Yaf_Registry::set($key, $res);
     }
     return $res;
 }
Example #27
0
 public function _initSession(Yaf_Dispatcher $dispatcher)
 {
     Yaf_Session::getInstance()->start();
     header("Cache-control:private");
     header('content-type:text/html;charset=utf-8');
 }
Example #28
0
 /**
  * 检测并确认用户姓名
  * @param $username
  * @return string
  */
 public function updateUsername($username)
 {
     if ($this->exits(array('user_name' => $username))) {
         return '用户名重复';
     }
     $userinfo = $this->getUserInfo();
     $result = $this->update(array('user_name' => $username), array('user_id' => $userinfo['user_id']));
     if ($result == TRUE) {
         $userinfo['user_name'] = $username;
         Yaf_Session::getInstance()->userinfo = $userinfo;
         return TRUE;
     }
     return FALSE;
 }
Example #29
0
 /**
  * 从SESSION删除通知消息
  */
 public static function delNotice()
 {
     Yaf_Session::getInstance()->del('NOTICE');
 }
Example #30
0
 public function LogoutAction()
 {
     //unset($_SESSION['username']);
     Yaf_Session::getInstance()->del("admin_username");
     header('Location:/admin/');
 }