1、修复bug
2、后台栏目分模型划分 3、前台增加微信开发用户登录功能
This commit is contained in:
@@ -30,25 +30,23 @@ class Addons extends Base {
|
||||
if (is_file($this->addon_path . 'config.php')) {
|
||||
$this->config_file = $this->addon_path . 'config.php';
|
||||
}
|
||||
|
||||
$this->template();
|
||||
}
|
||||
|
||||
public function template($template) {
|
||||
public function template() {
|
||||
$mc = $this->getAddonsName();
|
||||
$ac = input('ac', '', 'trim,strtolower');
|
||||
$parse_str = \think\Config::get('parse_str');
|
||||
$parse_str['__ADDONROOT__'] = ROOT_PATH . "/addons/{$mc}";
|
||||
\think\Config::set('parse_str', $parse_str);
|
||||
|
||||
if ($template) {
|
||||
$template = $template;
|
||||
} else {
|
||||
$template = $mc . "/" . $ac;
|
||||
}
|
||||
|
||||
$this->view->engine(
|
||||
array('view_path' => "addons/" . $mc . "/view/")
|
||||
array(
|
||||
'view_path' => "addons/" . $mc . "/view/",
|
||||
'replace' => array('__ADDONROOT__'=>ROOT_PATH . "/addons/{$mc}")
|
||||
)
|
||||
);
|
||||
echo $this->fetch($template);
|
||||
}
|
||||
|
||||
final public function getAddonsName() {
|
||||
|
||||
@@ -208,7 +208,7 @@ class Admin extends Base {
|
||||
$menu = array();
|
||||
foreach ($list as $key => $value) {
|
||||
$class = "\\addons\\" . strtolower($value['name']) . "\\controller\\Admin";
|
||||
if (is_file(ROOT_PATH . $class . ".php")) {
|
||||
if (is_file(ROOT_PATH .'/addons/' . strtolower($value['name']) . "/controller/Admin.php")) {
|
||||
$action = get_class_methods($class);
|
||||
$value['url'] = "admin/addons/execute?mc=" . strtolower($value['name']) . "&ac=" . $action[0];
|
||||
$menu[$key] = $value;
|
||||
|
||||
@@ -43,7 +43,8 @@ class Base extends \think\Controller {
|
||||
$ops = ucwords($op);
|
||||
$class = "\\addons\\{$mc}\\controller\\{$ops}";
|
||||
$addons = new $class;
|
||||
$addons->$ac();
|
||||
|
||||
return $addons->$ac();
|
||||
} else {
|
||||
$this->error('没有指定插件名称,控制器或操作!');
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace app\common\controller;
|
||||
|
||||
class Fornt extends Base {
|
||||
|
||||
public $wechat_oauth;
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
|
||||
@@ -27,6 +28,75 @@ class Fornt extends Base {
|
||||
|
||||
//主题设置
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
//当前栏目导航
|
||||
|
||||
@@ -15,7 +15,7 @@ class User extends Fornt {
|
||||
parent::_initialize();
|
||||
|
||||
if (!is_login() and !in_array($this->url, array('user/login/index', 'user/index/verify'))) {
|
||||
$this->redirect('user/login/index');exit();
|
||||
return $this->redirect('user/login/index');
|
||||
} elseif (is_login()) {
|
||||
$user = model('User')->getInfo(session('user_auth.uid'));
|
||||
// if (!$this->checkProfile($user) && $this->url !== 'user/profile/index') {
|
||||
@@ -24,8 +24,17 @@ class User extends Fornt {
|
||||
$this->assign('user', $user);
|
||||
|
||||
//设置会员中心菜单
|
||||
$this->setMenu();
|
||||
//$this->setMenu();
|
||||
}
|
||||
|
||||
if ($this->is_wechat() && !session('wechat_user')) {
|
||||
$user = & load_wechat('User');
|
||||
$wechat_user = $user->getUserInfo($this->wechat_oauth['openid']);
|
||||
//更新用户信息
|
||||
session('wechat_user', $wechat_user);
|
||||
}
|
||||
|
||||
$this->assign('wechat_user', session('wechat_user'));
|
||||
}
|
||||
|
||||
protected function setMenu() {
|
||||
|
||||
Reference in New Issue
Block a user