目录结构更新,增加composer支持
This commit is contained in:
@@ -26,7 +26,7 @@ class Addons extends Base {
|
||||
public function _initialize() {
|
||||
$mc = $this->getAddonsName();
|
||||
|
||||
$this->addon_path = ROOT_PATH . "/addons/{$mc}/";
|
||||
$this->addon_path = SENT_ADDON_PATH . "{$mc}/";
|
||||
if (is_file($this->addon_path . 'config.php')) {
|
||||
$this->config_file = $this->addon_path . 'config.php';
|
||||
}
|
||||
@@ -38,13 +38,13 @@ class Addons extends Base {
|
||||
$mc = $this->getAddonsName();
|
||||
$ac = input('ac', '', 'trim,strtolower');
|
||||
$parse_str = \think\Config::get('parse_str');
|
||||
$parse_str['__ADDONROOT__'] = ROOT_PATH . "/addons/{$mc}";
|
||||
$parse_str['__ADDONROOT__'] = SENT_ADDON_PATH . "{$mc}";
|
||||
\think\Config::set('parse_str', $parse_str);
|
||||
|
||||
$this->view->engine(
|
||||
array(
|
||||
'view_path' => "addons/" . $mc . "/view/",
|
||||
'replace' => array('__ADDONROOT__'=>ROOT_PATH . "/addons/{$mc}")
|
||||
'view_path' => SENT_ADDON_PATH . $mc . "/view/",
|
||||
'replace' => array('__ADDONROOT__'=>SENT_ADDON_PATH . "{$mc}")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\controller;
|
||||
use app\common\model\AuthGroup;
|
||||
use app\common\model\AuthRule;
|
||||
|
||||
class Admin extends Base {
|
||||
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
|
||||
if (!is_login() and !in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
if (!is_login() and !in_array($this->url_path, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
$this->redirect('admin/index/login');
|
||||
}
|
||||
|
||||
if (!in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
if (!in_array($this->url_path, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
|
||||
// 是否是超级管理员
|
||||
define('IS_ROOT', is_administrator());
|
||||
@@ -119,7 +112,7 @@ class Admin extends Base {
|
||||
|
||||
protected function setMenu() {
|
||||
$hover_url = $this->request->module() . '/' . $this->request->controller();
|
||||
$controller = $this->url;
|
||||
$controller = $this->url_path;
|
||||
$menu = array(
|
||||
'main' => array(),
|
||||
'child' => array(),
|
||||
@@ -218,4 +211,4 @@ class Admin extends Base {
|
||||
$this->assign('extend_menu', array('管理插件' => $menu));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
class Base extends \think\Controller {
|
||||
use think\Controller;
|
||||
|
||||
protected $url;
|
||||
protected $request;
|
||||
protected $module;
|
||||
protected $controller;
|
||||
protected $action;
|
||||
class Base extends Controller{
|
||||
|
||||
public function _initialize() {
|
||||
protected $url_path = ""; //当前完全访问路径
|
||||
|
||||
public function _initialize(){
|
||||
$this->url_path = strtolower($this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action());
|
||||
if (!is_file(APP_PATH . 'database.php') || !is_file(APP_PATH . 'install.lock')) {
|
||||
return $this->redirect('install/index/index');
|
||||
}
|
||||
@@ -28,8 +19,6 @@ class Base extends \think\Controller {
|
||||
cache('db_config_data', $config);
|
||||
}
|
||||
config($config);
|
||||
//获取request信息
|
||||
$this->requestInfo();
|
||||
}
|
||||
|
||||
public function execute($mc = null, $op = '', $ac = null) {
|
||||
@@ -110,34 +99,6 @@ class Base extends \think\Controller {
|
||||
$this->assign($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
* @param integer $id 验证码ID
|
||||
* @author 郭平平 <molong@tensent.cn>
|
||||
*/
|
||||
public function verify($id = 1) {
|
||||
$verify = new \org\Verify(array('length' => 4));
|
||||
$verify->entry($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
* @param integer $id 验证码ID
|
||||
* @return boolean 检测结果
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function checkVerify($code, $id = 1) {
|
||||
if ($code) {
|
||||
$verify = new \org\Verify();
|
||||
$result = $verify->check($code, $id);
|
||||
if (!$result) {
|
||||
return $this->error("验证码错误!", "");
|
||||
}
|
||||
} else {
|
||||
return $this->error("验证码为空!", "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 后台设置title
|
||||
* @description 设置后台页面的title
|
||||
@@ -149,29 +110,6 @@ class Base extends \think\Controller {
|
||||
$this->assign('meta_title', $title);
|
||||
}
|
||||
|
||||
//request信息
|
||||
protected function requestInfo() {
|
||||
$this->param = $this->request->param();
|
||||
defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module());
|
||||
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller());
|
||||
defined('ACTION_NAME') or define('ACTION_NAME', $this->request->action());
|
||||
defined('IS_POST') or define('IS_POST', $this->request->isPost());
|
||||
defined('IS_GET') or define('IS_GET', $this->request->isGet());
|
||||
$this->url = strtolower($this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action());
|
||||
$this->assign('request', $this->request);
|
||||
$this->assign('param', $this->param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个参数的数组形式
|
||||
*/
|
||||
protected function getArrayParam($param) {
|
||||
if (isset($this->param['id'])) {
|
||||
return array_unique((array) $this->param[$param]);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为手机访问
|
||||
@@ -214,4 +152,4 @@ class Base extends \think\Controller {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,125 +1,35 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
class Front extends Base {
|
||||
class Front extends Base{
|
||||
|
||||
public $wechat_oauth;
|
||||
public function _initialize() {
|
||||
public function _initialize(){
|
||||
parent::_initialize();
|
||||
|
||||
//判读是否为关闭网站
|
||||
if (\think\Config::get('web_site_close')) {
|
||||
header("Content-type:text/html;charset=utf-8");
|
||||
echo $this->fetch('common@default/public/close');exit();
|
||||
}
|
||||
|
||||
//设置SEO
|
||||
$this->setSeo();
|
||||
|
||||
$this->setHoverNav();
|
||||
|
||||
//主题设置
|
||||
//设置主题信息
|
||||
$this->setThemes();
|
||||
|
||||
//微信访问时
|
||||
// if ($this->isMobile() && $this->is_wechat()) {
|
||||
// if (!session('oauth')) {
|
||||
// $this->getOpentId();
|
||||
// }else{
|
||||
// $this->wechat_oauth = session('oauth');
|
||||
// $this->assign('oauth', session('oauth'));
|
||||
// }
|
||||
|
||||
// //微信用户直接使用微信登录
|
||||
// $this->WechatUser();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信用户登录
|
||||
*/
|
||||
protected function WechatUser(){
|
||||
if (!is_login()) {
|
||||
$openid = $this->wechat_oauth['openid'];
|
||||
//若系统内存在则直接登录,不存在不登录
|
||||
$result = model('User')->login($openid, '', 5);
|
||||
if ($result == -1) {
|
||||
$user = & load_wechat('User');
|
||||
$wechat_user = $user->getUserInfo($this->wechat_oauth['openid']);
|
||||
|
||||
$result = model('User')->register($openid, $openid, $openid, $openid.'@openid.com', true, array('openid'=>$openid,'nickname'=>$this->jsonName($wechat_user['nickname']),'headimgurl'=>$wechat_user['headimgurl']));
|
||||
}
|
||||
return $result;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* 过滤用户昵称里面的特殊字符
|
||||
+----------------------------------------------------------
|
||||
* @param string $str 待输出的用户昵称
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
protected function jsonName($str) {
|
||||
if($str){
|
||||
$return = '';
|
||||
$length = mb_strlen($str,'utf-8');
|
||||
for ($i=0; $i < $length; $i++) {
|
||||
$_tmpStr = mb_substr($str,$i,1,'utf-8');
|
||||
if(strlen($_tmpStr) >= 4){
|
||||
$return .= '';
|
||||
}else{
|
||||
$return .= $_tmpStr;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$return = 'wechat_'.time();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
protected function getOpentId(){
|
||||
$oauth = &load_wechat('Oauth');
|
||||
$user_oauth = $oauth->getOauthAccessToken();
|
||||
if ($user_oauth) {
|
||||
session('oauth',$user_oauth);
|
||||
}else{
|
||||
$uri = $oauth->getOauthRedirect('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
||||
header("Location:".$uri);
|
||||
}
|
||||
}
|
||||
|
||||
//当前栏目导航
|
||||
protected function setHoverNav() {
|
||||
//dump($_SERVER['PHP_SELF']);
|
||||
}
|
||||
|
||||
protected function setThemes() {
|
||||
//网站主题设置
|
||||
$themes['mobile'] = config('mobile_themes') ? config('mobile_themes') : 'mobile';
|
||||
$themes['pc'] = config('pc_themes') ? config('pc_themes') : 'default';
|
||||
$view_path = ($this->isMobile() && config('open_mobile_site') == '1') ? 'template/' . $themes['mobile'] . '/' : 'template/' . $themes['pc'] . '/';
|
||||
public function setThemes(){
|
||||
$theme = 'default';
|
||||
$module = $this->request->module();
|
||||
if (!in_array($module, array('index', 'install'))) {
|
||||
$view_path_pre = $module . '/';
|
||||
} else {
|
||||
$view_path_pre = '';
|
||||
if ($module == 'index') {
|
||||
$view_path = './template/' . $theme . '/' ;
|
||||
}else{
|
||||
$view_path = './template/' . $theme . '/' . $module . '/';
|
||||
}
|
||||
$this->view->config('view_path', $view_path . $view_path_pre)
|
||||
->config('tpl_replace_string',array(
|
||||
'__IMG__' => BASE_PATH . '/' . $view_path . 'static/images',
|
||||
'__JS__' => BASE_PATH . '/' . $view_path . 'static/js',
|
||||
'__CSS__' => BASE_PATH . '/' . $view_path . 'static/css',
|
||||
));
|
||||
|
||||
$tpl_replace = array(
|
||||
'__TPL__' => $view_path,
|
||||
'__CSS__' => $view_path . 'static/css/',
|
||||
'__JS__' => $view_path . 'static/js/',
|
||||
'__IMG__' => $view_path . 'static/images/',
|
||||
);
|
||||
$tpl_conf = array(
|
||||
'view_path' => $view_path,
|
||||
'tpl_replace_string' => $tpl_replace
|
||||
);
|
||||
$this->view->config($tpl_conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Attribute extends Base{
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected static function init(){
|
||||
self::afterInsert(function($data){
|
||||
if ($data['model_id']) {
|
||||
$name = db('Model')->where('id', $data['model_id'])->value('name');
|
||||
$db = new \com\Datatable();
|
||||
$attr = $data->toArray();
|
||||
$model_attr = array(
|
||||
'model_id' => $data['model_id'],
|
||||
'attr_id' => $data->id,
|
||||
'group_id' => 0,
|
||||
'is_add_table' => 1,
|
||||
'is_show' => $data['is_show'],
|
||||
'is_must' => $data['is_must'],
|
||||
'sort' => 0,
|
||||
);
|
||||
$attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
|
||||
return $db->columField(strtolower($name), $attr)->query();
|
||||
}
|
||||
});
|
||||
self::beforeUpdate(function($data){
|
||||
$attr = $data->toArray();
|
||||
$attr['action'] = 'CHANGE';
|
||||
$attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
|
||||
if ($attr['id']) {
|
||||
$name = db('Model')->where('id', $attr['model_id'])->value('name');
|
||||
$db = new \com\Datatable();
|
||||
return $db->columField(strtolower($name), $attr)->query();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function getTypeTextAttr($value, $data){
|
||||
$type = config('config_type_list');
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
|
||||
public function getFieldlist($map,$index='id'){
|
||||
$list = array();
|
||||
$row = db('Attribute')->field('*,remark as help,type,extra as "option",model_id')->where($map)->order('group_id asc, sort asc')->select();
|
||||
foreach ($row as $key => $value) {
|
||||
if (in_array($value['type'],array('checkbox','radio','select','bool'))) {
|
||||
$value['option'] = parse_field_attr($value['extra']);
|
||||
} elseif ($value['type'] == 'bind') {
|
||||
$extra = parse_field_bind($value['extra'], '', $value['model_id']);
|
||||
$option = array();
|
||||
foreach ($extra as $k => $v) {
|
||||
$option[$v['id']] = $v['title_show'];
|
||||
}
|
||||
$value['option'] = $option;
|
||||
}
|
||||
$list[$value['id']] = $value;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function del($id, $model_id){
|
||||
$map['id'] = $id;
|
||||
$info = $this->find($id);
|
||||
$tablename = db('Model')->where(array('id'=>$model_id))->value('name');
|
||||
|
||||
//先删除字段表内的数据
|
||||
$result = $this->where($map)->delete();
|
||||
if ($result) {
|
||||
$tablename = strtolower($tablename);
|
||||
//删除模型表中字段
|
||||
$db = new \com\Datatable();
|
||||
if (!$db->CheckField($tablename,$info['name'])) {
|
||||
return true;
|
||||
}
|
||||
$result = $db->delField($tablename,$info['name'])->query();
|
||||
if ($result) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,8 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 模型基类
|
||||
*/
|
||||
class Base extends \think\Model{
|
||||
use think\Model;
|
||||
|
||||
protected $param;
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'cover_id' => 'integer',
|
||||
);
|
||||
class Base extends Model {
|
||||
|
||||
public function initialize(){
|
||||
parent::initialize();
|
||||
$this->param = \think\Request::instance()->param();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据修改
|
||||
* @return [bool] [是否成功]
|
||||
*/
|
||||
public function change(){
|
||||
$data = \think\Request::instance()->post();
|
||||
if (isset($data['id']) && $data['id']) {
|
||||
return $this->save($data, array('id'=>$data['id']));
|
||||
}else{
|
||||
return $this->save($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Channel extends Base{
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected $auto = array('update_time', 'status'=>1);
|
||||
protected $insert = array('create_time');
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class Config extends Base{
|
||||
}
|
||||
|
||||
protected function getList($type){
|
||||
$path = ROOT_PATH . 'template/';
|
||||
$path = './template/';
|
||||
$file = opendir($path);
|
||||
while (false !== ($filename = readdir($file))) {
|
||||
if (!in_array($filename, array('.', '..'))) {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class MemberExtend extends Base{
|
||||
|
||||
protected $type = array(
|
||||
'uid' => 'integer',
|
||||
);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 菜单模型类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Menu extends \app\common\model\Base {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public function getAuthNodes($type = 'admin'){
|
||||
$map['type'] = $type;
|
||||
$rows = $this->db()->field('id,pid,group,title,url')->where($map)->order('id asc')->select();
|
||||
foreach ($rows as $key => $value) {
|
||||
$data[$value['id']] = $value;
|
||||
}
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value['pid'] > 0) {
|
||||
$value['group'] = $data[$value['pid']]['title'] . '管理';
|
||||
$list[] = $value;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class User extends Base{
|
||||
|
||||
protected $name = "Member";
|
||||
protected $createTime = 'reg_time';
|
||||
protected $updateTime = 'last_login_time';
|
||||
|
||||
protected $type = array(
|
||||
'uid' => 'integer',
|
||||
'reg_time' => 'integer'
|
||||
);
|
||||
protected $insert = array('status', 'reg_time');
|
||||
protected $update = array();
|
||||
|
||||
public $editfield = array(
|
||||
array('name'=>'uid','type'=>'hidden'),
|
||||
array('name'=>'username','title'=>'用户名','type'=>'readonly','help'=>''),
|
||||
array('name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''),
|
||||
array('name'=>'password','title'=>'密码','type'=>'password','help'=>'为空时则不修改'),
|
||||
array('name'=>'sex','title'=>'性别','type'=>'select','option'=>array('0'=>'保密','1'=>'男','2'=>'女'),'help'=>''),
|
||||
array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'),
|
||||
array('name'=>'qq','title'=>'QQ','type'=>'text','help'=>''),
|
||||
array('name'=>'score','title'=>'用户积分','type'=>'text','help'=>''),
|
||||
array('name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''),
|
||||
array('name'=>'status','title'=>'状态','type'=>'select','option'=>array('0'=>'禁用','1'=>'启用'),'help'=>''),
|
||||
);
|
||||
|
||||
public $addfield = array(
|
||||
array('name'=>'username','title'=>'用户名','type'=>'text','help'=>'用户名会作为默认的昵称'),
|
||||
array('name'=>'password','title'=>'密码','type'=>'password','help'=>'用户密码不能少于6位'),
|
||||
array('name'=>'repassword','title'=>'确认密码','type'=>'password','help'=>'确认密码'),
|
||||
array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'),
|
||||
);
|
||||
|
||||
public $useredit = array(
|
||||
array('name'=>'uid','type'=>'hidden'),
|
||||
array('name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''),
|
||||
array('name'=>'sex','title'=>'性别','type'=>'select','option'=>array('0'=>'保密','1'=>'男','2'=>'女'),'help'=>''),
|
||||
array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'),
|
||||
array('name'=>'mobile','title'=>'联系电话','type'=>'text','help'=>''),
|
||||
array('name'=>'qq','title'=>'QQ','type'=>'text','help'=>''),
|
||||
array('name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''),
|
||||
);
|
||||
|
||||
public $userextend = array(
|
||||
array('name'=>'company','title'=>'单位名称','type'=>'text','help'=>''),
|
||||
array('name'=>'company_addr','title'=>'单位地址','type'=>'text','help'=>''),
|
||||
array('name'=>'company_contact','title'=>'单位联系人','type'=>'text','help'=>''),
|
||||
array('name'=>'company_zip','title'=>'单位邮编','type'=>'text','help'=>''),
|
||||
array('name'=>'company_depart','title'=>'所属部门','type'=>'text','help'=>''),
|
||||
array('name'=>'company_post','title'=>'所属职务','type'=>'text','help'=>''),
|
||||
array('name'=>'company_type','title'=>'单位类型','type'=>'select', 'option'=>'', 'help'=>''),
|
||||
);
|
||||
|
||||
protected function setStatusAttr($value){
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected function setPasswordAttr($value, $data){
|
||||
return md5($value.$data['salt']);
|
||||
}
|
||||
|
||||
protected function getGroupListAttr($value, $data){
|
||||
$sql = db('AuthGroupAccess')->where('uid', $data['uid'])->fetchSql(true)->column('group_id');
|
||||
return db('AuthGroup')->where('id in ('.$sql.')')->column('title', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录模型
|
||||
* @param string $username [description]
|
||||
* @param string $password [description]
|
||||
* @param integer $type 登录类型,1为用户名登录2为邮箱登录3为手机登录4为用户ID登录5为微信登录
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function login($username = '', $password = '', $type = 1) {
|
||||
$map = array();
|
||||
if (\think\Validate::is($username, 'email')) {
|
||||
$type = 2;
|
||||
} elseif (preg_match("/^1[34578]{1}\d{9}$/", $username)) {
|
||||
$type = 3;
|
||||
}
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$map['username'] = $username;
|
||||
break;
|
||||
case 2:
|
||||
$map['email'] = $username;
|
||||
break;
|
||||
case 3:
|
||||
$map['mobile'] = $username;
|
||||
break;
|
||||
case 4:
|
||||
$map['uid'] = $username;
|
||||
break;
|
||||
case 5:
|
||||
$map['openid'] = $username;
|
||||
break;
|
||||
default:
|
||||
return 0; //参数错误
|
||||
}
|
||||
if (!$username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->where($map)->find();
|
||||
if (isset($user['uid']) && $user['uid'] && $user['status']) {
|
||||
if ($type == 3) {
|
||||
//手机验证手机动态密码
|
||||
if ($password == session('mobile_login_code')) {
|
||||
$this->autoLogin($user); //更新用户登录信息
|
||||
return $user['uid'];
|
||||
}else{
|
||||
return -5;
|
||||
}
|
||||
} elseif ($type == 5) {
|
||||
$this->autoLogin($user); //更新用户登录信息
|
||||
return $user['uid'];
|
||||
} else {
|
||||
/* 验证用户密码 */
|
||||
if (md5($password . $user['salt']) === $user['password']) {
|
||||
$this->autoLogin($user); //更新用户登录信息
|
||||
return $user['uid']; //登录成功,返回用户ID
|
||||
} else {
|
||||
return -2; //密码错误
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($type == 3 && preg_match("/^1[34578]{1}\d{9}$/", $username) && $password == session('mobile_login_code')) {
|
||||
$data = array(
|
||||
'username' => $username,
|
||||
'mobile' => $username,
|
||||
'salt' => rand_string(6),
|
||||
'password' => $password,
|
||||
);
|
||||
$result = $this->save($data);
|
||||
if ($result) {
|
||||
$this->autoLogin($this->data); //更新用户登录信息
|
||||
}
|
||||
return $this->data['uid'];
|
||||
} else {
|
||||
return -1; //用户不存在或被禁用
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
* @param integer $user 用户信息数组
|
||||
*/
|
||||
function register($username, $password, $repassword, $email, $isautologin = true, $other = array()){
|
||||
$data['username'] = $username;
|
||||
$data['salt'] = rand_string(6);
|
||||
$data['password'] = $password;
|
||||
$data['repassword'] = $repassword;
|
||||
$data['email'] = $email;
|
||||
if (!empty($other)) {
|
||||
$data = array_merge($data, $other);
|
||||
}
|
||||
$result = $this->validate(true)->save($data);
|
||||
if ($result) {
|
||||
$data['uid'] = $this->data['uid'];
|
||||
//$this->extend()->save($data);
|
||||
if ($isautologin) {
|
||||
$this->autoLogin($this->data);
|
||||
}
|
||||
return $result;
|
||||
}else{
|
||||
if (!$this->getError()) {
|
||||
$this->error = "注册失败!";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动登录用户
|
||||
* @param integer $user 用户信息数组
|
||||
*/
|
||||
private function autoLogin($user){
|
||||
/* 更新登录信息 */
|
||||
$data = array(
|
||||
'uid' => $user['uid'],
|
||||
'login' => array('exp', '`login`+1'),
|
||||
'last_login_time' => time(),
|
||||
'last_login_ip' => get_client_ip(1),
|
||||
);
|
||||
$this->where(array('uid'=>$user['uid']))->update($data);
|
||||
$user = $this->where(array('uid'=>$user['uid']))->find();
|
||||
|
||||
/* 记录登录SESSION和COOKIES */
|
||||
$auth = array(
|
||||
'uid' => $user['uid'],
|
||||
'username' => $user['username'],
|
||||
'last_login_time' => $user['last_login_time'],
|
||||
);
|
||||
|
||||
session('user_auth', $auth);
|
||||
session('user_auth_sign', data_auth_sign($auth));
|
||||
}
|
||||
|
||||
public function logout(){
|
||||
session('user_auth', null);
|
||||
session('user_auth_sign', null);
|
||||
}
|
||||
|
||||
public function getInfo($uid){
|
||||
$data = $this->where(array('uid'=>$uid))->find();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户资料
|
||||
*/
|
||||
public function editUser($data, $ischangepwd = false){
|
||||
if ($data['uid']) {
|
||||
if (!$ischangepwd || ($ischangepwd && $data['password'] == '')) {
|
||||
unset($data['salt']);
|
||||
unset($data['password']);
|
||||
}else{
|
||||
$data['salt'] = rand_string(6);
|
||||
}
|
||||
$result = $this->validate('member.edit')->save($data, array('uid'=>$data['uid']));
|
||||
if ($result) {
|
||||
return $this->extend->save($data, array('uid'=>$data['uid']));
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
$this->error = "非法操作!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function editpw($data, $is_reset = false){
|
||||
$uid = $is_reset ? $data['uid'] : session('user_auth.uid');
|
||||
if (!$is_reset) {
|
||||
//后台修改用户时可修改用户密码时设置为true
|
||||
$this->checkPassword($uid,$data['oldpassword']);
|
||||
|
||||
$validate = $this->validate('member.password');
|
||||
if (false === $validate) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$data['salt'] = rand_string(6);
|
||||
|
||||
return $this->save($data, array('uid'=>$uid));
|
||||
}
|
||||
|
||||
protected function checkPassword($uid,$password){
|
||||
if (!$uid || !$password) {
|
||||
$this->error = '原始用户UID和密码不能为空';
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->where(array('uid'=>$uid))->find();
|
||||
if (md5($password.$user['salt']) === $user['password']) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = '原始密码错误!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function extend(){
|
||||
return $this->hasOne('MemberExtend', 'uid');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user