修改三江源数据门户的用户模块

This commit is contained in:
Li Jianxuan 2014-01-24 02:33:21 +00:00
parent 4cd7966f1b
commit c527de9207
11 changed files with 1102 additions and 1112 deletions

File diff suppressed because it is too large Load Diff

View File

@ -53,13 +53,13 @@
<div class="control-group ">
<label class="control-label">工作单位</label>
<div class="controls">
<input type="text" name="unit" value="<?php echo empty($this->info['unit']) ? "":$this->info['unit']; ?>" class="span8" />
<input type="text" name="unit" value="<?php echo empty($this->info['unit']) ? "":$this->info['unit']; ?>" class="input-block-level" />
</div>
</div>
<div class="control-group ">
<label class="control-label">联系地址</label>
<div class="controls">
<input type="text" name="address" value="<?php echo empty($this->info['address']) ? "":$this->info['address']; ?>" class="span8" />
<input type="text" name="address" value="<?php echo empty($this->info['address']) ? "":$this->info['address']; ?>" class="input-block-level" />
</div>
</div>
<div class="control-group ">
@ -107,13 +107,13 @@
<div class="control-group ">
<label class="control-label">项目名称</label>
<div class="controls">
<input type="text" name="project_title" value="<?php echo empty($this->info['project_title']) ? "":$this->info['project_title']; ?>" class="span8" />
<input type="text" name="project_title" value="<?php echo empty($this->info['project_title']) ? "":$this->info['project_title']; ?>" class="input-block-level" />
</div>
</div>
<div class="control-group ">
<label class="control-label">项目简介</label>
<div class="controls">
<textarea name="project" class="span8"><?php echo empty($this->info['project']) ? "":$this->info['project']; ?></textarea>
<textarea name="project" class="input-block-level"><?php echo empty($this->info['project']) ? "":$this->info['project']; ?></textarea>
</div>
</div>
<div class="form-actions">

View File

@ -1,24 +1,55 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('用户登录');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/register.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/account/fetchpwd">找回密码</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<?php if (!empty($this->messages)) : ?>
<div id="message">
<?php
foreach ($this->messages as $info)echo $info;
?>
</div>
<?php endif; ?>
<?php if ($this->form) : ?>
<div id="info">
<?php echo $this->form;?>
</div>
<?php endif; ?>
<div id="tool">
<a href="/account/login">登录 </a> <a href="/account/register">注册新用户</a>
</div>
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('用户登录');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/register.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/account/fetchpwd">找回密码</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row-fluid">
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<form method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="email">E-mail</label>
<div class="controls">
<input id="email" type="text" value="" name="email" />
<span class="help-block">请输入注册时填写的Email地址</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="captcha">验证码</label>
<div class="controls">
<input id="captcha" type="text" value="" name="captcha" />
<img id="captcha_img" src="<?php echo $this->captcha ?>" style="cursor:pointer" />
<a href="javascript:void(0);" onclick="changecaptcha()">看不清?</a>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="hidden" name="submit" value="1" />
<?php if(!empty($this->href)){?>
<input type="hidden" name="href" value="<?= $this->href ?>" />
<?php }?>
<button type="submit" class="btn">提交</button>
<a href="/account/login">登录 </a> <a href="/account/register">注册新用户</a>
</div>
</div>
</form>
</div>
<script>
$('#captcha_img').click(function(e) {
changecaptcha();
});
function changecaptcha(){
$.ajax({
url:"/account/captcha",
data:"<?= time() ?>",
success: function(src){
document.getElementById('captcha_img').src = src;
}
});
}
</script>

View File

@ -6,21 +6,6 @@
$this->breadcrumb('<a href="/account/login">用户登录</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<style>
.login_box {
max-width: 300px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
</style>
<div class="row-fluid">
<form class="form-horizontal" method="post">
<?php if(empty($this->error)) { ?>
@ -28,9 +13,7 @@
请输入用户名和密码登录
</div>
<? }else{ ?>
<div class="alert alert-error alert-login">
<?= $this->error ?>
</div>
<?= $this->error ?>
<?php } ?>
<div class="control-group">
<label class="control-label" for="username">用户名</label>
@ -64,9 +47,6 @@
</div>
</div>
</form>
<hr />
<h5>其它账号登录</h5>
<a href="/account/oauth2login/type/escience">中国科技网通行证</a>
</div>
<script>
$('#captcha_img').click(function(e) {

View File

@ -1,19 +1,88 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('用户注册');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/register.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/account/register">用户注册</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row-fluit">
<div class="span12">
<img src="/images/pass_login1.gif" />&nbsp;确认服务条款&nbsp;&nbsp;
<img src="/images/pass_pic_arrowhead_2.gif" />&nbsp;&nbsp;
<img src="/images/pass_login2.gif" />&nbsp;填写基本信息&nbsp;&nbsp;
<img src="/images/pass_pic_arrowhead_2.gif" />&nbsp;&nbsp;
<img src="/images/pass_login3.gif" />&nbsp;注册完成
<?php echo $this->form;?>
</div>
</div>
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('用户注册');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/register.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/account/register">用户注册</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row-fluit">
<form class="form-horizontal" method="post" id="register">
<?php if(empty($this->error)) { ?>
<div class="alert alert-info alert-login">
请输入您的基本信息进行注册
</div>
<? }else{ ?>
<?= $this->error ?>
<?php } ?>
<div class="control-group">
<label class="control-label" for="username">用户名</label>
<div class="controls">
<input id="username" type="text" value="<?= isset($this->data['username']) ? $this->data['username']:"" ?>" name="username" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">密码</label>
<div class="controls">
<input id="password" type="password" value="" name="password" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="confirm_password">确认密码</label>
<div class="controls">
<input id="confirm_password" type="password" value="" name="confirm_password" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">E-Mail</label>
<div class="controls">
<input id="email" type="text" value="<?= isset($this->data['email']) ? $this->data['email']:"" ?>" name="email" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="realname">真实姓名</label>
<div class="controls">
<input id="realname" type="text" value="<?= isset($this->data['realname']) ? $this->data['realname']:"" ?>" name="realname" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="phone">电话</label>
<div class="controls">
<input id="phone" type="text" value="<?= isset($this->data['phone']) ? $this->data['phone']:"" ?>" name="phone" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="unit">单位</label>
<div class="controls">
<input id="unit" type="text" value="<?= isset($this->data['unit']) ? $this->data['unit']:"" ?>" name="unit" class="input-block-level" />
</div>
</div>
<div class="form-actions">
<input type="hidden" name="submit" value="1" />
<?php if(!empty($this->href)){?>
<input type="hidden" name="href" value="<?= $this->href ?>" />
<?php }?>
<button type="submit" class="btn btn-primary">提交</button>
<a href="/account/fetchpwd">忘记密码?</a>
<a href="/account/login">登陆</a>
</div>
</form>
</div>
<?php if(!empty($this->place)){ ?>
<script>
var input = $("#register input[name=<?= $this->place ?>]");
input.parent('div').parent('div.control-group').addClass('error');
input.focus();
input.blur(function(e){
if(input.val() != '')
{
input.parent('div').parent('div.control-group').removeClass('error');
}
});
</script>
<?php } ?>

View File

@ -0,0 +1,58 @@
<?php
namespace Helpers;
class Captcha extends \Zend_Controller_Plugin_Abstract
{
public $captcha;
private $sessionName = "captcha";
private $imgDir = "images/captcha";
function __construct($db = NULL)
{
$this->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;
}
}
}

View File

@ -1,372 +1,390 @@
<?php
namespace Users;
use \Helpers\View as view;
use \Helpers\dbh as dbh;
use \Users\Member;
use \Mail\Mail;
use \Users\Listener\AccountListener;
use \Users\Listener\EditListener;
use \Users\Listener\PwdListener;
class Account extends \Zend_Controller_Plugin_Abstract
{
public $memberTable = "users";
public $FieldIndex = "id";
public $FieldUsername = "username";
public $FieldPasword = "password";
public $FieldLastlogin = "ts_last_login";
public $FieldEmail = "email";
public $FieldLastloginIp = "last_login_ip";
public $GravatarEmailField = "gravatar_email";
public $FieldRealname = "realname";
public $RoleMember = "member";
private $db;
protected $events = NULL; //事件
/*
需要挂载的事件分别放在不同的listener中将各种操作进行模块化细分
*/
function __construct($initializingListener = TRUE,$db = NULL)
{
if(empty($db))
{
$this->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;
}
<?php
namespace Users;
use \Helpers\View as view;
use \Helpers\dbh as dbh;
use \Users\Member;
use \Mail\Mail;
use \Users\Listener\AccountListener;
use \Users\Listener\EditListener;
use \Users\Listener\PwdListener;
class Account extends \Zend_Controller_Plugin_Abstract
{
public $memberTable = "users";
public $FieldIndex = "id";
public $FieldUsername = "username";
public $FieldPasword = "password";
public $FieldLastlogin = "ts_last_login";
public $FieldEmail = "email";
public $FieldLastloginIp = "last_login_ip";
public $GravatarEmailField = "gravatar_email";
public $FieldRealname = "realname";
public $RoleMember = "member";
public $getPwdEmailTemplate = "users-changepassword"; //找回密码的邮件模板名称
public $PwdChangedEmailTemplate = "users-password-changed"; //密码修改后的邮件模板
private $db;
protected $events = NULL; //事件
private $config;
/*
需要挂载的事件分别放在不同的listener中将各种操作进行模块化细分
*/
function __construct($initializingListener = TRUE,$db = NULL)
{
if(empty($db))
{
$this->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;
}
}

View File

@ -1,11 +1,11 @@
<?php
namespace \Users;
namespace Users;
class Member
{
var $ck='DCC3ER4T8L2EFX94OPDF';
var $db; //传入PDO对象
var $mid; //会员ID
public $ck='DCC3ER4T8L2EFX94OPDF';
public $db; //传入PDO对象
public $mid; //会员ID
public $scr; //cookie 安全码 $_COOKIE['scr']
public $user;//cookie User $_COOKIE['user']

View File

@ -45,9 +45,9 @@ class LoginOperate implements \Users\Event\LoginEvent
if(!empty($data['username']))
{
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username']))
if(mb_strlen($data['username'])<2)
{
return array('error'=>"用户名应当以字母开头由字母数字和下划线组成并且长度在5到25个字符之间",'place'=>'username');
return array('error'=>"用户名长度应该大于两个字符",'place'=>'username');
}
}
@ -106,6 +106,10 @@ class LoginOperate implements \Users\Event\LoginEvent
}//loginSuccess
//检查token表记录
public function checkOAuthToken()
{
}
}

View File

@ -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']))

View File

@ -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'=>'您的用户名已经注册过账号,您是否<a href="/account/forgotpassword">忘记了密码?</a>','place'=>'username');
return array('error'=>'您的用户名已经注册过账号,您是否<a href="/account/fetchpwd">忘记了密码?</a>','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 .= '<p style="width:100%;overflow:hidden;"><img src="http://www.msgfm.com'.$this->config->upload->urlbase.$thumb[0]['thumb'][400]['url'].'" height="100" style="float:left;margin-right:10px;" />'.$v['title']. ' / ' .$v['realname'].'<br />'.$text.'<br /><a href="http://www.msgfm.com/voice/'.$v['id'].'.html">查看播放</a></p>';
}
}
return $content;
}//getMailContent();