IndexController.php
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;
use cmf\controller\HomeBaseController;
use think\Db;
use EasyWeChat\Foundation\Application;
class IndexController extends HomeBaseController
{
public function callback(){
$config = [];
$app = new Application($config);
$oauth = $app->oauth;
$user = $oauth->user();
$wechat_user = $user->toArray();
//todo $wechat_user与数据库对比
session('wechat_user',$wechat_user);
$target_url=session('target_url');
$targetUrl = empty($target_url) ? '/' : $target_url;
header('location:'. $targetUrl);
}
/**
* 前台用户首页(公开)
*/
public function index()
{
$id = $this->request->param("id", 0, "intval");
$userQuery = Db::name("User");
$user = $userQuery->where('id',$id)->find();
if (empty($user)) {
session('user',null);
$this->error("查无此人!");
}
$this->assign($user);
return $this->fetch(":index");
}
/**
* 前台ajax 判断用户登录状态接口
*/
function isLogin()
{
if (cmf_is_user_login()) {
$this->success("用户已登录",null,['user'=>cmf_get_current_user()]);
} else {
$this->error("此用户未登录!");
}
}
/**
* 退出登录
*/
public function logout()
{
session("user", null);//只有前台用户退出
return redirect($this->request->root() . "/");
}
}