From c527de92073c5d9237244d3eb3fc7607445f8217 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 24 Jan 2014 02:33:21 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=89=E6=B1=9F=E6=BA=90?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=97=A8=E6=88=B7=E7=9A=84=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 1110 +++++++---------- .../default/views/scripts/account/edit.phtml | 8 +- .../views/scripts/account/fetchpwd.phtml | 79 +- .../default/views/scripts/account/login.phtml | 22 +- .../views/scripts/account/register.phtml | 107 +- application/module/Helpers/Captcha.php | 58 + application/module/Users/Account.php | 760 +++++------ application/module/Users/Member.php | 8 +- .../module/Users/Operation/LoginOperate.php | 10 +- .../module/Users/Operation/PwdOperate.php | 9 +- .../Users/Operation/RegisterOperate.php | 43 +- 11 files changed, 1102 insertions(+), 1112 deletions(-) create mode 100644 application/module/Helpers/Captcha.php diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 2ef1b970..10864530 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,634 +1,476 @@ -view->config = Zend_Registry::get('config'); - $this->_request->setParam('return', $this->_request->getServer('REQUEST_URI')); - $this->db = Zend_Registry::get('db'); - $this->view->messages = $this->messenger->getMessages(); - $this->view->theme = new Theme(); - } - - function indexAction() - { - $this->view->pageID = "account-index"; - - include_once("Users.php"); - $usr = new Users($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - include_once("Avatar.php"); - $avatar = new Avatar(); - $this->view->avatar = $avatar->Get($user->email,140); - - $this->view->info = $usr->getUserInfo($uid); - } - - function editAction() - { - $this->view->pageID = "account-edit"; - - include_once("Users.php"); - $usr = new Users($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - include_once("Avatar.php"); - $avatar = new Avatar(); - $this->view->avatar = $avatar->Get($user->email,140); - - $this->view->projectType = array( - "无" => '', - "国家973计划项目课题" => "国家973计划项目课题", - "国家863计划课题"=>"国家863计划课题", - "国家级科技支撑课题" => "国家级科技支撑课题", - "国家级科技重大专项" => "国家级科技重大专项", - "国家级国家重大工程" => "国家级国家重大工程", - "国家级国家自然科学基金" => "国家级国家自然科学基金", - "国际合作项目"=>"国际合作项目", - "省部级项目" => "省部级项目", - "其他项目工程" => "其他项目工程" - ); - - $submit = $this->_getParam('submit'); - - if(!empty($submit)) - { - $data = $this->AccountEditParamFilter(); - - if($this->db->update("users",$data,"id=$uid")) - { - $this->view->AlertType = "alert-success"; - $this->view->msg = "修改成功!"; - $this->view->jump_url = "/account/edit"; - return true; - }else{ - $this->view->AlertType = "alert-error"; - $this->view->error = "修改失败,请重试"; - $this->view->info = $data; - return true; - } - }else{ - $this->view->info = $usr->getUserInfo($uid); - } - } - - function AccountEditParamFilter(){ - $data = array(); - $data['realname'] = substr(trim($this->_getParam('realname')),0,40); - $data['unit'] = substr(trim($this->_getParam('unit')),0,100); - $data['address'] = substr(trim($this->_getParam('address')),0,100); - $data['phone'] = substr(trim($this->_getParam('phone')),0,15); - $data['postcode'] = substr(trim($this->_getParam('postcode')),0,15); - $data['project_type'] = substr(trim($this->_getParam('project_type')),0,100); - $data['project_id'] = substr(trim($this->_getParam('project_id')),0,40); - $data['project_title'] = substr(trim($this->_getParam('project_title')),0,100); - $data['project'] = substr(trim($this->_getParam('project')),0,600); - - foreach($data as $k=>$v) - { - $data[$k] = $this->StringFilter($v); - } - - return $data; - } - - function StringFilter($string){ - $string = preg_replace ('/<[^>]*>/', ' ', $string); - return $string; - } - - function secureAction() - { - $this->view->pageID = "account-secure"; - - include_once("Users.php"); - $usr = new Users($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - $opt = $this->_getParam('opt'); - $submit = $this->_getParam('submit'); - - if(empty($opt)) - { - $this->view->section = "password"; - if(!empty($submit)) - { - $data = $this->AccountSecureParamFilter(); - - $this->view->AlertType = "alert-error"; - if(strlen($data['password'])>18 || strlen($data['new_password'])>18) - { - $this->view->error = view::Error("密码过长"); - return true; - } - if(strlen($data['new_password'])<=6 || strlen($data['new_password_confrim'])<=6) - { - $this->view->error = view::Error("密码过短,请输入大于6位的密码"); - return true; - } - if(md5($data['new_password']) != md5($data['new_password_confrim'])) - { - $this->view->error = view::Error("两次输入的密码不相同"); - return true; - } - - $sql = "SELECT password FROM users WHERE id=$uid"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(md5($data['password']) != $row['password']) - { - $this->view->error = view::Error("原密码不正确"); - return true; - } - - $data['password'] = md5($data['new_password']); - - unset($data['new_password']); - unset($data['new_password_confrim']); - - if($this->db->update("users",$data,"id=$uid")) - { - view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); - return true; - }else{ - $this->view->error = view::Error("修改失败"); - return true; - } - }else{ - $this->view->info = $usr->getUserInfo($uid); - } - }//password - - if($opt == "email") - { - $this->view->section = "email"; - if(!empty($submit)) - { - $email = $this->_getParam('email'); - $password = $this->_getParam('password'); - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) - { - $this->view->error = view::Error("错误的邮箱格式"); - return true; - } - - $sql = "SELECT password FROM users WHERE id=$uid"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(md5($password) != $row['password']) - { - $this->view->error = view::Error("原密码错误"); - return true; - } - - $data['email'] = $email; - - if($this->db->update("users",$data,"id=$uid")) - { - view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); - return true; - }else{ - $this->view->error = view::Error("修改失败"); - return true; - } - }else{ - $this->view->info = $usr->getUserInfo($uid); - } - }//email - } - - function AccountSecureParamFilter(){ - $data = array(); - $data['password'] = trim($this->_getParam('password')); - $data['new_password'] = trim($this->_getParam('new_password')); - $data['new_password_confrim'] = trim($this->_getParam('new_password_confrim')); - foreach($data as $k=>$v) - { - $data[$k] = $this->StringFilter($v); - } - return $data; - } - - function init() - { - $this->messenger=$this->_helper->getHelper('FlashMessenger'); - } - - function postDispatch() - { - //$this->view->messages = $this->messenger->getMessages(); - } - - function registerAction() - { - $form = new RegisterForm(); - $this->view->form = $form; - - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - $ut = new UsersTable(); - $u = $ut->createRow(); - $u->username = $form->getValue('username'); - $u->password = $form->getValue('password'); - $u->email=$form->getValue('email'); - if ($form->getValue('realname')) $u->realname=$form->getValue('realname'); - if ($form->getValue('phone')) $u->phone=$form->getValue('phone'); - if ($form->getValue('address')) $u->address=$form->getValue('address'); - if ($form->getValue('unit')) $u->unit=$form->getValue('unit'); - if ($form->getValue('project')) $u->project=$form->getValue('project'); - if ($u->save()) { - - //注册邮件 - $mail_template = "member-register"; - $mail_data = array( - 'name'=>$formData['username'], - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($formData['email'],$formData['username']); - $mail->send(); - - //自动登录系统 - $this->login($formData['username'],$formData['password']); - $this->_redirect('/'); - } - } else { - $form->populate($formData); - } - } - } - - function loginAction() - { - - $success=false; - - $options = array( - 'module' => $this->_request->getModuleName(), - 'controller' => $this->_request->getControllerName(), - 'action' => $this->_request->getActionName(), - ); - - $auth = Zend_Auth::getInstance(); - if ($auth->hasIdentity()) - { - view::Post($this,"您已经登录,无需重复登录",-1); - return true; - } - - $tohref = $this->_request->getParam('href'); - - if(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")) - { - $this->view->href = $_SERVER['REQUEST_URI']; - } - - if($tohref == "/account/login") - { - $this->view->href = $tohref = "/"; - } - - if(!empty($tohref)) - { - $this->view->href = $tohref; - } - - $captcha = $this->loadCaptcha(); - - $submit = $this->_getParam("submit"); - if(!empty($submit)) - { - $username = trim($this->_request->getParam('username')); - $password = trim($this->_request->getParam('password')); - $captchaword = trim($this->_request->getParam('captcha')); - - if(empty($username)) - { - $this->setCaptcha($captcha); - $this->view->error = "请输入用户名"; - return true; - } - - if(empty($password)) - { - $this->setCaptcha($captcha); - $this->view->error = "请输入密码"; - return true; - } - - if(empty($captchaword)) - { - $this->setCaptcha($captcha); - $this->view->error = "请输入验证码"; - return true; - } - - if(!isset($_SESSION['captcha'])) - { - $_SESSION['captcha'] = md5(time()); - } - - if ($captchaword != $_SESSION['captcha']) { - $this->setCaptcha($captcha); - $this->view->error = "验证码错误"; - return true; - } - - if (!$this->login($username,$password)) - { - $this->setCaptcha($captcha); - $this->view->error = "用户名或密码错误"; - $this->view->userid = $username; - return true; - } - else - { - if(!empty($tohref)) - { - view::Post($this,"登录成功,正在跳转",$tohref); - return true; - } - } - }else{ - $this->setCaptcha($captcha); - } - - } - - function loadCaptcha() - { - $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' => 'vdimg/', - 'imgUrl' => '/vdimg', - )); - return $captcha; - } - - function setCaptcha(Zend_Captcha_Image $captcha,$ajax = false){ - $captcha->generate(); - $_SESSION['captcha'] = $captcha->getWord(); - $url = $captcha->getImgUrl() - .$captcha->getId() - .$captcha->getSuffix(); - if(!$ajax) - { - $this->view->captcha = $url; - }else{ - return $url; - } - } - - function captchaAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $captcha = $this->loadCaptcha(); - $url = $this->setCaptcha($captcha,true); - - echo $url; - return true; - } - - function logoutAction() - { - $auth = Zend_Auth::getInstance(); - $auth->clearIdentity(); - require_once 'member.php'; - $mb=new member(); - member::flushcookie(); - $this->_redirect('/'); - } - - private function default_login($u,$p) - { - $auth = Zend_Auth::getInstance(); - $db=Zend_Registry::get('db'); - - $authAdapter = new Zend_Auth_Adapter_DbTable($db); - $authAdapter->setTableName('users') - ->setIdentityColumn('username') - ->setCredentialColumn('password'); - $authAdapter->setIdentity($u)->setCredential(md5($p)); - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - // success: store database row to auth's storage - $data = $authAdapter->getResultRowObject(null,'password'); - - //头像 - include_once("Avatar.php"); - $avatar = new Avatar(); - $data->avatar = $avatar->Get($data->email,40); - - //组ID - include_once("Users.php"); - $usr = new Users($db); - $data->gid = $usr->getGroup($data->id); - - $auth->getStorage()->write($data); - $db->query("update users set ts_last_login=now() where username=?",array($u)); - - if ($this->_request->getParam('remember')) { - $sql="select usertype from users where username='$u'"; - $rs=$db->query($sql); - $row=$rs->fetch(); - //if($row['usertype']!='administrator') - { - require_once 'member.php'; - $mb = new member(); - $mb -> putcookie($u,md5($p)); - } - } - - return true; - }else - { - return false; - } - return false; - } - private function aspnet_login($p,$salt,$password) - { - $p1=implode("\x00",str_split($p))."\x00"; - $ball=base64_decode($salt).$p1; - return trim($password)==base64_encode(sha1($ball,true)); - } - // 首先判断是否存在salt - // 若有salt,则按照aspnet membership加密算法进行判断 - function login($u,$p) - { - $ut= new UsersTable(); - $db=$ut->getAdapter(); - $sql="select password,salt from users where username=?"; - $uq=$db->query($sql,array($u)); - if ($urow=$uq->fetchObject()) - { - if (empty($urow->salt)) - return $this->default_login($u,$p); - else { - //进行判断并进行转换到默认 - if ($this->aspnet_login($p,$urow->salt,$urow->password)) - { - $sql="update users set password=md5(?),salt='' where username=?"; - $db->query($sql,array($p,$u)); - return $this->default_login($u,$p); - } else - return false; - } - } else { - //没有对应的用户,登录失败 - return false; - } - } - function fetchpwdAction() - { - $ut= new UsersTable(); - $db=$ut->getAdapter(); - $form = new LostpwdForm(); - $key=$this->_request->getParam('key'); - $login=$this->_request->getParam('login'); - if (empty($key) && empty($login)) { - $this->view->form = $form; - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - $sql="select * from users where email=?"; - $uq=$db->query($sql,array($formData['email'])); - if ($urow=$uq->fetchObject()) - { - //email the url to user - $username=$urow->username; - $sql="update users set activation=? where email=?"; - $uid=uniqid(); - $db->query($sql,array($uid,$formData['email'])); - - //发邮件 - $mail_template = "users-changepassword"; - $mail_data = array( - 'name'=>$username, - 'url' => view::getHostLink()."/account/fetchpwd/".$username."/".$uid - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($formData['email'],$username); - $mail->send(); - - - $this->view->messages[]='请检查您的新邮件中的确认激活链接。'; - $this->view->form=false;//do not echo form - } else - $this->messenger->addMessage('对不起,没有找到对应的电子邮件地址。'); - } - } else - $this->view->messages[]='请输入您的电子邮件地址。您将通过电子邮件收到新密码。'; - } else { - $sql="select * from users where username=? and activation=?"; - $uq=$db->query($sql,array($login,$key)); - $tmp_pwd=uniqid(); - if ($urow=$uq->fetchObject()) - { - $sql="update users set salt='',activation='',password=md5('".$tmp_pwd."') where username=? and activation=?"; - $db->query($sql,array($login,$key)); - - //发邮件 - $mail_template = "users-changepassword"; - $mail_data = array( - 'name'=>$login, - 'tmp_pwd' => $tmp_pwd - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($urow->email,$login); - $mail->send(); - - $this->view->messages[]='请查收您新邮件中的新密码'; - $this->view->form=false;//do not echo form - - } - } - - } //找回密码 - - //OAuth2登录跳转页面 - public function oauth2loginAction() - { - $type = $this->_getParam('type'); - $client = new Client(); - $url = $client->makeRequestCodeUrl($type); - - view::Post($this,"为您转入科技网登录入口",$url); - } - - //oauth2登录回调地址 - public function callbackAction() - { - $type = $this->_getParam('type'); - $code = $this->_getParam('code'); - - $client = new Client($type); - - $client->initSource(); - $target = $client->getSource()->getTarget($type); - $this->view->target_name = $target['name']; - - $token = $client->requestToken($code); - - if(is_string($token)) - { - view::Post($this,$token,'/account/login'); - } - - $status = $client->storageTokenData($type,$token); - - if($status === true) - { - echo ""; - }else{ - echo $status; - } - } - -} - +view->config = Zend_Registry::get('config'); + $this->_request->setParam('return', $this->_request->getServer('REQUEST_URI')); + $this->db = Zend_Registry::get('db'); + $this->view->messages = $this->messenger->getMessages(); + $this->view->theme = new Theme(); + } + + function indexAction() + { + $this->view->pageID = "account-index"; + + include_once("Users.php"); + $usr = new Users($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + include_once("Avatar.php"); + $avatar = new Avatar(); + $this->view->avatar = $avatar->Get($user->email,140); + + $this->view->info = $usr->getUserInfo($uid); + } + + function editAction() + { + $this->view->pageID = "account-edit"; + + include_once("Users.php"); + $usr = new Users($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + include_once("Avatar.php"); + $avatar = new Avatar(); + $this->view->avatar = $avatar->Get($user->email,140); + + $this->view->projectType = array( + "无" => '', + "国家973计划项目课题" => "国家973计划项目课题", + "国家863计划课题"=>"国家863计划课题", + "国家级科技支撑课题" => "国家级科技支撑课题", + "国家级科技重大专项" => "国家级科技重大专项", + "国家级国家重大工程" => "国家级国家重大工程", + "国家级国家自然科学基金" => "国家级国家自然科学基金", + "国际合作项目"=>"国际合作项目", + "省部级项目" => "省部级项目", + "其他项目工程" => "其他项目工程", + ); + + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $data = $this->AccountEditParamFilter(); + + if($this->db->update("users",$data,"id=$uid")) + { + $this->view->AlertType = "alert-success"; + $this->view->msg = "修改成功!"; + $this->view->jump_url = "/account/edit"; + return true; + }else{ + $this->view->AlertType = "alert-error"; + $this->view->error = "修改失败,请重试"; + $this->view->info = $data; + return true; + } + }else{ + $this->view->info = $usr->getUserInfo($uid); + } + } + + function AccountEditParamFilter(){ + $data = array(); + $data['realname'] = substr(trim($this->_getParam('realname')),0,40); + $data['unit'] = substr(trim($this->_getParam('unit')),0,100); + $data['address'] = substr(trim($this->_getParam('address')),0,100); + $data['phone'] = substr(trim($this->_getParam('phone')),0,15); + $data['postcode'] = substr(trim($this->_getParam('postcode')),0,15); + $data['project_type'] = substr(trim($this->_getParam('project_type')),0,100); + $data['project_id'] = substr(trim($this->_getParam('project_id')),0,40); + $data['project_title'] = substr(trim($this->_getParam('project_title')),0,100); + $data['project'] = substr(trim($this->_getParam('project')),0,600); + + foreach($data as $k=>$v) + { + $data[$k] = $this->StringFilter($v); + } + + return $data; + } + + function StringFilter($string){ + $string = preg_replace ('/<[^>]*>/', ' ', $string); + return $string; + } + + function secureAction() + { + $this->view->pageID = "account-secure"; + + include_once("Users.php"); + $usr = new Users($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + $opt = $this->_getParam('opt'); + $submit = $this->_getParam('submit'); + + if(empty($opt)) + { + $this->view->section = "password"; + if(!empty($submit)) + { + $data = $this->AccountSecureParamFilter(); + + $this->view->AlertType = "alert-error"; + if(strlen($data['password'])>18 || strlen($data['new_password'])>18) + { + $this->view->error = view::Error("密码过长"); + return true; + } + if(strlen($data['new_password'])<=6 || strlen($data['new_password_confrim'])<=6) + { + $this->view->error = view::Error("密码过短,请输入大于6位的密码"); + return true; + } + if(md5($data['new_password']) != md5($data['new_password_confrim'])) + { + $this->view->error = view::Error("两次输入的密码不相同"); + return true; + } + + $sql = "SELECT password FROM users WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(md5($data['password']) != $row['password']) + { + $this->view->error = view::Error("原密码不正确"); + return true; + } + + $data['password'] = md5($data['new_password']); + + unset($data['new_password']); + unset($data['new_password_confrim']); + + if($this->db->update("users",$data,"id=$uid")) + { + view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); + return true; + }else{ + $this->view->error = view::Error("修改失败"); + return true; + } + }else{ + $this->view->info = $usr->getUserInfo($uid); + } + }//password + + if($opt == "email") + { + $this->view->section = "email"; + if(!empty($submit)) + { + $email = $this->_getParam('email'); + $password = $this->_getParam('password'); + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) + { + $this->view->error = view::Error("错误的邮箱格式"); + return true; + } + + $sql = "SELECT password FROM users WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(md5($password) != $row['password']) + { + $this->view->error = view::Error("原密码错误"); + return true; + } + + $data['email'] = $email; + + if($this->db->update("users",$data,"id=$uid")) + { + view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); + return true; + }else{ + $this->view->error = view::Error("修改失败"); + return true; + } + }else{ + $this->view->info = $usr->getUserInfo($uid); + } + }//email + } + + function AccountSecureParamFilter(){ + $data = array(); + $data['password'] = trim($this->_getParam('password')); + $data['new_password'] = trim($this->_getParam('new_password')); + $data['new_password_confrim'] = trim($this->_getParam('new_password_confrim')); + foreach($data as $k=>$v) + { + $data[$k] = $this->StringFilter($v); + } + return $data; + } + + function init() + { + $this->messenger=$this->_helper->getHelper('FlashMessenger'); + } + + function postDispatch() + { + //$this->view->messages = $this->messenger->getMessages(); + } + + function registerAction() + { + $order = new \Order\Order(); + + $this->view->projectType = array_merge(array("无"=>""),$order->projectType); + + $submit = $this->_getParam("submit"); + + if(!empty($submit)) + { + $account = new Account(); + $this->view->data = $data = $account->getRegisterParam(); + $status = $account->register($data); + + if(isset($status['error'])) + { + $this->view->error = view::Error($status['error']); + if(isset($status['place'])) + { + $this->view->place = $status['place']; + } + }else{ + view::Post($this,"注册成功!","/"); + return true; + } + } + + } + + function loginAction() + { + $options = array( + 'module' => $this->_request->getModuleName(), + 'controller' => $this->_request->getControllerName(), + 'action' => $this->_request->getActionName(), + ); + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + { + view::Post($this,"您已经登录,无需重复登录","/index"); + return true; + } + + $tohref = $this->_request->getParam('href'); + + if($_SERVER['REQUEST_URI'] !== "/account/login") + { + $this->view->href = $_SERVER['REQUEST_URI']; + }else{ + $this->view->href = "/"; + } + + if(!empty($tohref)) + { + $this->view->href = $tohref; + } + + $captcha = new Captcha(); + + $submit = $this->_getParam("submit"); + if(!empty($submit)) + { + $username = trim($this->_request->getParam('username')); + $password = trim($this->_request->getParam('password')); + $captchaword = trim($this->_request->getParam('captcha')); + + if($captcha->isValid($captchaword) !== true) + { + $this->view->error = view::Error("验证码错误"); + $this->view->captcha = $captcha->setCaptcha(); + return true; + } + + $account = new Account(); + $status = $account->login(array( + 'username' => $username, + 'password' => $password + )); + + if(isset($status['error'])) + { + $this->view->error = view::Error($status['error']); + $this->view->captcha = $captcha->setCaptcha(); + return true; + } + + view::Post($this,"登录成功,正在跳转",$tohref); + return true; + }else{ + $this->view->captcha = $captcha->setCaptcha(); + } + + + } + + public function captchaAction() + { + if(view::isXmlHttpRequest($this)) + { + $captcha = new Captcha(); + $url = $captcha->setCaptcha(); + echo $url; + return true; + }else{ + echo "bad request!"; + exit(); + } + } + + public function logoutAction() + { + $auth = Zend_Auth::getInstance(); + $auth->clearIdentity(); + Member::flushcookie(); + $this->_redirect('/'); + } + + public function fetchpwdAction() + { + $salt = trim($this->_getParam('salt')); + $submit = $this->_getParam('submit'); + if(empty($salt)) + { + $captcha = new Captcha(); + + if(!empty($submit)) + { + $email = trim($this->_request->getParam('email')); + $captchaword = trim($this->_request->getParam('captcha')); + + if(!$captcha->isValid($captchaword)) + { + $this->view->error = view::Error("验证码错误"); + $this->view->captcha = $captcha->setCaptcha(); + return true; + } + + $account = new Account(); + $status = $account->getMyPassword($email); + + if(isset($status['error'])) + { + $this->view->error = view::Error($status['error']); + $this->view->captcha = $captcha->setCaptcha(); + return true; + } + + view::Post($this,"您的密码重置申请已提交,请在邮箱中查看"); + return true; + }else{ + $this->view->captcha = $captcha->setCaptcha(); + }//提交密码重置申请 + } + + else{ + $this->_helper->viewRenderer('account-resetpassword'); + $this->view->salt = $salt; + if(!empty($submit)) + { + $username = trim($this->_request->getParam('username')); + $password = trim($this->_request->getParam('password')); + $confirm_password = trim($this->_request->getParam('confirm_password')); + + $account = new Account(); + $status = $account->resetPassword(array( + 'username' => $username, + 'password' => $password, + 'confirm_password' => $confirm_password, + 'salt' => $salt + )); + + if(isset($status['error'])) + { + $this->view->error = view::Error($status['error']); + return true; + } + + view::Post($this,"您的密码修改成功!请使用新密码登录","/account/login"); + return true; + } + }//修改密码 + + } //找回密码 + + //OAuth2登录跳转页面 + public function oauth2loginAction() + { + $type = $this->_getParam('type'); + $client = new Client(); + $url = $client->makeRequestCodeUrl($type); + + view::Post($this,"为您转入科技网登录入口",$url); + } + + //oauth2登录回调地址 + public function callbackAction() + { + $type = $this->_getParam('type'); + $code = $this->_getParam('code'); + + $client = new Client($type); + + $client->initSource(); + $target = $client->getSource()->getTarget($type); + $this->view->target_name = $target['name']; + + $token = $client->requestToken($code); + + if(is_string($token)) + { + view::Post($this,$token,'/account/login'); + } + + $status = $client->storageTokenData($type,$token); + + if($status === true) + { + echo ""; + }else{ + echo $status; + } + } + +} + diff --git a/application/default/views/scripts/account/edit.phtml b/application/default/views/scripts/account/edit.phtml index c37d8411..db4eff44 100755 --- a/application/default/views/scripts/account/edit.phtml +++ b/application/default/views/scripts/account/edit.phtml @@ -53,13 +53,13 @@
- info['unit']; ?>" class="span8" /> + info['unit']; ?>" class="input-block-level" />
- info['address']; ?>" class="span8" /> + info['address']; ?>" class="input-block-level" />
@@ -107,13 +107,13 @@
- info['project_title']; ?>" class="span8" /> + info['project_title']; ?>" class="input-block-level" />
- +
diff --git a/application/default/views/scripts/account/fetchpwd.phtml b/application/default/views/scripts/account/fetchpwd.phtml index fcea22a9..ac41ca95 100644 --- a/application/default/views/scripts/account/fetchpwd.phtml +++ b/application/default/views/scripts/account/fetchpwd.phtml @@ -1,24 +1,55 @@ -headTitle($this->config->title->site); - $this->headTitle('用户登录'); - $this->headTitle()->setSeparator(' - '); - $this->headLink()->appendStylesheet('/css/register.css'); - $this->breadcrumb('首页'); - $this->breadcrumb('找回密码'); - $this->breadcrumb()->setSeparator(' > '); -?> -messages)) : ?> -
-messages as $info)echo $info; - ?> -
- -form) : ?> -
-form;?> -
- - +headTitle($this->config->title->site); + $this->headTitle('用户登录'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/register.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('找回密码'); + $this->breadcrumb()->setSeparator(' > '); +?> +
+ error)) { ?> + error ?> + +
+
+ +
+ + 请输入注册时填写的Email地址 +
+
+
+ +
+ + + 看不清? +
+
+
+
+ + href)){?> + + + + 登录 注册新用户 +
+
+
+
+ \ No newline at end of file diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index a362a769..6b389c32 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -6,21 +6,6 @@ $this->breadcrumb('用户登录'); $this->breadcrumb()->setSeparator(' > '); ?> -
error)) { ?> @@ -28,9 +13,7 @@ 请输入用户名和密码登录
- + error ?>
@@ -64,9 +47,6 @@
-
-
其它账号登录
-中国科技网通行证
+ \ 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/Users/Account.php b/application/module/Users/Account.php index 717a34d6..0f94658e 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -1,372 +1,390 @@ -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 getRegisterParam(\Zend_Controller_Request_Abstract $request = NULL) + { + if(empty($request)) + { + $request = new \Zend_Controller_Request_Http(); + } + $data = array( + 'username'=>trim($request->getParam('username')), + 'password'=>trim($request->getParam('password')), + 'confirm_password'=>trim($request->getParam('confirm_password')), + 'email' => trim($request->getParam('email')), + 'realname' => trim($request->getParam('realname')), + 'phone' => trim($request->getParam('phone')), + 'unit' => trim($request->getParam('unit')), + 'address' => trim($request->getParam('address')), + 'project' => trim($request->getParam('project')), + 'project_id' => trim($request->getParam('project_id')), + 'project_type' => trim($request->getParam('project_type')), + 'project_title' => trim($request->getParam('project_title')), + 'project_leader'=> trim($request->getParam('project_leader')), + 'postcode' => trim($request->getParam('postcode')), + ); + 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..c7ad012c 100644 --- a/application/module/Users/Member.php +++ b/application/module/Users/Member.php @@ -1,11 +1,11 @@ "用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username'); + return array('error'=>"用户名长度应该大于两个字符",'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'])) diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php index 9d3c006a..0c02b560 100644 --- a/application/module/Users/Operation/RegisterOperate.php +++ b/application/module/Users/Operation/RegisterOperate.php @@ -7,7 +7,7 @@ use \Helpers\View as view; class RegisterOperate implements \Users\Event\RegisterEvent { private $db; //传入PDO对象 - public $tbl_member = "tbl_member"; + public $tbl_member = "users"; public $FieldUsername = "username"; public $FieldPasword = "password"; public $FieldLastlogin = "ts_last_login"; @@ -45,9 +45,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent if(!empty($data['username'])) { - if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username'])) + if(!preg_match("/[0-9a-zA-Z\xa0-\xff_]{2,25}/",$data['username'])) { - return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到16个字符之间",'place'=>'username'); + return array('error'=>"用户名只能包含字母汉字数字和下划线,并且长度在2到26个字符之间",'place'=>'username'); } } @@ -83,17 +83,15 @@ class RegisterOperate implements \Users\Event\RegisterEvent if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email'])) { - return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place'=>'email'); + return array('error'=>"请输入正确的电子邮件地址",'place'=>'email'); } - if(empty($data['realname'])) + if(!empty($data['realname'])) { - return array('error'=>"请输入姓名",'place'=>'realname'); - } - - if(mb_strlen($data['realname'],"UTF-8")>10 ) - { - return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname'); + if(mb_strlen($data['realname'],"UTF-8")>10 ) + { + return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname'); + } } return true; @@ -118,7 +116,7 @@ class RegisterOperate implements \Users\Event\RegisterEvent { if($row[$this->FieldUsername] == $data['username']) { - return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>'username'); + return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>'username'); } if($row[$this->FieldEmail] == $data['email']) @@ -148,10 +146,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent return false; } - $mail_template = "register"; + $mail_template = "member-register"; $mail_data = array( 'name'=>$data['realname'], - 'content'=>$this->getMailContent() ); $mail = new Mail(); @@ -166,25 +163,11 @@ class RegisterOperate implements \Users\Event\RegisterEvent //邮件内容 public function getMailContent() { - $sql = "SELECT v.id,v.title,v.thumb,v.status,v.content,m.realname,m.username FROM tbl_voice v - LEFT JOIN tbl_member m ON v.userid = m.id - WHERE v.status > 0 - ORDER BY v.id DESC - LIMIT 5"; - $rs = $this->db->query($sql); - $latest = $rs->fetchAll(); + $content = ""; - foreach($latest as $k=>$v) - { - if($v['thumb'] != '[]') - { - $thumb = json_decode($v['thumb'],true); - $text = mb_strlen($v['content'],"UTF-8") > 100 ? mb_substr($v['content'],0,100,"UTF-8") : $v['content']; - $content .= '

'.$v['title']. ' / ' .$v['realname'].'
'.$text.'
查看播放

'; - } - } + return $content; }//getMailContent();