From ab9c5da4158011802d5a5ffa77f784cf20aa70fc Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 27 May 2014 07:59:37 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E5=91=98=E7=B1=BB?= =?UTF-8?q?=E5=92=8C=E6=9D=83=E9=99=90=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/Sookon/Authentication/AclAuthorize.php | 138 +++++++------- vendor/Sookon/Authentication/AclResource.php | 167 ++++++++--------- vendor/Wbb/Vhome/Member/Account/Account.php | 115 ++++++++++++ vendor/Wbb/Vhome/Member/Account/Config.php | 47 +++++ vendor/Wbb/Vhome/Member/Account/Login.php | 40 ++++ vendor/Wbb/Vhome/Member/Account/Register.php | 91 +++++++++ vendor/Wbb/Vhome/Member/Event/LoginEvent.php | 13 ++ vendor/Wbb/Vhome/Member/Event/MemberEvent.php | 12 ++ .../Wbb/Vhome/Member/Event/RegisterEvent.php | 13 ++ .../Wbb/Vhome/Member/Handle/LoginHandle.php | 102 +++++++++++ .../Wbb/Vhome/Member/Handle/MemberHandle.php | 76 ++++++++ .../Vhome/Member/Handle/RegisterHandle.php | 173 ++++++++++++++++++ .../Vhome/Member/Listener/MemberListener.php | 38 ++++ vendor/Wbb/Vhome/Post/Event/PostEvent.php | 12 ++ vendor/Wbb/Vhome/Post/Handle/PostHandle.php | 89 +++++++++ .../Wbb/Vhome/Post/Listener/PostListener.php | 34 ++++ 16 files changed, 1004 insertions(+), 156 deletions(-) create mode 100644 vendor/Wbb/Vhome/Member/Account/Account.php create mode 100644 vendor/Wbb/Vhome/Member/Account/Config.php create mode 100644 vendor/Wbb/Vhome/Member/Account/Login.php create mode 100644 vendor/Wbb/Vhome/Member/Account/Register.php create mode 100644 vendor/Wbb/Vhome/Member/Event/LoginEvent.php create mode 100644 vendor/Wbb/Vhome/Member/Event/MemberEvent.php create mode 100644 vendor/Wbb/Vhome/Member/Event/RegisterEvent.php create mode 100644 vendor/Wbb/Vhome/Member/Handle/LoginHandle.php create mode 100644 vendor/Wbb/Vhome/Member/Handle/MemberHandle.php create mode 100644 vendor/Wbb/Vhome/Member/Handle/RegisterHandle.php create mode 100644 vendor/Wbb/Vhome/Member/Listener/MemberListener.php create mode 100644 vendor/Wbb/Vhome/Post/Event/PostEvent.php create mode 100644 vendor/Wbb/Vhome/Post/Handle/PostHandle.php create mode 100644 vendor/Wbb/Vhome/Post/Listener/PostListener.php diff --git a/vendor/Sookon/Authentication/AclAuthorize.php b/vendor/Sookon/Authentication/AclAuthorize.php index d2aabe00..5758d919 100644 --- a/vendor/Sookon/Authentication/AclAuthorize.php +++ b/vendor/Sookon/Authentication/AclAuthorize.php @@ -1,70 +1,70 @@ -acl = $acl; - - $this->loadAuthorize(); - - $acl = $this->acl; - } - - public function loadAuthorize() - { - $this->role = new \stdClass(); - $this->role->guest = 'guest'; - - $this->role->staff = 'member'; - - $this->role->admin = 'administrator'; - - $roleGuest = new Role($this->role->guest); - - $this->acl->addRole($roleGuest); - $this->acl->addRole(new Role($this->role->staff), $roleGuest); - $this->acl->addRole(new Role($this->role->admin)); - - $this->authorizeGuest(); - $this->authorizestaff(); - $this->authorizeAdministrator(); - } - - public function authorizeGuest() - { - $this->acl->deny($this->role->guest); - - $this->acl->allow($this->role->guest,'Application\Controller\Account',array('login','register','logout','forgotpassword','getpassword','captcha')); - $this->acl->allow($this->role->guest,'Application\Controller\Service',array('upload','thumb')); - - $this->acl->allow($this->role->guest,'Application\Controller\Index'); - $this->acl->allow($this->role->guest,'Application\Controller\Search'); - $this->acl->allow($this->role->guest,'Article\Controller\Article',array('index','view')); - $this->acl->allow($this->role->guest,'Article\Controller\Category',array('index','list')); - - $this->acl->allow($this->role->guest,'Metadata\Controller\Index'); - } - - public function authorizestaff() - { - $this->acl->allow($this->role->staff,'Application\Controller\Index',array('index')); - $this->acl->allow($this->role->staff,'Application\Controller\Account',array('index')); - $this->acl->allow($this->role->staff,'Application\Controller\Service',array('upload','delatt','thumb')); - - } - - public function authorizeAdministrator() - { - $this->acl->allow($this->role->admin); - } +acl = $acl; + + $this->loadAuthorize(); + + $acl = $this->acl; + } + + public function loadAuthorize() + { + $this->role = new \stdClass(); + $this->role->guest = 'guest'; + + $this->role->staff = 'member'; + + $this->role->admin = 'administrator'; + + $roleGuest = new Role($this->role->guest); + + $this->acl->addRole($roleGuest); + $this->acl->addRole(new Role($this->role->staff), $roleGuest); + $this->acl->addRole(new Role($this->role->admin)); + + $this->authorizeGuest(); + $this->authorizestaff(); + $this->authorizeAdministrator(); + } + + public function authorizeGuest() + { + $this->acl->deny($this->role->guest); + + $this->acl->allow($this->role->guest,'Member\Controller\Account',array('login','register','logout','forgotpassword','getpassword','captcha')); + $this->acl->allow($this->role->guest,'Application\Controller\Service',array('upload','thumb')); + + $this->acl->allow($this->role->guest,'Application\Controller\Index'); + $this->acl->allow($this->role->guest,'Application\Controller\Search'); + $this->acl->allow($this->role->guest,'Application\Controller\Post'); + + } + + public function authorizestaff() + { + $this->acl->allow($this->role->staff,'Application\Controller\Index',array('index')); + + $this->acl->allow($this->role->staff,'Application\Controller\Service',array('upload','delatt','thumb')); + + $this->acl->allow($this->role->staff,'Member\Controller\Index'); + $this->acl->allow($this->role->staff,'Member\Controller\Account',array('index')); + } + + public function authorizeAdministrator() + { + $this->acl->allow($this->role->admin); + } } \ No newline at end of file diff --git a/vendor/Sookon/Authentication/AclResource.php b/vendor/Sookon/Authentication/AclResource.php index 572ba0f4..5b600dfc 100644 --- a/vendor/Sookon/Authentication/AclResource.php +++ b/vendor/Sookon/Authentication/AclResource.php @@ -1,88 +1,81 @@ - array( - 'login', - 'logout', - 'register', - 'forgotpassword', - 'getpassword', - 'captcha', - 'index' - ), - - //service - 'Application\Controller\Service' => array( - 'upload', - 'delatt', - 'thumb', - 'bigthumb' - ), - - 'Article\Controller\Article' => array( - 'index', - 'view' - ), - - 'Article\Controller\Category' => array( - 'index', - 'list' - ), - - 'Metadata\Controller\Index', - ); - - function __construct(Acl &$acl) - { - $this->acl = $acl; - - $this->loadResource(); - - $acl = $this->acl; - } - - public function loadResource() - { - foreach($this->config as $index => $resource) - { - if(!is_array($resource)) - { - $this->acl->addResource(new Resource($resource)); - continue; - } - - $this->acl->addResource(new Resource($index)); - - foreach($resource as $action) - { - if($this->acl->hasResource($action)) - { - continue; - } - - $this->acl->addResource(new Resource($action),$index); - } - } - } - + array( + 'index', + 'create', + ), + + //service + 'Application\Controller\Service' => array( + 'upload', + 'delatt', + 'thumb', + 'bigthumb' + ), + + 'Member\Controller\Index', + //account + 'Member\Controller\Account' => array( + 'login', + 'logout', + 'register', + 'forgotpassword', + 'getpassword', + 'captcha', + 'index' + ), + ); + + function __construct(Acl &$acl) + { + $this->acl = $acl; + + $this->loadResource(); + + $acl = $this->acl; + } + + public function loadResource() + { + foreach($this->config as $index => $resource) + { + if(!is_array($resource)) + { + $this->acl->addResource(new Resource($resource)); + continue; + } + + $this->acl->addResource(new Resource($index)); + + foreach($resource as $action) + { + if($this->acl->hasResource($action)) + { + continue; + } + + $this->acl->addResource(new Resource($action),$index); + } + } + } + } \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Account/Account.php b/vendor/Wbb/Vhome/Member/Account/Account.php new file mode 100644 index 00000000..657036cb --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Account/Account.php @@ -0,0 +1,115 @@ +db = new Db(); + $this->config = GlobalConfig::get(); + $this->conf = Config::get(); + + $Listener = new Listener(); + $this->getEventManager()->attachAggregate($Listener); + } + + public function setEventManager(EventManagerInterface $events) + { + $events->setIdentifiers(array( + __CLASS__, + get_called_class(), + )); + $this->events = $events; + return $this; + } + + public function getEventManager() + { + if (NULL === $this->events) { + $this->setEventManager(new EventManager()); + } + return $this->events; + } + + //获取账号信息,数组 + public function getAccountInfo($id = 0) + { + if($id == 0) + { + $id = view::User('id'); + } + $sql = "SELECT * FROM {$this->conf->table->member} WHERE id=$id"; + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + //storeLogin + public function storeLogin($data,$md5 = true) + { + $auth = new AuthenticationService(); + $auth->setStorage(new SessionStorage($this->config->session_namespace)); + + new Zend_Db($dbAdapter); + + $authAdapter = new \Zend\Authentication\Adapter\DbTable( + $dbAdapter, + $this->conf->table->member, + $this->conf->field->uname, + $this->conf->field->pwd + ); + + if($md5 === true) + { + $password = md5($data[$this->conf->field->pwd]); + }else{ + $password = $data[$this->conf->field->pwd]; + } + + $authAdapter + ->setIdentity($data[$this->conf->field->uname]) + ->setCredential($password) + ; + + $result = $authAdapter->authenticate(); + + $user = $authAdapter->getResultRowObject(null,array($this->conf->field->pwd)); + + if(!$result->isValid()) + { + return array("error"=>"用户信息验证失败"); + } + + $email = $user->email; + $results = $this->getEventManager()->trigger('login.success.createAvatar', $this, compact('email')); + $user->avatar = $results->last(); + $auth->getStorage()->write($user); + + $id = $user->id; + $results = $this->getEventManager()->trigger('login.success.updateStatus', $this, compact('id')); + + return array('success'=>1); + } + + public function cookieLogin($data) + { + return $this->storeLogin($data,false); + } + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Account/Config.php b/vendor/Wbb/Vhome/Member/Account/Config.php new file mode 100644 index 00000000..d8527d7e --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Account/Config.php @@ -0,0 +1,47 @@ +ck = 'DT0xe28SqIcmy334asEfUf'; + + $conf->table = new \stdClass(); + $conf->field = new \stdClass(); + $conf->role = new \stdClass(); + $conf->form = new \stdClass(); + + $conf->table->member = "users"; + + $conf->field->uname = "username"; + $conf->field->pwd = "password"; + $conf->field->email = "email"; + $conf->field->lastlogin = "ts_last_login"; + $conf->field->lastip = "last_login_ip"; + $conf->field->gravatar = "email"; + $conf->field->realname = "realname"; + + $conf->role->member = "member"; + $conf->role->admin = "admin"; + $conf->role->guest = "guest"; + + $conf->form->uname = "username"; + $conf->form->pwd = "password"; + $conf->form->c_pwd = "confirm_password"; + $conf->form->email = "email"; + $conf->form->realname = "realname"; + + return $conf; + } + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Account/Login.php b/vendor/Wbb/Vhome/Member/Account/Login.php new file mode 100644 index 00000000..ea13fd0c --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Account/Login.php @@ -0,0 +1,40 @@ +getEventManager()->trigger('login.checkParam', $this, compact('data')); + $cache_data = $results->last(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $state = $this->storeLogin($data); + + if(isset($state['success'])) + { + $mb = new Member(); + $mb->putcookie($data[$this->conf->field->uname],md5($data[$this->conf->field->pwd])); + } + + return $state; + }//login + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Account/Register.php b/vendor/Wbb/Vhome/Member/Account/Register.php new file mode 100644 index 00000000..4538a712 --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Account/Register.php @@ -0,0 +1,91 @@ +getEventManager()->trigger('register.checkParam', $this, $params); + $cache_data = $results->last(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $results = $this->getEventManager()->trigger('register.checkUser', $this, $params); + $cache_data = $results->last(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $loginData = array( + $this->conf->field->uname => $data['username'], + $this->conf->field->pwd => $data['password'] + ); + + $data['password'] = md5($data['password']); + $data['usertype'] = $this->config->member->default_role; + unset($data['confirm_password']); + + $dbh = new dbh(); + + $id = $dbh->insert($this->conf->table->member,$data,true); + + if(!empty($id) && is_numeric($id)) + { + $this->storeLogin($loginData); + if(isset($state['success'])) + { + $mb = new Member(); + $mb->putcookie($data[$this->conf->field->uname],$data[$this->FieldPasword]); + } + $params = compact('data','id'); + $results = $this->getEventManager()->trigger('register.success', $this, $params); + return array("success" => 1); + }else{ + if($id === false) + { + return array('error'=>'服务器开小差了,请稍后再试'); + }else{ + return array('error'=>'服务器处理中遇到错误,请联系管理员'); + } + } + + }//register + + //注册信息参数 + public function getParam(\Zend_Controller_Request_Abstract $request) + { + $data = array( + $this->conf->field->uname => $request->getParam('username'), + $this->conf->field->pwd => $request->getParam('password'), + $this->conf->form->c_pwd => $request->getParam('confirm_password'), + $this->conf->form->email => $request->getParam('email'), + $this->conf->form->realname =>$request->getParam('realname') + ); + return $data; + } + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Event/LoginEvent.php b/vendor/Wbb/Vhome/Member/Event/LoginEvent.php new file mode 100644 index 00000000..d7cd3760 --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Event/LoginEvent.php @@ -0,0 +1,13 @@ +db = new Db(); + $this->conf = Config::get(); + } + + public function checkParam(EventInterface $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data[$this->conf->field->uname])) + { + return array('error'=>"请输入用户名",'place'=>'username'); + } + + if(!empty($data[$this->conf->field->uname])) + { + if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/",$data[$this->conf->field->uname])) + { + return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在2到25个字符之间",'place'=>'username'); + } + } + + if(empty($data[$this->conf->field->pwd])) + { + return array('error'=>"请输入密码",'place'=>'password'); + } + + $sql = "SELECT id,{$this->conf->field->pwd} FROM {$this->conf->table->member} WHERE {$this->conf->field->uname}=?"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($data[$this->conf->field->uname])); + $row = $sth->fetch(); + + if(isset($row['id']) && !empty($row['id'])) + { + if(strlen($row[$this->conf->field->pwd]) !== 32) + { + return array('error'=>"您的密码或因安全猿因或其他问题已经被重置,请先重置密码再登陆",'place'=>'password'); + } + if($row[$this->conf->field->pwd] !== md5($data[$this->conf->field->pwd])) + { + return array('error'=>"密码错误",'place'=>'password'); + } + return true; + }else{ + return array('error'=>"用户不存在",'place'=>'username'); + } + + }//checkParam + + public function updateStatus(EventInterface $e){ + + $id = (int)$e->getParam('id'); + + if(!is_numeric($id)) + { + return false; + } + + $update = array( + $this->conf->field->lastlogin => date("Y-m-d H:i:s"), + //$this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"] + ); + + $dbh = new dbh(); + @$statusUpdate = $dbh->update($this->conf->table->member,$update," id=$id "); + + return true; + }//loginSuccess + + public function createAvatar(EventInterface $e){ + + $email = $e->getParam('email'); + $avatar = new Gravatar(); + return $avatar->Get($email); + + }//loginSuccess + + + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Handle/MemberHandle.php b/vendor/Wbb/Vhome/Member/Handle/MemberHandle.php new file mode 100644 index 00000000..de8a1113 --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Handle/MemberHandle.php @@ -0,0 +1,76 @@ +db = new Pdo(); + + $this->config = Config::get(); + } + + //检查字段 + public function checkParam(EventInterface $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data["username"])) + { + return "用户名"; + } + + return true; + }//checkParam + + //处理字段 + public function processData(EventInterface $e) + { + $data = $e->getParam('data'); + + if(empty($data['uuid'])) + { + unset($data['uuid']); + } + + return $data; + } + + //注册成功 + public function recordPosted(EventInterface $e) + { + $data = $e->getParam('data'); + $id = $e->getParam('id'); + + //view::Dump(array($data,$id,$params)); + + //return $data; + } + + //用户修改 + public function recordChanged(EventInterface $e) + { + $data = $e->getParam('data'); + $id = $e->getParam('id'); + + //return $data; + } + + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Handle/RegisterHandle.php b/vendor/Wbb/Vhome/Member/Handle/RegisterHandle.php new file mode 100644 index 00000000..9d64974f --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Handle/RegisterHandle.php @@ -0,0 +1,173 @@ +db = new Db(); + $this->conf = Config::get(); + $this->config = GlobalConfig::get('email'); + } + + public function checkParam(EventInterface $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data[$this->conf->field->uname])) + { + return array('error'=>"请输入用户名",'place'=> $this->conf->form->uname ); + } + + if(!empty($data[$this->conf->field->uname])) + { + if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data[$this->conf->field->uname])) + { + return array( + 'error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到16个字符之间", + 'place'=>$this->conf->form->uname + ); + } + } + + if(empty($data[$this->conf->field->pwd])) + { + return array('error'=>"请输入密码",'place'=>$this->conf->form->pwd); + } + + if(strlen($data[$this->conf->field->pwd]) < 6) + { + return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>$this->conf->form->pwd); + } + + if(strlen($data[$this->conf->field->pwd]) > 14) + { + return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>$this->conf->form->pwd); + } + + if(empty($data[$this->conf->form->c_pwd])) + { + return array('error'=>"请再次输入密码已确认输入正确",'place'=>$this->conf->form->c_pwd); + } + + if(md5($data[$this->conf->field->pwd]) != md5($data[$this->conf->form->c_pwd])) + { + return array('error'=>"两次输入的密码不同,请重新输入",'place'=>$this->conf->form->c_pwd); + } + + if(empty($data[$this->conf->field->email])) + { + return array('error'=>"请输入电子邮箱,作为找回密码和接受通知的联系方式",'place' => $this->conf->form->email); + } + + if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data[$this->conf->field->email])) + { + return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place' => $this->conf->form->email); + } + + if(empty($data[$this->conf->field->realname])) + { + return array('error'=>"起个响亮的名号吧",'place'=> $this->conf->form->realname); + } + + if(mb_strlen($data[$this->conf->field->realname],"UTF-8")>15 ) + { + return array('error'=>":-(这名号也太长了吧,不要超过15个字哦",'place'=> $this->conf->form->realname); + } + + return true; + }//checkParam + + public function checkUser(EventInterface $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "用户信息验证失败,请重新尝试"; + } + + $sql = "SELECT + id,{$this->conf->field->uname},{$this->conf->field->email} + FROM {$this->conf->table->member} + WHERE {$this->conf->field->uname}='".$data[$this->conf->field->uname]."' + OR {$this->conf->field->email}='".$data[$this->conf->field->email]."'"; + + $rs = $this->db->query($sql); + + $row = $rs->fetch(); + + if(isset($row['id']) && !empty($row['id'])) + { + if($row[$this->conf->field->uname] == $data[$this->conf->field->uname]) + { + return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>$this->conf->form->uname); + } + + if($row[$this->conf->field->email] == $data[$this->conf->field->email]) + { + return array('error'=>'您的邮箱已经注册过账号,请换一个邮箱','place'=>$this->conf->form->email); + } + + return array('error'=>'您的用户名或邮箱已经使用过,注册马甲请换一个用户名'); + } + + return true; + }//checkUser + + public function registerSuccess(EventInterface $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return false; + } + + $id = $e->getParam('id'); + + if(!is_numeric($id)) + { + return false; + } + + $mail_template = $this->config->template->register; + $mail_data = array( + 'name'=>$data[$this->conf->field->realname], + 'content' => '' + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($data[$this->conf->field->email],$data[$this->conf->field->realname]); + $mail->send(); + + return true; + }//registerSuccess + + //邮件内容 + public function getMailContent() + { + $content = ""; + + return $content; + }//getMailContent(); + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Member/Listener/MemberListener.php b/vendor/Wbb/Vhome/Member/Listener/MemberListener.php new file mode 100644 index 00000000..8bd97cdf --- /dev/null +++ b/vendor/Wbb/Vhome/Member/Listener/MemberListener.php @@ -0,0 +1,38 @@ +listeners[] = $events->attach('register.checkParam', array($_Events, 'checkParam'), 100); + $this->listeners[] = $events->attach('register.checkUser', array($_Events, 'checkUser'), 80); + $this->listeners[] = $events->attach('register.success', array($_Events, 'registerSuccess'), 50); + + $_Events = new Handle\LoginHandle(); + $this->listeners[] = $events->attach('login.checkParam', array($_Events, 'checkParam'), 100); + $this->listeners[] = $events->attach('login.success.updateStatus', array($_Events, 'updateStatus'), 50); + $this->listeners[] = $events->attach('login.success.createAvatar', array($_Events, 'createAvatar'), 50); + } + + public function detach(EventManagerInterface $events) + { + foreach ($this->listeners as $index => $listener) { + if ($events->detach($listener)) { + unset($this->listeners[$index]); + } + } + } + +} diff --git a/vendor/Wbb/Vhome/Post/Event/PostEvent.php b/vendor/Wbb/Vhome/Post/Event/PostEvent.php new file mode 100644 index 00000000..7cadde48 --- /dev/null +++ b/vendor/Wbb/Vhome/Post/Event/PostEvent.php @@ -0,0 +1,12 @@ +db = new Pdo(); + + $this->config = Config::get(); + } + + //检查字段 + public function checkParam(EventInterface $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data["title"])) + { + return "请输入标题"; + } + + if(empty($data["body"])) + { + return "请输入内容"; + } + + return true; + }//checkParam + + //处理字段 + public function processData(EventInterface $e) + { + $data = $e->getParam('data'); + + if(empty($data['uuid'])) + { + unset($data['uuid']); + } + + if(empty($data['ts_published'])) + { + $data['ts_published'] = date("Y-m-d H:i:s"); + } + + unset($data['tags']); + unset($data['category']); + + return $data; + } + + //发布 + public function recordPosted(EventInterface $e) + { + $data = $e->getParam('data'); + $id = $e->getParam('id'); + + //view::Dump(array($data,$id,$params)); + + //return $data; + } + + //更改 + public function recordChanged(EventInterface $e) + { + $data = $e->getParam('data'); + $id = $e->getParam('id'); + + //return $data; + } + + +} \ No newline at end of file diff --git a/vendor/Wbb/Vhome/Post/Listener/PostListener.php b/vendor/Wbb/Vhome/Post/Listener/PostListener.php new file mode 100644 index 00000000..2e29c3dc --- /dev/null +++ b/vendor/Wbb/Vhome/Post/Listener/PostListener.php @@ -0,0 +1,34 @@ +listeners[] = $events->attach('submit.checkParam', array($_Events, 'checkParam'), 100); + $this->listeners[] = $events->attach('submit.processData', array($_Events, 'processData'), 100); + $this->listeners[] = $events->attach('submit.recordPosted', array($_Events, 'recordPosted'), 100); + $this->listeners[] = $events->attach('submit.recordChanged', array($_Events, 'recordChanged'), 100); + } + + public function detach(EventManagerInterface $events) + { + foreach ($this->listeners as $index => $listener) { + if ($events->detach($listener)) { + unset($this->listeners[$index]); + } + } + } + +}