diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 53789af8..7ad19371 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,300 +1,654 @@ -_redirect('/'); - } - function init() - { - $this->messenger=$this->_helper->getHelper('FlashMessenger'); - } - function postDispatch() - { - //$this->view->messages = $this->messenger->getMessages(); - } - function preDispatch() - { - $this->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(); - } - - 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=new WestdcMailer($this->view->config->smtp); - $body=file_get_contents($this->view->config->register->email->template); - $body=str_replace("[username]",$formData['username'],$body); - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - //中文标题有乱码,在1.5版本中尚未解决 - //ref: http://framework.zend.com/issues/browse/ZF-2532 - $mail->setSubject('欢迎使用中国西部环境与生态数据中心'); - $mail->send(); - - //自动登录系统 - $this->login($formData['username'],$formData['password']); - $this->_redirect('/'); - } - } else { - $form->populate($formData); - } - } - } - function editAction() - { - $form=new UsereditForm(); - $this->view->form=$form; - $auth = Zend_Auth::getInstance(); - $user = $auth->getIdentity(); - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - //save user info - $ut=new UsersTable(); - $row=$ut->fetchRow('id='.$formData['id']); - if (md5($formData['oldpassword'])==$row->password && $formData['password']) { - //修改密码 - $row->password=md5($formData['password']); - } - if ($formData['email']) $row->email=$formData['email']; - if ($formData['phone']) $row->phone=$formData['phone']; - if ($formData['realname']) $row->realname=$formData['realname']; - if ($formData['unit']) $row->unit=$formData['unit']; - if ($formData['address']) $row->address=$formData['address']; - if ($formData['project']) $row->project=$formData['project']; - $row->save(); - //todo:更新session信息 - } - } else { - /*$formData['id']=$user->id; - $formData['email']=$user->email; - $formData['phone']=$user->phone; - $formData['realname']=$user->realname; - $formData['unit']=$user->unit; - $formData['address']=$user->address; - $formData['project']=$user->project;*/ - $ut=new UsersTable(); - $row=$ut->fetchRow('id='.$user->id); - $formData['email']=$row->email; - $formData['phone']=$row->phone; - $formData['realname']=$row->realname; - $formData['unit']=$row->unit; - $formData['address']=$row->address; - $formData['project']=$row->project; - $formData['id']=$row->id; - $form->populate($formData); - } - } - function loginAction() - { - $form = new LoginForm(); - $success=false; - $message=''; - $this->view->form = $form; - $auth = Zend_Auth::getInstance(); - if ($auth->hasIdentity()) $this->_redirect('/account'); - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - if (!$this->login($formData['username'],$formData['password'])) - { - $this->messenger->addMessage('登录失败,请检查您的用户名和密码。'); - } else $success=true; - } - - if(!$success) { - $flashMessenger = $this->_helper->getHelper('FlashMessenger'); - $flashMessenger->setNamespace('actionErrors'); - $flashMessenger->addMessage($message); - $this->_redirect('/account/login'); - } else - { - $tohref = $this->_request->getParam('href'); - if(!empty($tohref)) - { - $this->_redirect($tohref); - }else{ - $this->_redirect($this->_request->getParam('return')); - } - - } - } else { - //$formData['redirect'] = $redirect; - //$form->populate($formData); - } - } - - function logoutAction() - { - $auth = Zend_Auth::getInstance(); - $auth->clearIdentity(); - require_once 'member.php'; - $mb=new member(); - $mb::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'); - $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; - } - 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=new WestdcMailer($this->view->config->smtp); - $body="尊敬的西部数据中心用户: - 有人提出了针对此用户名的密码重置请求。 - - 用户名:"; - $body.=$username; - $body.=" - - 若想重置您的密码请打开下面的链接,否则请忽略此邮件,一切如常。 -"; - $body.="http://westdc.westgis.ac.cn/account/fetchpwd/".$username."/".$uid; - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - $mail->setSubject('密码已重置'); - $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=new WestdcMailer($this->view->config->smtp); - $body="尊敬的西部数据中心用户: - 您的密码已修改。 - - 用户名:"; - $body.=$login; - $body.="密码:".$tmp_pwd; - $body.=" - http://westdc.westgis.ac.cn/account/login"; - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($urow->email); - $mail->setSubject('您的新密码'); - $mail->send(); - $this->view->messages[]='请查收您新邮件中的新密码'; - $this->view->form=false;//do not echo form - - } - } - - } -} - +_redirect('/'); + } + function init() + { + $this->messenger=$this->_helper->getHelper('FlashMessenger'); + } + function postDispatch() + { + //$this->view->messages = $this->messenger->getMessages(); + } + function preDispatch() + { + $this->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(); + } + + function registerAction() + { + $reg = $this->_request->getParam('submit'); + if(!empty($reg)) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + try{ + + $username = mb_substr(trim($this->_request->getParam('username')),0,100,'utf-8'); + $name = mb_substr(trim($this->_request->getParam('name')),0,100,'utf-8'); + $email = mb_substr(trim($this->_request->getParam('email')),0,100,'utf-8'); + $phone = mb_substr(trim($this->_request->getParam('phone')),0,100,'utf-8'); + $unit = mb_substr(trim($this->_request->getParam('employer')),0,200,'utf-8'); + $address = mb_substr(trim($this->_request->getParam('address')),0,250,'utf-8'); + $project = mb_substr(trim($this->_request->getParam('project')),0,500,'utf-8'); + $password = mb_substr(trim($this->_request->getParam('password')),0,22,'utf-8'); + $password_confirm = mb_substr(trim($this->_request->getParam('password_confirm')),0,22,'utf-8'); + $vdcode = strtolower(substr(trim($this->_request->getParam('vdcode')),0,4)); + + include_once('ajax/box.php'); + + if(strlen($username)<6) + { + echo box::warning('用户名不能少于6个字符'); + exit(); + } + + if(strlen($username)>20) + { + echo box::warning('用户名不能超过20个字符'); + exit(); + } + + if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,19}$/",$username)) + { + echo box::warning("用户名只能包含英文字母及数字"); + exit(); + } + + if(strlen($name)<2) + { + echo box::warning("姓名太短"); + exit(); + } + + if(strlen($name)>32) + { + echo box::warning("姓名太长"); + exit(); + } + + if(preg_match("/[\"|'|~|!|#|\$|%|\^|\&|\*|\+|\{|\}|\[|\]|:|;|<|>|\?|\/]/",$name)) + { + echo box::warning("姓名中包含非法字符"); + exit(); + } + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) + { + echo box::warning("请输入正确的Email地址"); + exit(); + } + + if(!empty($phone) && preg_match("/[\"|'|~|!|#|\$|%|\^|\&|\*|\{|\}|\[|\]|:|;|<|>|\?|\/]/",$phone)) + { + echo box::warning("请输入正确的电话号码"); + exit(); + } + + if(!empty($unit) && preg_match("/[\"|'|~|!|#|\$|%|\^|\&|\*|\{|\}|\[|\]|:|;|<|>|\?|\/]/",$unit)) + { + echo box::warning("输入的内容中包含非法字符"); + exit(); + } + + if(!empty($address) && preg_match("/[\"|'|~|!|\$|%|\^|\&|\*|\{|\}|\?|\/]/",$address)) + { + echo box::warning("地址中包含非法字符"); + exit(); + } + + $match = "/[\"|'|\\\]/i"; + + if(preg_match($match,$password) || preg_match($match,$password_confirm)) + { + echo box::warning("密码中包含非法字符,请重新输入"); + exit(); + } + + if(empty($password)) + { + echo box::warning("请输入密码"); + exit(); + } + + if(strlen($password)<6) + { + echo box::warning("密码太短"); + exit(); + } + + if(strlen($password)>20) + { + echo box::warning("密码长度不能超过20个字符"); + exit(); + } + + if($password!==$password_confirm) + { + echo box::warning("两次输入的密码不同"); + exit(); + } + + $sql = "select id from users where username like '%$username%'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if($row['id']>0) + { + echo box::warning("该用户名已经被占用,请更换"); + exit(); + } + + $sql = "select id from users where email like '%$email%'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if($row['id']>0) + { + echo box::warning("该Email已经被使用,请更换"); + exit(); + } + + if($vdcode != $_SESSION['vdcodes']) + { + echo box::warning("验证码错误"); + exit(); + } + + $sql = "INSERT INTO users (username,password,email,realname,unit,address,project,phone,usertype) + VALUES (?,?,?,?,?,?,?,?,?)"; + + $sth = $this->db->prepare($sql); + $ec = $sth->execute(array($username,md5($password),$email,$name,$unit,$address,$project,$phone,'member')); + + //$sql = "INSERT INTO users (username,password,usertype,email,realname,unit,address,project,phone) + // VALUES ('$username','".md5($password)."','member','$email','$name','$unit','$address','$project','$phone')"; + //$ec = $this->db->exec($sql); + if($ec) + { + $this->login($username,md5($password)); + echo box::success(""); + exit(); + } + else + { + echo box::warning("An error occurred!Re-try please!"); + exit(); + } + }catch(Exception $e){ + echo box::warning("An error occurred!".$e->getMessage()); + exit(); + } + }//ajax 注册 + } + + + function editAction() + { + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $username = $user->username; + $sql = "select * from users where username='$username'"; + $rs = $this->db->query($sql); + $rows = $rs->fetch(); + $this->view->user = $rows; + } + } + + + function saveoptAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $opt = $this->_request->getParam('opt'); + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $username = $user->username; + $sql = "select * from users where username='$username'"; + $rs = $this->db->query($sql); + $rows = $rs->fetch(); + $this->view->user = $rows; + } + else + { + echo "You must log in"; + exit(); + } + + if($opt == 'general') + { + $realname = mb_substr(trim($this->_request->getParam('name')),0,100,'utf-8'); + $phone = mb_substr(trim($this->_request->getParam('phone')),0,100,'utf-8'); + $unit = mb_substr(trim($this->_request->getParam('employer')),0,200,'utf-8'); + $address = mb_substr(trim($this->_request->getParam('address')),0,250,'utf-8'); + $project = mb_substr(trim($this->_request->getParam('project')),0,500,'utf-8'); + + try{ + + if(empty($realname)) + { + echo "Please enter your Name"; + exit(); + } + + $sql = "UPDATE users SET realname='$realname',phone='$phone',unit='$unit',address='$address',project='$project' WHERE id='{$rows['id']}'"; + if($this->db->query($sql)) + { + echo "Saved!"; + exit(); + }else{ + echo "Failed!"; + exit(); + } + + //Error!Retry please!SQLSTATE[42P02]: Undefined parameter: 7 错误: 没有参数 $1 CONTEXT: Error occurred on dblink connection named "unnamed": could not execute command. + }catch (Exception $e){ + echo "An error occurred!"; + exit(); + } + } + + else if ($opt == 'email') + { + $email = substr(trim($this->_request->getParam('email')),0,100); + $password = trim($this->_request->getParam('password')); + + try{ + + if(empty($email)) + { + echo "Please enter your E-mail"; + exit(); + } + + if(empty($password)) + { + echo "Please enter your password"; + exit(); + } + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) + { + echo "Incorrect email"; + exit(); + } + + if(md5($password)!==$rows['password']){ + echo "The password you entered is incorrect.Please re-enter your password"; + exit(); + } + + $sql = "UPDATE users SET email='$email' where id='{$rows['id']}'"; + if($this->db->query($sql)) + { + echo "Saved!"; + exit(); + }else{ + echo "Failed!"; + exit(); + } + }catch(Exception $e){ + echo "An error occurred!"; + exit(); + } + + } + + else if ($opt == 'password') + { + $password = trim($this->_request->getParam('password')); + $password_new = trim($this->_request->getParam('password_new')); + $password_confirm = trim($this->_request->getParam('password_confirm')); + + $match = "/[\"|'|\\\]/i"; + + if(empty($password)) + { + echo "Please enter your password"; + exit(); + } + + if(empty($password_new)) + { + echo "Please enter your new password"; + exit(); + } + + if($password==$password_new) + { + echo "New password cannot be same as the old"; + exit(); + } + + if(empty($password_confirm)) + { + echo "Please re-enter your new password"; + exit(); + } + + if(preg_match($match,$password) || preg_match($match,$password_new) || preg_match($match,$password_confirm) || $rows['password']!== md5($password)) + { + echo "The password you entered is incorrect.Please re-enter your password"; + exit(); + } + + if(strlen($password_new)<6) + { + echo "Your new password is too short"; + exit(); + } + + if(strlen($password_new)>20) + { + echo "Your new password is too long"; + exit(); + } + + if(md5($password_new) !== md5($password_confirm)) + { + echo "Entered passwords differ from the another"; + exit(); + } + + try{ + + $sql = "UPDATE users SET password='".md5($password_new)."' WHERE username='$username'"; + if($this->db->query($sql)) + { + echo "Changes Saved!"; + exit(); + }else{ + echo "Failed!Please check the input content"; + exit(); + } + + }catch(Exception $e){ + echo "An error occurred!"; + exit(); + } + + } + + else + { + exit(); + } + } //saveopt ajax修改用户信息 + + function loginAction() + { + $submit = $this->_request->getParam('submit'); + + if(!empty($submit)) + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $success=false; + $message=''; + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + $this->_redirect('/account'); + + $username = trim($this->_request->getParam('username')); + $password = trim($this->_request->getParam('password')); + $vdcode = strtolower(substr(trim($this->_request->getParam('vdcode')),0,4)); + + include_once('ajax/box.php'); + + if(empty($username)) + { + echo box::warning('请输入用户名'); + exit(); + } + + if(empty($password)) + { + echo box::warning('请输入密码'); + exit(); + } + + if(empty($vdcode)) + { + echo box::warning('请输入验证码'); + exit(); + } + + if($vdcode != $_SESSION['vdcodes']) + { + echo box::warning("验证码错误"); + exit(); + } + + if (!$this->login($username,$password)) + { + echo box::error('用户名或密码错误'); + exit(); + } + + else + { + echo box::success('登录成功,如果页面没有跳转请点击这里'); + exit(); + } + + + + $tohref = $this->_request->getParam('href'); + if(!empty($tohref)) + { + $this->_redirect($tohref); + }else{ + $this->_redirect($this->_request->getParam('return')); + } + + } + } + + function logoutAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + { + $auth->clearIdentity(); + require_once 'member.php'; + 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'); + $auth->getStorage()->write($data); + $db->query($db->quoteInto("update users set ts_last_login=now() where username=?",$u)); + + if ($this->_request->getParam('remember')) { + require_once 'member.php'; + $mb = new member(); + $mb -> putcookie($u,md5($p)); + } + + return true; + } + 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) + { + $db=Zend_Registry::get('db'); + $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() + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + $this->_redirect('/account'); + + $email = $this->_request->getParam('email'); + + include_once('ajax/box.php'); + if(empty($email)) + { + echo box::warning('请输入要找回密码的账户所对应的Email地址'); + exit(); + } + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) + { + echo box::warning("请输入正确的Email地址"); + exit(); + } + + $sql = "SELECT * FROM users WHERE email=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($email)); + $row = $sth->fetch(); + + if($row['id']=='') + { + echo box::error("未找到对应用户"); + exit(); + } + + + //email the url to user + $username=$row['username']; + $sql="update users set activation=? where email=?"; + $uid=uniqid(); + $db->query($sql,array($uid,$formData['email'])); + $mail=new WestdcMailer($this->view->config->smtp); + $mailtp=new EmailText($this->db, + 'member-fetchpwd', + array('user' => $username,'uid'=>$uid) + ); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'WDSCAR Service Team'); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($email); + $mail->send(); + $this->view->messages[]='Please check the activation link in your email.'; + $this->view->form=false;//do not echo form + + + + $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=new WestdcMailer($this->view->config->smtp); + $mailtp=new EmailText($this->db, + 'member-fetchpwd', + array('user' => $username,'uid'=>$uid) + ); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'WDSCAR Service Team'); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($formData['email']); + $mail->send(); + $this->view->messages[]='Please check the activation link in your email.'; + $this->view->form=false;//do not echo form + } else + $this->messenger->addMessage('Sorry, the email is not found.'); + } + } else + $this->view->messages[]='Please input your email, you will get the new password in your email.'; + } 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=new WestdcMailer($this->view->config->smtp); + $mailtp=new EmailText($this->db,'member-resetpwd', + array('user' => $login,'pwd'=>$tmp_pwd)); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'WDSCAR Service Team'); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($urow->email); + $mail->send(); + $this->view->messages[]='Please check your new password in your email.'; + $this->view->form=false;//do not echo form + } + } + }// function fetchpwdAction() +} + diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 7cad0074..4a556c82 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -56,6 +56,13 @@ class ServiceController extends Zend_Controller_Action print base64_decode($thumb['data']); } } + + public function getFileinfo($id){ + $sql = "select * from attachments where id='$id'"; + $re= $this->db->query($sql); + $row= $re->fetch(); + return $row; + } /* * 查看数据缩略大图 @@ -115,8 +122,8 @@ class ServiceController extends Zend_Controller_Action $sql="select id,title,uuid,description,filesize,fileformat from metadata where east and west>? and north and south>?"; if (!empty($key)) { $search=new Search($key); - $where=$search->sql_expr(array("title","description")); - $sql.= " and ".$where; + $where=$search->sql_expr(array("title","description")); + $sql.= " and ".$where; $sql.= " order by title"; $rows=$this->db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%')); } else { @@ -240,7 +247,7 @@ class ServiceController extends Zend_Controller_Action $sql="select uuid,title,datatype,filesize,id from normalmetadata"; $md=$this->db->fetchAll($sql); foreach($md as $m) - { + { print $m["uuid"].","; print $m["title"].","; print ($m["datatype"]?"内部":"公开").","; @@ -1052,7 +1059,7 @@ class ServiceController extends Zend_Controller_Action { if($page > 0) { - $pre = '
'; + $pre = ''; } if($num > $pageSize*($page+1)) { @@ -1187,7 +1194,7 @@ class ServiceController extends Zend_Controller_Action { $pre = '<'; }else{ - $pre = '<'; + $pre = '<'; } if($num <= $pageSize*($page+1)) { @@ -1214,42 +1221,42 @@ class ServiceController extends Zend_Controller_Action } echo ''; echo $pagnation; - }//文档页面相关数据 - function geonetworkAction() - { + }//文档页面相关数据 + function geonetworkAction() + { $this->_helper->viewRenderer->setNoRender(); - $this->_helper->layout->disableLayout(); + $this->_helper->layout->disableLayout(); $auth = Zend_Auth::getInstance(); - $url = $this->config->geonetwork->url.'/srv/cn/'.urldecode($this->_request->getParam('url')); - if (!$auth->hasIdentity()) - { - $this->_redirect('/account/login?href=/service/geonetwork?url='.$url); - } - $user = $auth->getIdentity(); - //need to get pwd from database - $sql='select username,md5(password) as pwd from users where id='.$user->id; - $this->db->setFetchMode(Zend_Db::FETCH_OBJ); - $row=$this->db->fetchRow($sql); - $login=$this->config->geonetwork->url.'/srv/en/xml.user.login?username='.$row->username.'&password='.$row->pwd; - $body=' - - - + $url = $this->config->geonetwork->url.'/srv/cn/'.urldecode($this->_request->getParam('url')); + if (!$auth->hasIdentity()) + { + $this->_redirect('/account/login?href=/service/geonetwork?url='.$url); + } + $user = $auth->getIdentity(); + //need to get pwd from database + $sql='select username,md5(password) as pwd from users where id='.$user->id; + $this->db->setFetchMode(Zend_Db::FETCH_OBJ); + $row=$this->db->fetchRow($sql); + $login=$this->config->geonetwork->url.'/srv/en/xml.user.login?username='.$row->username.'&password='.$row->pwd; + $body=' + + + '; $this->getResponse()->setHeader('Content-Type', 'text/html') - ->setBody($body); + ->setBody($body); } /* @@ -1262,30 +1269,30 @@ class ServiceController extends Zend_Controller_Action include_once('ImgCode.php'); $imagecode=new Custom_Controller_Plugin_ImgCode(); $imagecode->image2(); - } - - //header output - function headerAction() - { + } + + //header output + function headerAction() + { $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $header=file_get_contents('../application/default/views/scripts/header.phtml'); + $this->_helper->viewRenderer->setNoRender(); + $header=file_get_contents('../application/default/views/scripts/header.phtml'); $content=''; - $content.=eval('?>'.$header); - $content.=''; + href="/css/default.css" />'; + $content.=eval('?>'.$header); + $content.=''; $this->getResponse()->setHeader('Content-Type', 'text/html') - ->setBody($content); - } - - //footer output - function footerAction() - { + ->setBody($content); + } + + //footer output + function footerAction() + { $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $footer=file_get_contents('../application/default/views/scripts/footer.phtml'); + $this->_helper->viewRenderer->setNoRender(); + $footer=file_get_contents('../application/default/views/scripts/footer.phtml'); $this->getResponse()->setHeader('Content-Type', 'text/html') - ->setBody($footer); - } + ->setBody($footer); + } } diff --git a/application/default/controllers/SubmitController.php b/application/default/controllers/SubmitController.php index 63eeea8b..4ec1ce0b 100644 --- a/application/default/controllers/SubmitController.php +++ b/application/default/controllers/SubmitController.php @@ -32,12 +32,12 @@ class SubmitController extends Zend_Controller_Action function helpAction(){ }//helpAction()帮助文档 - - //新建元数据 - function newdataAction() - { + + //新建元数据 + function newdataAction() + { $ac = $this->_request->getParam('ac'); - $id = $this->_request->getParam('id'); + $id = $this->_request->getParam('id'); $this->wdb=Zend_Db::factory($this->view->config->geonetwork); $auth = Zend_Auth::getInstance(); @@ -49,10 +49,10 @@ class SubmitController extends Zend_Controller_Action //在geonetwork中查看单条数据 if (!empty($id) && empty($ac)) - { + { $this->view->url='metadata.show?id='.$id; $this->_helper->viewRenderer('newdata-view'); - } + } //查看属于自己的所有的未提交数据列表 else if((empty($ac) && empty($uuid))|| $ac=='list') { @@ -71,168 +71,333 @@ class SubmitController extends Zend_Controller_Action $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; - } + } //元数据导入 else if($ac=="import") { $this->_helper->viewRenderer('newdata-import'); - } + } //从模板新建元数据 else if($ac=="add") - { + { $keywords = $this->_request->getParam('q'); - if(!empty($keywords)) + if(!empty($keywords)) { $this->view->q = $keywords; - $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md + $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md left join geonetworkmetadata gn on md.uuid=gn.uuid WHERE gn.id is not null"; $search=new Search($keywords); $where=$search->sql_expr(array("md.title","md.description")); - $sql.=' and '.$where; + $sql.=' and '.$where; $sql.=" order by md.ts_created desc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); - + $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } - $sql="select id,(regexp_matches(data,'+ +
+ ++ +
+ +