修改邮件设置和发送配置

This commit is contained in:
Li Jianxuan 2014-03-07 03:21:59 +00:00
parent 02e12c01ae
commit 9b946942d9
4 changed files with 327 additions and 327 deletions

View File

@ -20,7 +20,7 @@ return array(
'port' => 994,
'ssl' => 'tls',
'auth' => 'login',
'name' => '青海省生态综合数据网' //发件人
),
'template'=> array(
'register' => 'member-register', //注册

View File

@ -1,313 +1,314 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage;
use Sookon\User\Account;
use Sookon\User\Member;
use Sookon\User\Gravatar;
use Sookon\Helpers\Auth;
use Sookon\Helpers\Captcha;
use Sookon\Helpers\View as view;
class AccountController extends AbstractActionController
{
public $ViewModel;
public function __construct()
{
$this->ViewModel = new ViewModel();
}
public function indexAction()
{
$submit = $this->params()->fromPost('submit');
$account = new Account();
if(!empty($submit))
{
$data = $account->getEditParam($this->getRequest());
$Listener = new \Sookon\User\Listener\EditListener();
$account->getEventManager()->attachAggregate($Listener);
$type = $this->params()->fromPost('type');
$this->ViewModel->setVariable('section',$type) ;
$status = $account->edit($data,$type);
if($status !== true)
{
$this->ViewModel->setVariable('error',view::Error($status));
}else{
$this->ViewModel->setVariable('error',view::Error("修改成功","alert-success"));
}
}
$user = $account->getAccountInfo();
$av = new Gravatar();
$this->ViewModel->setVariable('user',$user);
$this->ViewModel->setVariable('avatar',$av->Get($user['email'],100));
return $this->ViewModel;
}
public function loginAction()
{
if($this->getRequest()->isXmlHttpRequest())
{
$submit = $this->params()->fromPost('submit');
if(!empty($submit))
{
if ($auth->hasIdentity())
{
return JsonModel(array('error'=>"您已登录,无需重复登录"));
}
else{
$account = new Account();
$status = $account->login(array(
'username'=>$this->params()->fromPost('username'),
'password'=>$this->params()->fromPost('password')
));
if(is_array($status))
{
return new JsonModel($status);
}
}
}
return;
}
$auth = new Auth;
$instance = $auth->getInstance();
if ($instance->hasIdentity())
{
view::Post($this,'您已经登陆过了,无需重复登陆','/');
return $this->ViewModel;
}
$submit = $this->params()->fromPost('submit');
if(!empty($submit))
{
$account = new Account();
$status = $account->login(array(
'username'=>$this->params()->fromPost('username'),
'password'=>$this->params()->fromPost('password')
));
if(isset($status['error']))
{
$viewModel = array('error' => view::Error($status['error']));
if(isset($status['place']))
{
array_push($viewModel,array("place"=>$status['place']));
}
return new ViewModel($viewModel);
}else{
if(isset($_GET['href']) && !preg_match("/http:\/\//",$_GET['href']) && $_GET['href'] != '/account/login')
{
$href = $_GET['href'];
}else{
$href = "/";
}
view::Post($this,"登陆成功!",$href);
return $this->ViewModel;
}
}
}//login
public function registerAction()
{
if($this->getRequest()->isXmlHttpRequest())
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$account = new Account();
$data = $account->getParam($this->_request);
$result = $account->register($data);
if(!empty($result))
{
$this->jsonexit($result);
return true;
}
$this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试'));
return;
}
$success = false;
$auth = new Auth;
$instance = $auth->getInstance();
if ($instance->hasIdentity())
{
view::Post($this,'您已经登陆过了,无需重复登陆','/');
return $this->ViewModel;
}
$submit = $this->params()->fromPost('submit');
if(!empty($submit))
{
$account = new Account();
$data = array(
'username' => $this->params()->fromPost('username'),
'password'=>$this->params()->fromPost('password'),
'confirm_password'=>$this->params()->fromPost('confirm_password'),
'email'=>$this->params()->fromPost('email'),
'realname'=>$this->params()->fromPost('realname')
);
$result = $account->register($data);
if(!empty($result))
{
if(isset($result['error']))
{
$this->ViewModel->setVariable('error',view::Error($result['error']));
$this->ViewModel->setVariable('data',$data);
if(isset($result['place']))
{
$this->ViewModel->setVariable('place',$result['place']);
}
return $this->ViewModel;
}
if(isset($result['success']))
{
view::Post($this,"注册成功!",'/');
return $this->ViewModel;
}
}else{
$this->ViewModel->setVariable('error','处理中出现问题');
$this->ViewModel->setVariable('data',$data);
return $this->ViewModel;
}
}//submit
}//用户注册
//登录状态
public function loginstatus()
{
}
public function logoutAction()
{
$auth = new Auth();
$result = $auth->clearIndentity();
Member::flushcookie();
view::Post($this,"您已经成功注销",'/');
return $this->ViewModel;
}
//找回密码
function forgotpasswordAction()
{
$submit = $this->params()->fromPost('submit');
$captcha = new Captcha();
if(!empty($submit))
{
$email = $this->params()->fromPost('email');
$captchaword = $this->params()->fromPost('captcha');
if(!$captcha->isValid($captchaword))
{
$this->ViewModel->setVariable('error',view::Error("验证码错误"));
$this->ViewModel->setVariable('captcha', $captcha->setCaptcha());
return $this->ViewModel;
}
$account = new Account();
$status = $account->getMyPassword($email);
if(isset($status['error']) && !empty($status['error']))
{
$this->ViewModel->setVariable('error',$status['error']);
return $this->ViewModel;
}else{
$this->ViewModel->setVariable('msg',"申请成功!请在您的邮箱中查看密码重置邮件");
return $this->ViewModel;
}
}else{
$this->ViewModel->setVariable('captcha', $captcha->setCaptcha());
return $this->ViewModel;
}
}
//重置密码
function getpasswordAction()
{
$submit = $this->params()->fromPost('submit');
$salt = $this->params()->fromQuery('salt');
if(empty($salt))
{
$this->ViewModel->setVariable('msg',view::Msg("alert-danger","缺少密码重置密钥"));
return $this->ViewModel;
}
$this->ViewModel->setVariable('salt',$salt);
if(!empty($submit))
{
$data = array(
'username' => $this->params()->fromPost('username'),
'password' => $this->params()->fromPost('password'),
'confirm_password' => $this->params()->fromPost('confirm_password'),
'salt' => $salt
);
$account = new Account();
$Listener = new \Sookon\User\Listener\PwdListener();
$account->getEventManager()->attachAggregate($Listener);
$status = $account->resetPassword($data);
if(isset($status['error']) && !empty($status['error']))
{
$this->ViewModel->setVariable('username',$data['username']);
$this->ViewModel->setVariable('error',view::Error($status['error']));
return $this->ViewModel;
}else{
$this->ViewModel->setVariable('msg',view::Msg("alert-success","您的密码已经成功更改,<a href='/account/login'>请点击这里登陆</a>"));
return $this->ViewModel;
}
}
}//getpasswordAction()
public function captchaAction()
{
if($this->getRequest()->isXmlHttpRequest())
{
$this->ViewModel->setTerminal(true);
$captcha = new Captcha();
$url = $captcha->setCaptcha();
echo $url;
exit();
}else{
echo "bad request!";
exit();
}
}
}
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage;
use Sookon\User\Account;
use Sookon\User\Member;
use Sookon\User\Gravatar;
use Sookon\Helpers\Auth;
use Sookon\Helpers\Captcha;
use Sookon\Helpers\View as view;
class AccountController extends AbstractActionController
{
public $ViewModel;
public function __construct()
{
$this->ViewModel = new ViewModel();
}
public function indexAction()
{
$submit = $this->params()->fromPost('submit');
$account = new Account();
if(!empty($submit))
{
$data = $account->getEditParam($this->getRequest());
$Listener = new \Sookon\User\Listener\EditListener();
$account->getEventManager()->attachAggregate($Listener);
$type = $this->params()->fromPost('type');
$this->ViewModel->setVariable('section',$type) ;
$status = $account->edit($data,$type);
if($status !== true)
{
$this->ViewModel->setVariable('error',view::Error($status));
}else{
$this->ViewModel->setVariable('error',view::Error("修改成功","alert-success"));
}
}
$user = $account->getAccountInfo();
$av = new Gravatar();
$this->ViewModel->setVariable('user',$user);
$this->ViewModel->setVariable('avatar',$av->Get($user['email'],100));
return $this->ViewModel;
}
public function loginAction()
{
if($this->getRequest()->isXmlHttpRequest())
{
$submit = $this->params()->fromPost('submit');
if(!empty($submit))
{
if ($auth->hasIdentity())
{
return JsonModel(array('error'=>"您已登录,无需重复登录"));
}
else{
$account = new Account();
$status = $account->login(array(
'username'=>$this->params()->fromPost('username'),
'password'=>$this->params()->fromPost('password')
));
if(is_array($status))
{
return new JsonModel($status);
}
}
}
return;
}
$auth = new Auth;
$instance = $auth->getInstance();
if ($instance->hasIdentity())
{
view::Post($this,'您已经登陆过了,无需重复登陆','/');
return $this->ViewModel;
}
$submit = $this->params()->fromPost('submit');
if(!empty($submit))
{
$account = new Account();
$status = $account->login(array(
'username'=>$this->params()->fromPost('username'),
'password'=>$this->params()->fromPost('password')
));
if(isset($status['error']))
{
$viewModel = array('error' => view::Error($status['error']));
if(isset($status['place']))
{
array_push($viewModel,array("place"=>$status['place']));
}
return new ViewModel($viewModel);
}else{
if(isset($_GET['href']) && !preg_match("/http:\/\//",$_GET['href']) && $_GET['href'] != '/account/login')
{
$href = $_GET['href'];
}else{
$href = "/";
}
view::Post($this,"登陆成功!",$href);
return $this->ViewModel;
}
}
}//login
public function registerAction()
{
if($this->getRequest()->isXmlHttpRequest())
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$account = new Account();
$data = $account->getParam($this->_request);
$result = $account->register($data);
if(!empty($result))
{
$this->jsonexit($result);
return true;
}
$this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试'));
return;
}
$success = false;
$auth = new Auth;
$instance = $auth->getInstance();
if ($instance->hasIdentity())
{
view::Post($this,'您已经登陆过了,无需重复登陆','/');
return $this->ViewModel;
}
$submit = $this->params()->fromPost('submit');
if(!empty($submit))
{
$account = new Account();
$data = array(
'username' => $this->params()->fromPost('username'),
'password'=>$this->params()->fromPost('password'),
'confirm_password'=>$this->params()->fromPost('confirm_password'),
'email'=>$this->params()->fromPost('email'),
'realname'=>$this->params()->fromPost('realname')
);
$result = $account->register($data);
if(!empty($result))
{
if(isset($result['error']))
{
$this->ViewModel->setVariable('error',view::Error($result['error']));
$this->ViewModel->setVariable('data',$data);
if(isset($result['place']))
{
$this->ViewModel->setVariable('place',$result['place']);
}
return $this->ViewModel;
}
if(isset($result['success']))
{
view::Post($this,"注册成功!",'/');
return $this->ViewModel;
}
}else{
$this->ViewModel->setVariable('error','处理中出现问题');
$this->ViewModel->setVariable('data',$data);
return $this->ViewModel;
}
}//submit
}//用户注册
//登录状态
public function loginstatus()
{
}
public function logoutAction()
{
$auth = new Auth();
$result = $auth->clearIndentity();
Member::flushcookie();
view::Post($this,"您已经成功注销",'/');
return $this->ViewModel;
}
//找回密码
public function forgotpasswordAction()
{
$submit = $this->params()->fromPost('submit');
$captcha = new Captcha();
if(!empty($submit))
{
$email = $this->params()->fromPost('email');
$captchaword = $this->params()->fromPost('captcha');
if(!$captcha->isValid($captchaword))
{
$this->ViewModel->setVariable('error',view::Error("验证码错误"));
$this->ViewModel->setVariable('captcha', $captcha->setCaptcha());
return $this->ViewModel;
}
$account = new Account();
$status = $account->getMyPassword($email);
if(isset($status['error']) && !empty($status['error']))
{
$this->ViewModel->setVariable('captcha', $captcha->setCaptcha());
$this->ViewModel->setVariable('error',$status['error']);
return $this->ViewModel;
}else{
$this->ViewModel->setVariable('msg',"申请成功!请在您的邮箱中查看密码重置邮件");
return $this->ViewModel;
}
}else{
$this->ViewModel->setVariable('captcha', $captcha->setCaptcha());
return $this->ViewModel;
}
}
//重置密码
public function getpasswordAction()
{
$submit = $this->params()->fromPost('submit');
$salt = $this->params()->fromQuery('salt');
if(empty($salt))
{
$this->ViewModel->setVariable('msg',view::Msg("alert-danger","缺少密码重置密钥"));
return $this->ViewModel;
}
$this->ViewModel->setVariable('salt',$salt);
if(!empty($submit))
{
$data = array(
'username' => $this->params()->fromPost('username'),
'password' => $this->params()->fromPost('password'),
'confirm_password' => $this->params()->fromPost('confirm_password'),
'salt' => $salt
);
$account = new Account();
$Listener = new \Sookon\User\Listener\PwdListener();
$account->getEventManager()->attachAggregate($Listener);
$status = $account->resetPassword($data);
if(isset($status['error']) && !empty($status['error']))
{
$this->ViewModel->setVariable('username',$data['username']);
$this->ViewModel->setVariable('error',view::Error($status['error']));
return $this->ViewModel;
}else{
$this->ViewModel->setVariable('msg',view::Msg("alert-success","您的密码已经成功更改,<a href='/account/login'>请点击这里登陆</a>"));
return $this->ViewModel;
}
}
}//getpasswordAction()
public function captchaAction()
{
if($this->getRequest()->isXmlHttpRequest())
{
$this->ViewModel->setTerminal(true);
$captcha = new Captcha();
$url = $captcha->setCaptcha();
echo $url;
exit();
}else{
echo "bad request!";
exit();
}
}
}

View File

@ -12,7 +12,6 @@ use Zend\Mail\Transport\SmtpOptions;
class Mail
{
private $db; //传入PDO对象.
private $conf; //邮件设置
private $config; //站点设置
private $email_cfg;
@ -50,24 +49,23 @@ class Mail
private function loadconf()
{
$this->conf->name = $this->config->site_title;
$email_cfg = Config::get('email');
$this->email_cfg = $email_cfg->config;
}
private function smtp()
{
$this->transport = new SmtpTransport();
$this->email_cfg = $email_cfg = Config::get('email');
$options = new SmtpOptions(array(
'name' => $email_cfg->hostname,
'host' => $email_cfg->host,
'port' => $email_cfg->port, // Notice port change for TLS is 587
'connection_class' => $email_cfg->auth,
'name' => $this->email_cfg->hostname,
'host' => $this->email_cfg->host,
'port' => $this->email_cfg->port, // Notice port change for TLS is 587
'connection_class' => $this->email_cfg->auth,
'connection_config' => array(
'username' => $email_cfg->username,
'password' => $email_cfg->password,
'ssl' => $email_cfg->ssl,
'username' => $this->email_cfg->username,
'password' => $this->email_cfg->password,
'ssl' => $this->email_cfg->ssl,
),
));
@ -77,7 +75,7 @@ class Mail
//设置默认发件人
public function setDefaultForm()
{
$this->mail->setFrom($this->email_cfg->username,$this->conf->name);
$this->mail->setFrom($this->email_cfg->username,$this->email_cfg->name);
}
//加载模板

View File

@ -307,9 +307,10 @@ class Account implements EventManagerAwareInterface
$salt = md5($email.'---'.$row[$this->conf->field->uname]);
$sql = "UPDATE {$this->conf->table->member} SET salt='$salt' WHERE id={$row['id']}";
//view::Dump($sql);
$state = $this->db->exec($sql);
if($state<1)
if($state < 1)
{
return array('error'=>"处理中出现错误,请重试",'place'=>'email');
}