代码更新

This commit is contained in:
2019-07-01 16:13:59 +08:00
parent d141eb7c24
commit 86c24dc40e
30 changed files with 13731 additions and 94 deletions

View File

@@ -1,9 +1,102 @@
<?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\model;
use think\Model;
class Config extends Model
{
/**
* 设置模型
*/
class Config extends Model{
protected $type = array(
'id' => 'integer',
);
protected $auto = array('name', 'update_time', 'status'=>1);
protected $insert = array('create_time');
protected function setNameAttr($value){
return strtolower($value);
}
protected function getTypeTextAttr($value, $data){
$type = config('config_type_list');
$type_text = explode(',', $type[$data['type']]);
return $type_text[0];
}
public function lists(){
$map = array('status' => 1);
$res = $this->where($map)->field('type,name,value')->select();
$config = array();
foreach ($res->toArray() as $value) {
$config[$value['name']] = $this->parse($value['type'], $value['value']);
}
return $config;
}
/**
* 根据配置类型解析配置
* @param integer $type 配置类型
* @param string $value 配置值
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
private function parse($type, $value){
switch ($type) {
case 'textarea': //解析数组
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
if(strpos($value,':')){
$value = array();
foreach ($array as $val) {
$list = explode(':', $val);
if(isset($list[2])){
$value[$list[0]] = $list[1].','.$list[2];
}else{
$value[$list[0]] = $list[1];
}
}
}else{
$value = $array;
}
break;
}
return $value;
}
public function getThemesList(){
$files = array();
$files['pc'] = $this->getList('pc');
$files['mobile'] = $this->getList('mobile');
return $files;
}
protected function getList($type){
$path = './template/';
$file = opendir($path);
while (false !== ($filename = readdir($file))) {
if (!in_array($filename, array('.', '..'))) {
$files = $path . $filename . '/info.php';
if (is_file($files)) {
$info = include($files);
if (isset($info['type']) && $info['type'] == $type) {
$info['id'] = $filename;
$info['img'] = '/template/' . $filename . '/' . $info['img'];
$list[] = $info;
}else{
continue;
}
}
}
}
return isset($list) ? $list : array();
}
}

View File

@@ -1,9 +1,125 @@
<?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\model;
use think\Model;
class Member extends Model
{
/**
* @title: 用户模型
*/
class Member extends Model {
protected $pk = 'uid';
protected $createTime = 'reg_time';
protected $updateTime = 'last_login_time';
protected $insert = ['reg_ip'];
protected $type = [
'uid' => 'integer',
'reg_time' => 'integer',
];
public $loginVisible = array('uid', 'username', 'nickname', 'access_token'); //用户登录成功返回的字段
protected function setPasswordAttr($value) {
$salt = rand_string(6);
$this->set('salt', $salt);
return md5($value . $salt);
}
protected function setRegIpAttr($value) {
return get_client_ip(1);
}
protected function getAccessTokenAttr($value, $data) {
return authcode($data['uid'] . '|' . $data['username'] . '|' . $data['password'], 'ENCODE');
}
/**
* @title 用户登录
* param username:用户名、手机号码、邮箱 password:密码、手机验证码、开源类型 type:登录类型(账号密码登录、手机号码+验证码登录、开源账号登录)
*/
public function login($username, $password, $type = 1) {
$map = array();
if (preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $username)) {
$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;
default:
return false; //参数错误
}
if (!$username) {
return false;
}
$user = $this->where($map)->find();
if (isset($user['uid']) && $user['uid'] && $user['status']) {
/* 验证用户密码 */
if (md5($password . $user['salt']) === $user['password']) {
/* 更新登录信息 */
(new MemberLog())->record($user);
return $user->append(array('access_token'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
} else {
$this->error = "密码错误";
return false; //密码错误
}
} else {
$this->error = "用户不存在或被禁用";
return false;
}
}
/**
* @title: 注册
*/
public function register($data) {
$result = self::create($data);
if (false !== $result) {
$user = $this->where('uid', $result->uid)->find();
} else {
$this->error = "注册失败!";
return false;
}
/* 更新登录信息 */
(new MemberLog())->record($user);
return $user->append(array('access_token'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
}
/**
* @title: 获取用户列表
*/
public function getUserList() {
}
/**
* @title: 获取用户信息
*/
public function getInfo($uid) {
}
public function socialite() {
return $this->hasMany('MemberSocialite', 'uid', 'uid');
}
}

29
app/model/MemberLog.php Normal file
View File

@@ -0,0 +1,29 @@
<?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\model;
use think\Model;
/**
* @title: 用户日志模型
*/
class MemberLog extends Model {
public function record($user){
/* 更新登录信息 */
$data = array(
'uid' => $user['uid'],
'login' => array('inc', '1'),
'last_login_time' => time(),
'last_login_ip' => get_client_ip(1),
);
Member::where(array('uid'=>$user['uid']))->update($data);
}
}

View File

@@ -0,0 +1,59 @@
<?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 MemberSocialite extends Base{
protected $type = array(
'uid' => 'integer',
);
public function register(){
if ($socialite->where('openid', $data['info']['openid'])->value('id')) {
$this->error = "请勿重复注册!";
return false;
} else {
$account = array(
'username' => $data['info']['openid'],
'password' => rand_string(8),
);
$result = self::create($account);
if (false !== $result) {
$socialite_info = $data['info'];
$user = $this->where('uid', $result->uid)->find();
$socialite_info['uid'] = $user['uid'];
$socialite_info['type'] = $data['open_type'];
$socialite->register($socialite_info);
} else {
$this->error = "注册失败!";
return false;
}
}
}
public function wechatLogin($user_info){
$socialite = $this->where('openid', $user_info['openid'])->where('type', 'wechat')->find();
$member = new Member();
if ($socialite) {
$this->where('id', $socialite['id'])->update($user_info);
if ($socialite['uid'] > 0) {
//绑定了用户则自动登录
$user = $member->where('uid', $socialite['uid'])->find();
$member->autoLogin($user);
}
}else{
$user_info['type'] = 'wechat';
$this->insert($user_info);
}
}
}

19
app/model/Menu.php Normal file
View File

@@ -0,0 +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\model;
use think\Model;
/**
* @title: 菜单模型
*/
class Menu extends Model {
}