public function addAction()
 {
     WAuthUtil::whetherLogout($this);
     $request = $this->getRequest();
     $form = new PageForm();
     //start
     if ($request->isPost() && isset($request->getPost()['pcontent'])) {
         $page = new Page();
         $user = new User();
         $form->bind($page);
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $auth = WAuthUtil::get_auth();
             $schID = $auth->schoolID;
             $userID = $auth->userID;
             $page->setSchID($schID);
             $user->setUserID($userID);
             $page->setUser($user);
             $pageID = $this->getservice()->getNewPageIDandMakedir();
             $page->setPageID($pageID);
             $file = $request->getFiles();
             $this->getservice()->savePage($page, $file);
             //                 Redirect to list of albums如果想要dump就不要转业
             return $this->redirect()->toRoute('page');
         } else {
             $messages = $form->getMessages();
             Debug::dump($messages);
         }
     }
     WAuthUtil::addUserpanelToLayout($this, '/add');
     return new ViewModel(array('pageform' => $form));
 }
 public function detailAction()
 {
     WAuthUtil::whetherLogout($this);
     //form
     $form = new FollowForm();
     $id = $this->params()->fromRoute('id');
     //增加点击次数
     $this->getFollowService()->updateClicktime($id);
     //查看是否评论,进行request处理
     $request = $this->getRequest();
     $whetherlogin = false;
     $userID = 0;
     $auth = WAuthUtil::get_auth();
     $star = null;
     if ($auth) {
         $whetherlogin = true;
         $userID = $auth->userID;
         $star = $this->getFollowService()->getStar($userID, $id);
     }
     if ($request->isPost() && isset($request->getPost()['fcontent'])) {
         if ($auth) {
             $followObject = new Follow();
             $user = new User();
             //!之所以要用一个对象,是因为follow对象里面没有userID这个属性,要在mapper里手工加上
             $form->bind($followObject);
             //通过Hydrator\ArraySerializable 通过model的exchangeArray
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $user->setUserID($userID);
                 $followObject->setUser($user);
                 $followObject->setPageID($id);
                 $this->getFollowService()->saveFollow($followObject);
                 //                 Redirect to list of albums如果想要dump就不要转业
                 //                 return $this->redirect()->toRoute('page');
             } else {
                 $messages = $form->getMessages();
                 Debug::dump($messages);
             }
         }
     }
     //读取page信息
     try {
         $page = $this->getPageService()->getPage($id);
     } catch (\InvalidArgumentException $ex) {
         return $this->redirect()->toRoute('blog');
     }
     //读取follow信息
     $follows = $this->getFollowService()->getFollows($id);
     //         //         Debug::dump($page);
     WAuthUtil::addUserpanelToLayout($this, '/detail/' . $id);
     return new ViewModel(array('userID' => $userID, 'page' => $page, 'follows' => $follows, 'form' => $form, 'whetherLogin' => $whetherlogin, 'simi' => $this->getFollowService()->getSimi($id), 'star' => $star));
 }
Exemple #3
0
 public function registerAction()
 {
     $form = new UserForm();
     $form->get('submit')->setValue('Register');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $user = new User();
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $user->exchangeArray($form->getData());
             $this->getUserList()->createUser($user);
         }
     }
     return array('form' => $form);
 }
 public function detailAction()
 {
     WAuthUtil::whetherLogout($this);
     //form
     $form = new RFollowForm();
     $id = $this->params()->fromRoute('id');
     //查看是否评论,进行request处理
     $request = $this->getRequest();
     if ($request->isPost() && isset($request->getPost()['rfcontent'])) {
         $followObject = new RFollow();
         $user = new User();
         //!之所以要用一个对象,是因为follow对象里面没有userID这个属性,要在mapper里手工加上
         $form->bind($followObject);
         //通过Hydrator\ArraySerializable 通过model的exchangeArray
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $auth = WAuthUtil::get_auth();
             $userID = $auth->userID;
             $user->setUserID($userID);
             $followObject->setUser($user);
             $followObject->setRecruitID($id);
             $this->getRFollowService()->saveRFollow($followObject);
             //                 Redirect to list of albums如果想要dump就不要转业
             //                 return $this->redirect()->toRoute('page');
         } else {
             $messages = $form->getMessages();
             Debug::dump($messages);
         }
     }
     //读取page信息
     try {
         $recruit = $this->getRecruitService()->getRecruit($id);
     } catch (\InvalidArgumentException $ex) {
         return $this->redirect()->toRoute('blog');
     }
     //读取follow信息
     $follows = $this->getRFollowService()->getRFollows($id);
     //         //         Debug::dump($page);
     WAuthUtil::addUserpanelToLayout($this, '/detail/' . $id);
     return new ViewModel(array('recruit' => $recruit, 'follows' => $follows, 'form' => $form));
 }
 public function auth(User $user)
 {
     $auth = new AuthenticationService();
     $authAdapter = new DbTable($this->dbAdapter);
     $authAdapter->setTableName('user')->setIdentityColumn('username')->setCredentialColumn('upassword');
     $authAdapter->setIdentity($user->getUsername())->setCredential($user->getUpassword());
     $result = $auth->authenticate($authAdapter);
     if ($result->isValid()) {
         $storage = $auth->getStorage();
         $storage->write($authAdapter->getResultRowObject(array('userID', 'username', 'schoolID')));
         return true;
     } else {
         print_r($result->getMessages());
     }
 }
 public function registerAction()
 {
     $form = new UserForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $user = new User();
         //             echo $_GET['user'];
         //             Debug::dump($request->getPost());
         $form->setInputFilter($user->getInputFilter());
         //就算没有输入id也可以通过检验。
         $form->bind($user);
         $form->setData($request->getPost());
         if ($form->isValid()) {
             //                 $user->setId(9);
             //                 Debug::dump($user);
             $this->getservice()->save($user);
             $this->getservice()->auth($user);
             //                 Debug::dump($form->getData());//经过bind,是一个$user对象,必须要实现exchangeArray ,get和set不必要
             //Debug::dump($user);//同上
             //                 Redirect to list of albums如果想要dump就不要转业
             return $this->redirect()->toRoute('add');
         } else {
             $messages = $form->getMessages();
             //                 Debug::dump($messages);
         }
     }
     //layout()用法
     //         $v1=new ViewModel(array(
     //             'identity'=>'wyj'
     //         ));
     //         //网页顶部显示登陆信息一般过程
     //         $v1->setTemplate('blog/user/userPanel');
     //         $layout=$this->layout();
     //         $layout->addChild($v1,'userPanel');
     $v = new ViewModel(array('userform' => $form));
     return $v;
 }