db = \Zend_Registry::get('db'); }else{ $this->db = $db; } $this->config = \Zend_Registry::get('config'); } public function checkParam(\Zend_EventManager_Event $e){ $data = $e->getParam('data'); if(!is_array($data)) { return "参数错误"; } if(empty($data['username'])) { return array('error'=>"请输入用户名",'place'=>'username'); } if(!empty($data['username'])) { if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username'])) { return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username'); } } if(empty($data['password'])) { return array('error'=>"请输入密码",'place'=>'password'); } $sql = "SELECT id,{$this->FieldPasword} FROM {$this->tbl_member} WHERE {$this->FieldUsername}=?"; $sth = $this->db->prepare($sql); $rs = $sth->execute(array($data[$this->FieldUsername])); $row = $sth->fetch(); if(isset($row['id']) && !empty($row['id'])) { if(strlen($row[$this->FieldPasword]) !== 32) { return array('error'=>"您的密码或因安全原因或其他问题已经被重置,请先重置密码再登陆",'place'=>'password'); } if($row[$this->FieldPasword] !== md5($data['password'])) { return array('error'=>"密码错误",'place'=>'password'); } return true; }else{ return array('error'=>"用户不存在",'place'=>'username'); } }//checkParam public function updateStatus(\Zend_EventManager_Event $e){ $id = (int)$e->getParam('id'); if(!is_numeric($id)) { return false; } $update = array( $this->FieldLastlogin => date("Y-m-d H:i:s"), $this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"] ); $dbh = new dbh(); @$statusUpdate = $dbh->update($this->tbl_member,$update," id=$id "); return true; }//loginSuccess public function createAvatar(\Zend_EventManager_Event $e){ $email = $e->getParam('email'); $avatar = new Gravatar(); return $avatar->Get($email); }//loginSuccess }