diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index 5e4684a6..9f3d6c21 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -1,5 +1,5 @@ -
没有找到对应的元数据。
- \ No newline at end of file + \ No newline at end of file diff --git a/application/module/Helpers/Captcha.php b/application/module/Helpers/Captcha.php new file mode 100644 index 00000000..43a835b3 --- /dev/null +++ b/application/module/Helpers/Captcha.php @@ -0,0 +1,58 @@ +loadCaptcha(); + } + + public function loadCaptcha() + { + $this->captcha = new \Zend_Captcha_Image(array( + 'captcha' => 'Image', + 'wordLen' => 4, + 'fontsize'=>16, + 'width' => 100, + 'height' => 38, + 'dotNoiseLevel'=>2, + 'lineNoiseLevel'=>1, + 'timeout' => 300, + 'font' => '../data/fonts/ggbi.ttf', + 'imgDir' => $this->imgDir, + 'imgUrl' => '/images/captcha', + )); + } + + public function setCaptcha(){ + if(!is_dir($this->imgDir)) + { + mkdir($this->imgDir); + } + + $this->captcha->generate(); + $_SESSION[$this->sessionName] = $this->captcha->getWord(); + $url = $this->captcha->getImgUrl() + .$this->captcha->getId() + .$this->captcha->getSuffix(); + + return $url; + } + + public function isValid($captchaword) + { + if($captchaword == $_SESSION[$this->sessionName]) + { + return true; + }else{ + return false; + } + } + +} \ No newline at end of file diff --git a/application/module/Mail/Mail.php b/application/module/Mail/Mail.php index 8736bffb..06288646 100644 --- a/application/module/Mail/Mail.php +++ b/application/module/Mail/Mail.php @@ -121,7 +121,12 @@ class Mail $this->subject = $subject; $this->body = $body; - $this->type = $row['type']; + if(isset($row['type'])) + { + $this->type = $row['type']; + }else{ + $this->type = "text"; + } }//加载模板 diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php index 717a34d6..e5679992 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -1,372 +1,377 @@ -db = \Zend_Registry::get('db'); - }else{ - $this->db = $db; - } - - $this->config = \Zend_Registry::get('config'); - - if($initializingListener === TRUE) - { - $this->loadListener(); - } - } - - public function loadListener() - { - //主要操作,账号注册,登录,设置session等 - $AccountListener = new AccountListener(); - @$this->events()->attachAggregate($AccountListener); - - //账户编辑 - $EditListener = new EditListener(); - @$this->events()->attachAggregate($EditListener); - - //账户安全性(找回密码) - $PwdListener = new PwdListener(); - @$this->events()->attachAggregate($PwdListener); - } - - public function events(\Zend_EventManager_EventCollection $events = NULL) - { - if ($events !== NULL) { - $this->events = $events; - } elseif ($this->events === NULL) { - $this->events = new \Zend_EventManager_EventManager(__CLASS__); - } - return $this->events; - } - - //获取账号信息,数组 - public function getAccountInfo($id = 0) - { - if($id == 0) - { - $id = view::User('id'); - } - $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; - $rs = $this->db->query($sql); - return $rs->fetch(); - } - - //注册 - public function register($data) - { - $params = compact('data'); - $results = $this->events()->trigger('register.checkParam', $this, $params); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $results = $this->events()->trigger('register.checkUser', $this, $params); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $loginData = array( - 'username'=>$data['username'], - 'password'=>$data['password'] - ); - - $data['password'] = md5($data['password']); - $data['usertype'] = "member"; - unset($data['confirm_password']); - - $dbh = new dbh(); - - $id = $dbh->insert($this->memberTable,$data,true); - - if(!empty($id) && is_numeric($id)) - { - $this->storeLogin($loginData); - $mb = new Member(); - $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) - $params = compact('data','id'); - $results = $this->events()->trigger('register.success', $this, $params); - return array("success" => 1); - }else{ - if($id === false) - { - return array('error'=>'服务器开小差了,请稍后再试'); - }else{ - return array('error'=>'服务器处理中遇到错误,请联系管理员'); - } - } - - }//register - - //登陆 - public function login($data) - { - $results = $this->events()->trigger('login.checkParam', $this, compact('data')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $state = $this->storeLogin($data); - - $mb = new Member(); - $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); - - return $state; - }//login - - //storeLogin - //将登录信息保存在session和cookie中 - public function storeLogin($data,$md5verify = true) - { - $auth = \Zend_Auth::getInstance(); - $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); - $authAdapter->setTableName($this->memberTable) - ->setIdentityColumn($this->FieldUsername) - ->setCredentialColumn($this->FieldPasword); - - if($data[$this->FieldPasword] == 0) - { - $password = "0"; - }else{ - if($md5verify === false) - { - $password = $data[$this->FieldPasword]; - }else{ - $password = md5($data[$this->FieldPasword]); - } - } - - $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); - - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - - $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); - $email = $user->email; - $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); - $user->avatar = $results->bottom(); - $auth->getStorage()->write($user); - - $id = $user->id; - @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); - - return array('success'=>1); - } - return array('error'=>'处理中发现错误,请重试'); - } - - //注册信息参数 - public function getParam(\Zend_Controller_Request_Abstract $request) - { - $data = array( - 'username'=>$request->getParam('username'), - 'password'=>$request->getParam('password'), - 'confirm_password'=>$request->getParam('confirm_password'), - 'email'=>$request->getParam('email'), - 'realname'=>$request->getParam('realname') - ); - return $data; - } - - //获取用户账户修改参数 - public function getEditParam(\Zend_Controller_Request_Abstract $request) - { - $type = $request->getParam('type'); - - if($type == "general") - { - $data = array( - 'realname'=>$request->getParam('realname'), - 'signature'=>$request->getParam('signature'), - 'description'=>$request->getParam('description') - ); - } - - if($type == "password") - { - $data = array( - 'password' => $request->getParam('password'), - 'password_new'=>$request->getParam('password_new'), - 'password_confirm'=>$request->getParam('password_confirm') - ); - } - return $data; - } - - //编辑 - public function edit($data,$type) - { - $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - if($type == "general") - { - $data['signature'] = htmlspecialchars($data['signature']); - $data['description'] = htmlspecialchars($data['description']); - }else if($type == "password") - { - $data['password'] = md5($data['password_new']); - unset($data['password_new']); - unset($data['password_confirm']); - }else{ - return "参数错误"; - } - - $dbh = new dbh(); - $uid = view::User('id'); - if($dbh->update($this->memberTable,$data," id=$uid") === true) - { - return true; - }else{ - return false; - } - } - - //找回密码 - public function getMyPassword($email) - { - $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(!isset($row['username']) || empty($row['username'])) - { - return array('error'=>"此邮箱并未注册",'place'=>'email'); - } - - $salt = md5($email.'---'.$row['username']); - - $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; - $state = $this->db->exec($sql); - - if($state<1) - { - return array('error'=>"处理中出现错误,请重试",'place'=>'email'); - } - - $mail_template = "forgotpassword"; - $mail_data = array( - 'name'=>$row['realname'], - 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($email,$row['realname']); - $mail->send(); - - return array("success"=>1); - } - - //重置密码 - public function resetPassword($data) - { - $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($data['salt'])); - $row = $sth->fetch(); - - if(!isset($row['username']) || empty($row['username'])) - { - return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); - } - - if($row['username'] !== $data['username']) - { - return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); - } - - $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; - $this->db->exec($sql); - - $mail_template = "getpassworded"; - $mail_data = array( - 'name'=>$row['realname'], - ); - $mail = new Mail(); - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($row['email'],$row['realname']); - $mail->send(); - - return true; - - } - +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + if($initializingListener === TRUE) + { + $this->loadListener(); + } + } + + public function loadListener() + { + //主要操作,账号注册,登录,设置session等 + $AccountListener = new AccountListener(); + @$this->events()->attachAggregate($AccountListener); + + //账户编辑 + $EditListener = new EditListener(); + @$this->events()->attachAggregate($EditListener); + + //账户安全性(找回密码) + $PwdListener = new PwdListener(); + @$this->events()->attachAggregate($PwdListener); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //获取账号信息,数组 + public function getAccountInfo($id = 0) + { + if($id == 0) + { + $id = view::User('id'); + } + $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + //注册 + public function register($data) + { + $params = compact('data'); + $results = $this->events()->trigger('register.checkParam', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $results = $this->events()->trigger('register.checkUser', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $loginData = array( + 'username'=>$data['username'], + 'password'=>$data['password'] + ); + + $data['password'] = md5($data['password']); + $data['usertype'] = "member"; + unset($data['confirm_password']); + + $dbh = new dbh(); + + $id = $dbh->insert($this->memberTable,$data,true); + + if(!empty($id) && is_numeric($id)) + { + $this->storeLogin($loginData); + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) + $params = compact('data','id'); + $results = $this->events()->trigger('register.success', $this, $params); + return array("success" => 1); + }else{ + if($id === false) + { + return array('error'=>'服务器开小差了,请稍后再试'); + }else{ + return array('error'=>'服务器处理中遇到错误,请联系管理员'); + } + } + + }//register + + //登陆 + public function login($data) + { + $results = $this->events()->trigger('login.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $state = $this->storeLogin($data); + + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); + + return $state; + }//login + + //storeLogin + //将登录信息保存在session和cookie中 + public function storeLogin($data,$md5verify = true) + { + $auth = \Zend_Auth::getInstance(); + $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); + $authAdapter->setTableName($this->memberTable) + ->setIdentityColumn($this->FieldUsername) + ->setCredentialColumn($this->FieldPasword); + + if($data[$this->FieldPasword] === 0) + { + $password = "0"; + }else{ + if($md5verify == false) + { + $password = $data[$this->FieldPasword]; + }else{ + $password = md5($data[$this->FieldPasword]); + } + } + + $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); + $result = $auth->authenticate($authAdapter); + + if ($result->isValid()) { + + $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); + $email = $user->email; + $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); + $user->avatar = $results->bottom(); + $auth->getStorage()->write($user); + + $id = $user->id; + @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); + + return array('success'=>1); + }else{ + return array("error"=>"用户信息验证失败,请重新登录"); + } + return array('error'=>'处理中发现错误,请重试'); + } + + //注册信息参数 + public function getParam(\Zend_Controller_Request_Abstract $request) + { + $data = array( + 'username'=>$request->getParam('username'), + 'password'=>$request->getParam('password'), + 'confirm_password'=>$request->getParam('confirm_password'), + 'email'=>$request->getParam('email'), + 'realname'=>$request->getParam('realname') + ); + return $data; + } + + //获取用户账户修改参数 + public function getEditParam(\Zend_Controller_Request_Abstract $request) + { + $type = $request->getParam('type'); + + if($type == "general") + { + $data = array( + 'realname'=>$request->getParam('realname'), + 'signature'=>$request->getParam('signature'), + 'description'=>$request->getParam('description') + ); + } + + if($type == "password") + { + $data = array( + 'password' => $request->getParam('password'), + 'password_new'=>$request->getParam('password_new'), + 'password_confirm'=>$request->getParam('password_confirm') + ); + } + return $data; + } + + //编辑 + public function edit($data,$type) + { + $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + if($type == "general") + { + $data['signature'] = htmlspecialchars($data['signature']); + $data['description'] = htmlspecialchars($data['description']); + }else if($type == "password") + { + $data['password'] = md5($data['password_new']); + unset($data['password_new']); + unset($data['password_confirm']); + }else{ + return "参数错误"; + } + + $dbh = new dbh(); + $uid = view::User('id'); + if($dbh->update($this->memberTable,$data," id=$uid") === true) + { + return true; + }else{ + return false; + } + } + + //找回密码 + public function getMyPassword($email) + { + $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"此邮箱并未注册",'place'=>'email'); + } + + $salt = md5($email.'--'.time().'--'.$row['username']); + + $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; + $state = $this->db->exec($sql); + + if($state<1) + { + return array('error'=>"处理中出现错误,请重试",'place'=>'email'); + } + + $mail_data = array( + 'name'=>$row['realname'], + 'link'=> view::getHostLink().'/account/fetchpwd/?salt='.$salt, + 'site' => $this->config->title->site + ); + + $mail = new Mail(); + + $mail->loadTemplate($this->getPwdEmailTemplate,$mail_data); + $mail->addTo($email,$row['realname']); + $mail->send(); + + return array("success"=>1); + } + + //重置密码 + public function resetPassword($data) + { + $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($data['salt'])); + $row = $sth->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + if($row['username'] !== $data['username']) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; + $this->db->exec($sql); + + $mail_data = array( + 'name' => $row['realname'], + 'site' => $this->config->title->site + ); + $mail = new Mail(); + $mail->loadTemplate($this->PwdChangedEmailTemplate,$mail_data); + $mail->addTo($row['email'],$row['realname']); + $mail->send(); + + return true; + + } + } \ No newline at end of file diff --git a/application/module/Users/Member.php b/application/module/Users/Member.php index 9854e6f1..fcb2bce2 100644 --- a/application/module/Users/Member.php +++ b/application/module/Users/Member.php @@ -1,5 +1,5 @@ "用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username'); + return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在3到25个字符之间",'place'=>'username'); } } @@ -106,6 +106,10 @@ class LoginOperate implements \Users\Event\LoginEvent }//loginSuccess - + //检查token表记录 + public function checkOAuthToken() + { + + } } \ No newline at end of file diff --git a/application/module/Users/Operation/PwdOperate.php b/application/module/Users/Operation/PwdOperate.php index ae87513f..27d54184 100644 --- a/application/module/Users/Operation/PwdOperate.php +++ b/application/module/Users/Operation/PwdOperate.php @@ -58,6 +58,11 @@ class PwdOperate implements \Users\Event\PwdEvent { $data = $e->getParam('data'); + if(empty($data['salt'])) + { + return array('error'=>"密钥不正确,请重新申请","place"=>'salt'); + } + if(empty($data['username'])) { return array('error'=>"请输入用户名",'place'=>'username'); @@ -70,12 +75,12 @@ class PwdOperate implements \Users\Event\PwdEvent if(strlen($data['password']) < 6) { - return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>'password'); + return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password'); } if(strlen($data['password']) > 14) { - return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>'password'); + return array('error'=>"密码太长,请不要超过14位",'place'=>'password'); } if(empty($data['confirm_password']))