'update.gitignore'

pull/57/head
XingChao 2018-02-27 10:19:39 +08:00
parent 1176dfe6d5
commit 5d05d2f1bb
12 changed files with 1400 additions and 1481 deletions

4
.gitignore vendored 100644
View File

@ -0,0 +1,4 @@
##ignore this file##
/.idea/*
/Runtime/*
/application/database.php

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,7 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JSHint" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="Jscs" enabled="true" level="ERROR" enabled_by_default="true" />
</profile>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/fastadmin.iml" filepath="$PROJECT_DIR$/.idea/fastadmin.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,114 +1,114 @@
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Api; use app\common\controller\Api;
use app\common\library\Sms as Smslib; use app\common\library\Sms as Smslib;
use app\common\model\User; use app\common\model\User;
/** /**
* 短信接口 * 短信接口
*/ */
class Sms extends Api class Sms extends Api
{ {
protected $noNeedLogin = '*'; protected $noNeedLogin = '*';
protected $noNeedRight = '*'; protected $noNeedRight = '*';
public function _initialize() public function _initialize()
{ {
parent::_initialize(); parent::_initialize();
} }
/** /**
* 发送验证码 * 发送验证码
* *
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $event 事件名称 * @param string $event 事件名称
*/ */
public function send() public function send()
{ {
$mobile = $this->request->request("mobile"); $mobile = $this->request->request("mobile");
$event = $this->request->request("event"); $event = $this->request->request("event");
$event = $event ? $event : 'register'; $event = $event ? $event : 'register';
$last = Smslib::get($mobile, $event); $last = Smslib::get($mobile, $event);
if ($last && time() - $last['createtime'] < 60) if ($last && time() - $last['createtime'] < 60)
{ {
$this->error(__('发送频繁')); $this->error(__('发送频繁'));
} }
if ($event) if ($event)
{ {
$userinfo = User::getByMobile($mobile); $userinfo = User::getByMobile($mobile);
if ($event == 'register' && $userinfo) if ($event == 'register' && $userinfo)
{ {
//已被注册 //已被注册
$this->error(__('已被注册')); $this->error(__('已被注册'));
} }
else if (in_array($event, ['changemobile']) && $userinfo) else if (in_array($event, ['changemobile']) && $userinfo)
{ {
//被占用 //被占用
$this->error(__('已被占用')); $this->error(__('已被占用'));
} }
else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
{ {
//未注册 //未注册
$this->error(__('未注册')); $this->error(__('未注册'));
} }
} }
$ret = Smslib::send($mobile, NULL, $event); $ret = Smslib::send($mobile, NULL, $event);
if ($ret) if ($ret)
{ {
$this->success(__('发送成功')); $this->success(__('发送成功'));
} }
else else
{ {
$this->error(__('发送失败')); $this->error(__('发送失败'));
} }
} }
/** /**
* 检测验证码 * 检测验证码
* *
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $event 事件名称 * @param string $event 事件名称
* @param string $captcha 验证码 * @param string $captcha 验证码
*/ */
public function check() public function check()
{ {
$mobile = $this->request->request("mobile"); $mobile = $this->request->request("mobile");
$event = $this->request->request("event"); $event = $this->request->request("event");
$event = $event ? $event : 'register'; $event = $event ? $event : 'register';
$captcha = $this->request->request("captcha"); $captcha = $this->request->request("captcha");
if ($event) if ($event)
{ {
$userinfo = User::getByMobile($mobile); $userinfo = User::getByMobile($mobile);
if ($event == 'register' && $userinfo) if ($event == 'register' && $userinfo)
{ {
//已被注册 //已被注册
$this->error(__('已被注册')); $this->error(__('已被注册'));
} }
else if (in_array($event, ['changemobile']) && $userinfo) else if (in_array($event, ['changemobile']) && $userinfo)
{ {
//被占用 //被占用
$this->error(__('已被占用')); $this->error(__('已被占用'));
} }
else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
{ {
//未注册 //未注册
$this->error(__('未注册')); $this->error(__('未注册'));
} }
} }
$ret = Smslib::check($mobile, $captcha, $event); $ret = Smslib::check($mobile, $captcha, $event);
if ($ret) if ($ret)
{ {
$this->success(__('成功')); $this->success(__('成功'));
} }
else else
{ {
$this->error(__('验证码不正确')); $this->error(__('验证码不正确'));
} }
} }
} }

View File

@ -1,112 +1,112 @@
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Api; use app\common\controller\Api;
use app\common\model\User; use app\common\model\User;
/** /**
* 验证接口 * 验证接口
*/ */
class Validate extends Api class Validate extends Api
{ {
protected $noNeedLogin = '*'; protected $noNeedLogin = '*';
protected $layout = ''; protected $layout = '';
protected $error = null; protected $error = null;
public function _initialize() public function _initialize()
{ {
parent::_initialize(); parent::_initialize();
} }
/** /**
* 检测邮箱 * 检测邮箱
* *
* @param string $email 邮箱 * @param string $email 邮箱
* @param string $id 会员ID * @param string $id 会员ID
*/ */
public function check_email_available() public function check_email_available()
{ {
$email = $this->request->request('email'); $email = $this->request->request('email');
$id = (int) $this->request->request('id'); $id = (int) $this->request->request('id');
$count = User::where('email', '=', $email)->where('id', '<>', $id)->count(); $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
if ($count > 0) if ($count > 0)
{ {
$this->error(__('邮箱已经被占用')); $this->error(__('邮箱已经被占用'));
} }
$this->success(); $this->success();
} }
/** /**
* 检测用户名 * 检测用户名
* *
* @param string $username 用户名 * @param string $username 用户名
* @param string $id 会员ID * @param string $id 会员ID
*/ */
public function check_username_available() public function check_username_available()
{ {
$email = $this->request->request('username'); $email = $this->request->request('username');
$id = (int) $this->request->request('id'); $id = (int) $this->request->request('id');
$count = User::where('username', '=', $email)->where('id', '<>', $id)->count(); $count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
if ($count > 0) if ($count > 0)
{ {
$this->error(__('用户名已经被占用')); $this->error(__('用户名已经被占用'));
} }
$this->success(); $this->success();
} }
/** /**
* 检测手机 * 检测手机
* *
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $id 会员ID * @param string $id 会员ID
*/ */
public function check_mobile_available() public function check_mobile_available()
{ {
$email = $this->request->request('mobile'); $email = $this->request->request('mobile');
$id = (int) $this->request->request('id'); $id = (int) $this->request->request('id');
$count = User::where('mobile', '=', $email)->where('id', '<>', $id)->count(); $count = User::where('mobile', '=', $email)->where('id', '<>', $id)->count();
if ($count > 0) if ($count > 0)
{ {
$this->error(__('已经使用该手机号注册')); $this->error(__('已经使用该手机号注册'));
} }
$this->success(); $this->success();
} }
/** /**
* 检测手机 * 检测手机
* *
* @param string $mobile 手机号 * @param string $mobile 手机号
*/ */
public function check_mobile_exist() public function check_mobile_exist()
{ {
$email = $this->request->request('mobile'); $email = $this->request->request('mobile');
$count = User::where('mobile', '=', $email)->count(); $count = User::where('mobile', '=', $email)->count();
if (!$count) if (!$count)
{ {
$this->error(__('手机号不存在')); $this->error(__('手机号不存在'));
} }
$this->success(); $this->success();
} }
/** /**
* 检测验证码 * 检测验证码
* *
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $captcha 验证码 * @param string $captcha 验证码
* @param string $event 事件 * @param string $event 事件
*/ */
public function check_sms_correct() public function check_sms_correct()
{ {
$mobile = $this->request->request('mobile'); $mobile = $this->request->request('mobile');
$captcha = $this->request->request('captcha'); $captcha = $this->request->request('captcha');
$event = $this->request->request('event'); $event = $this->request->request('event');
if (!\app\common\library\Sms::check($mobile, $captcha, $event)) if (!\app\common\library\Sms::check($mobile, $captcha, $event))
{ {
$this->error(__('验证码不正确')); $this->error(__('验证码不正确'));
} }
$this->success(); $this->success();
} }
} }

View File

@ -1,93 +1,93 @@
<?php <?php
namespace app\api\model; namespace app\api\model;
use think\Cache; use think\Cache;
use think\Model; use think\Model;
/** /**
* 地区数据模型 * 地区数据模型
*/ */
class Area extends Model class Area extends Model
{ {
/** /**
* 根据经纬度获取当前地区信息 * 根据经纬度获取当前地区信息
* *
* @param string $lng 经度 * @param string $lng 经度
* @param string $lat 纬度 * @param string $lat 纬度
* @return array 城市信息 * @return array 城市信息
*/ */
public static function getAreaFromLngLat($lng, $lat, $level = 3) public static function getAreaFromLngLat($lng, $lat, $level = 3)
{ {
$namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district']; $namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
$rangearr = [1 => 15000, 2 => 1000, 3 => 200]; $rangearr = [1 => 15000, 2 => 1000, 3 => 200];
$geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3]; $geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3];
$georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3]; $georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3];
$neararea = []; $neararea = [];
// 读取范围内的ID // 读取范围内的ID
$redis = Cache::store('redis')->handler(); $redis = Cache::store('redis')->handler();
$georadiuslist = []; $georadiuslist = [];
if (method_exists($redis, 'georadius')) if (method_exists($redis, 'georadius'))
{ {
$georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']); $georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
} }
if ($georadiuslist) if ($georadiuslist)
{ {
list($id, $distance) = $georadiuslist[0]; list($id, $distance) = $georadiuslist[0];
} }
$id = isset($id) && $id ? $id : 3; $id = isset($id) && $id ? $id : 3;
return self::get($id); return self::get($id);
} }
/** /**
* 根据经纬度获取省份 * 根据经纬度获取省份
* *
* @param string $lng 经度 * @param string $lng 经度
* @param string $lat 纬度 * @param string $lat 纬度
* @return array * @return array
*/ */
public static function getProvinceFromLngLat($lng, $lat) public static function getProvinceFromLngLat($lng, $lat)
{ {
$provincedata = []; $provincedata = [];
$citydata = self::getCityFromLngLat($lng, $lat); $citydata = self::getCityFromLngLat($lng, $lat);
if ($citydata) if ($citydata)
{ {
$provincedata = self::get($citydata['pid']); $provincedata = self::get($citydata['pid']);
} }
return $provincedata; return $provincedata;
} }
/** /**
* 根据经纬度获取城市 * 根据经纬度获取城市
* *
* @param string $lng 经度 * @param string $lng 经度
* @param string $lat 纬度 * @param string $lat 纬度
* @return array * @return array
*/ */
public static function getCityFromLngLat($lng, $lat) public static function getCityFromLngLat($lng, $lat)
{ {
$citydata = []; $citydata = [];
$districtdata = self::getDistrictFromLngLat($lng, $lat); $districtdata = self::getDistrictFromLngLat($lng, $lat);
if ($districtdata) if ($districtdata)
{ {
$citydata = self::get($districtdata['pid']); $citydata = self::get($districtdata['pid']);
} }
return $citydata; return $citydata;
} }
/** /**
* 根据经纬度获取地区 * 根据经纬度获取地区
* *
* @param string $lng 经度 * @param string $lng 经度
* @param string $lat 纬度 * @param string $lat 纬度
* @return array * @return array
*/ */
public static function getDistrictFromLngLat($lng, $lat) public static function getDistrictFromLngLat($lng, $lat)
{ {
$districtdata = self::getAreaFromLngLat($lng, $lat, 3); $districtdata = self::getAreaFromLngLat($lng, $lat, 3);
return $districtdata; return $districtdata;
} }
} }

View File

@ -1,143 +1,143 @@
<?php <?php
namespace app\common\library; namespace app\common\library;
use think\Hook; use think\Hook;
/** /**
* 验证码类 * 验证码类
*/ */
class Sms class Sms
{ {
/** /**
* 验证码有效时长 * 验证码有效时长
* @var int * @var int
*/ */
protected static $expire = 120; protected static $expire = 120;
/** /**
* 最大允许检测的次数 * 最大允许检测的次数
* @var int * @var int
*/ */
protected static $maxCheckNums = 10; protected static $maxCheckNums = 10;
/** /**
* 获取最后一次手机发送的数据 * 获取最后一次手机发送的数据
* *
* @param int $mobile 手机号 * @param int $mobile 手机号
* @param string $event 事件 * @param string $event 事件
* @return Sms * @return Sms
*/ */
public static function get($mobile, $event = 'default') public static function get($mobile, $event = 'default')
{ {
$sms = \app\common\model\Sms:: $sms = \app\common\model\Sms::
where(['mobile' => $mobile, 'event' => $event]) where(['mobile' => $mobile, 'event' => $event])
->order('id', 'DESC') ->order('id', 'DESC')
->find(); ->find();
Hook::listen('sms_get', $sms, null, true); Hook::listen('sms_get', $sms, null, true);
return $sms ? $sms : NULL; return $sms ? $sms : NULL;
} }
/** /**
* 发送验证码 * 发送验证码
* *
* @param int $mobile 手机号 * @param int $mobile 手机号
* @param int $code 验证码,为空时将自动生成4位数字 * @param int $code 验证码,为空时将自动生成4位数字
* @param string $event 事件 * @param string $event 事件
* @return boolean * @return boolean
*/ */
public static function send($mobile, $code = NULL, $event = 'default') public static function send($mobile, $code = NULL, $event = 'default')
{ {
$code = is_null($code) ? mt_rand(1000, 9999) : $code; $code = is_null($code) ? mt_rand(1000, 9999) : $code;
$time = time(); $time = time();
$sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'createtime' => $time]); $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'createtime' => $time]);
$result = Hook::listen('sms_send', $sms, null, true); $result = Hook::listen('sms_send', $sms, null, true);
if (!$result) if (!$result)
{ {
$sms->delete(); $sms->delete();
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
/** /**
* 发送通知 * 发送通知
* *
* @param mixed $mobile 手机号,多个以,分隔 * @param mixed $mobile 手机号,多个以,分隔
* @param string $msg 消息内容 * @param string $msg 消息内容
* @param string $template 消息模板 * @param string $template 消息模板
* @return boolean * @return boolean
*/ */
public static function notice($mobile, $msg = '', $template = NULL) public static function notice($mobile, $msg = '', $template = NULL)
{ {
$params = [ $params = [
'mobile' => $mobile, 'mobile' => $mobile,
'msg' => $msg, 'msg' => $msg,
'template' => $template 'template' => $template
]; ];
$result = Hook::listen('sms_notice', $params, null, true); $result = Hook::listen('sms_notice', $params, null, true);
return $result ? TRUE : FALSE; return $result ? TRUE : FALSE;
} }
/** /**
* 校验验证码 * 校验验证码
* *
* @param int $mobile 手机号 * @param int $mobile 手机号
* @param int $code 验证码 * @param int $code 验证码
* @param string $event 事件 * @param string $event 事件
* @return boolean * @return boolean
*/ */
public static function check($mobile, $code, $event = 'default') public static function check($mobile, $code, $event = 'default')
{ {
$time = time() - self::$expire; $time = time() - self::$expire;
$sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event]) $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
->order('id', 'DESC') ->order('id', 'DESC')
->find(); ->find();
if ($sms) if ($sms)
{ {
if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums) if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums)
{ {
$correct = $code == $sms['code']; $correct = $code == $sms['code'];
if (!$correct) if (!$correct)
{ {
$sms->times = $sms->times + 1; $sms->times = $sms->times + 1;
$sms->save(); $sms->save();
return FALSE; return FALSE;
} }
else else
{ {
$result = Hook::listen('sms_check', $sms, null, true); $result = Hook::listen('sms_check', $sms, null, true);
return $result; return $result;
} }
} }
else else
{ {
// 过期则清空该手机验证码 // 过期则清空该手机验证码
self::flush($mobile, $event); self::flush($mobile, $event);
return FALSE; return FALSE;
} }
} }
else else
{ {
return FALSE; return FALSE;
} }
} }
/** /**
* 清空指定手机号验证码 * 清空指定手机号验证码
* *
* @param int $mobile 手机号 * @param int $mobile 手机号
* @param string $event 事件 * @param string $event 事件
* @return boolean * @return boolean
*/ */
public static function flush($mobile, $event = 'default') public static function flush($mobile, $event = 'default')
{ {
\app\common\model\Sms:: \app\common\model\Sms::
where(['mobile' => $mobile, 'event' => $event]) where(['mobile' => $mobile, 'event' => $event])
->delete(); ->delete();
Hook::listen('sms_flush'); Hook::listen('sms_flush');
return TRUE; return TRUE;
} }
} }

View File

@ -1,56 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\Env;
return [
// 数据库类型
'type' => Env::get('database.type', 'mysql'),
// 服务器地址
'hostname' => Env::get('database.hostname', '39.106.45.64'),
// 数据库名
'database' => Env::get('database.database', 'qulvxing'),
// 用户名
'username' => Env::get('database.username', 'jtl'),
// 密码
'password' => Env::get('database.password', '!jtl123361@GLOD.com'),
// 端口
'hostport' => Env::get('database.hostport', ''),
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => Env::get('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => Env::get('database.prefix', 'fa_'),
// 数据库调试模式
'debug' => Env::get('database.debug', true),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'array',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式,默认为Y-m-d H:i:s
'datetime_format' => false,
// 是否需要进行SQL性能分析
'sql_explain' => false,
];

View File

@ -1,358 +1,358 @@
<?php <?php
namespace app\index\controller; namespace app\index\controller;
use app\common\controller\Frontend; use app\common\controller\Frontend;
use think\Cookie; use think\Cookie;
use think\Hook; use think\Hook;
use think\Session; use think\Session;
use think\Validate; use think\Validate;
/** /**
* 会员中心 * 会员中心
*/ */
class User extends Frontend class User extends Frontend
{ {
protected $layout = 'default'; protected $layout = 'default';
protected $noNeedLogin = ['login', 'register', 'third']; protected $noNeedLogin = ['login', 'register', 'third'];
protected $noNeedRight = ['*']; protected $noNeedRight = ['*'];
public function _initialize() public function _initialize()
{ {
parent::_initialize(); parent::_initialize();
$auth = $this->auth; $auth = $this->auth;
$ucenter = get_addon_info('ucenter'); $ucenter = get_addon_info('ucenter');
if ($ucenter && $ucenter['state']) if ($ucenter && $ucenter['state'])
{ {
include ADDON_PATH . 'ucenter' . DS . 'uc.php'; include ADDON_PATH . 'ucenter' . DS . 'uc.php';
} }
//监听注册登录注销的事件 //监听注册登录注销的事件
Hook::add('user_login_successed', function($user) use($auth) { Hook::add('user_login_successed', function($user) use($auth) {
Cookie::set('uid', $user->id); Cookie::set('uid', $user->id);
Cookie::set('token', $auth->getToken()); Cookie::set('token', $auth->getToken());
}); });
Hook::add('user_register_successed', function($user) use($auth) { Hook::add('user_register_successed', function($user) use($auth) {
Cookie::set('uid', $user->id); Cookie::set('uid', $user->id);
Cookie::set('token', $auth->getToken()); Cookie::set('token', $auth->getToken());
}); });
Hook::add('user_delete_successed', function($user) use($auth) { Hook::add('user_delete_successed', function($user) use($auth) {
Cookie::delete('uid'); Cookie::delete('uid');
Cookie::delete('token'); Cookie::delete('token');
}); });
Hook::add('user_logout_successed', function($user) use($auth) { Hook::add('user_logout_successed', function($user) use($auth) {
Cookie::delete('uid'); Cookie::delete('uid');
Cookie::delete('token'); Cookie::delete('token');
}); });
} }
/** /**
* 会员中心 * 会员中心
*/ */
public function index() public function index()
{ {
$this->view->assign('title', __('User center')); $this->view->assign('title', __('User center'));
return $this->view->fetch(); return $this->view->fetch();
} }
/** /**
* 注册会员 * 注册会员
*/ */
public function register() public function register()
{ {
$url = $this->request->request('url', url('user/index')); $url = $this->request->request('url', url('user/index'));
if ($this->auth->id) if ($this->auth->id)
$this->success(__('You\'ve logged in, do not login again'), $url); $this->success(__('You\'ve logged in, do not login again'), $url);
if ($this->request->isPost()) if ($this->request->isPost())
{ {
$username = $this->request->post('username'); $username = $this->request->post('username');
$password = $this->request->post('password'); $password = $this->request->post('password');
$email = $this->request->post('email'); $email = $this->request->post('email');
$mobile = $this->request->post('mobile', ''); $mobile = $this->request->post('mobile', '');
$captcha = $this->request->post('captcha'); $captcha = $this->request->post('captcha');
$token = $this->request->post('__token__'); $token = $this->request->post('__token__');
$rule = [ $rule = [
'username' => 'require|length:3,30', 'username' => 'require|length:3,30',
'password' => 'require|length:6,30', 'password' => 'require|length:6,30',
'email' => 'require|email', 'email' => 'require|email',
'mobile' => 'regex:/^1\d{10}$/', 'mobile' => 'regex:/^1\d{10}$/',
'captcha' => 'require|captcha', 'captcha' => 'require|captcha',
'__token__' => 'token', '__token__' => 'token',
]; ];
$msg = [ $msg = [
'username.require' => 'Username can not be empty', 'username.require' => 'Username can not be empty',
'username.length' => 'Username must be 3 to 30 characters', 'username.length' => 'Username must be 3 to 30 characters',
'password.require' => 'Password can not be empty', 'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters', 'password.length' => 'Password must be 6 to 30 characters',
'captcha.require' => 'Captcha can not be empty', 'captcha.require' => 'Captcha can not be empty',
'captcha.captcha' => 'Captcha is incorrect', 'captcha.captcha' => 'Captcha is incorrect',
'email' => 'Email is incorrect', 'email' => 'Email is incorrect',
'mobile' => 'Mobile is incorrect', 'mobile' => 'Mobile is incorrect',
]; ];
$data = [ $data = [
'username' => $username, 'username' => $username,
'password' => $password, 'password' => $password,
'email' => $email, 'email' => $email,
'mobile' => $mobile, 'mobile' => $mobile,
'captcha' => $captcha, 'captcha' => $captcha,
'__token__' => $token, '__token__' => $token,
]; ];
$validate = new Validate($rule, $msg); $validate = new Validate($rule, $msg);
$result = $validate->check($data); $result = $validate->check($data);
if (!$result) if (!$result)
{ {
$this->error(__($validate->getError())); $this->error(__($validate->getError()));
} }
if ($this->auth->register($username, $password, $email, $mobile)) if ($this->auth->register($username, $password, $email, $mobile))
{ {
$synchtml = ''; $synchtml = '';
////////////////同步到Ucenter//////////////// ////////////////同步到Ucenter////////////////
if (defined('UC_STATUS') && UC_STATUS) if (defined('UC_STATUS') && UC_STATUS)
{ {
$uc = new \addons\ucenter\library\client\Client(); $uc = new \addons\ucenter\library\client\Client();
$synchtml = $uc->uc_user_synregister($this->auth->id, $password); $synchtml = $uc->uc_user_synregister($this->auth->id, $password);
} }
$this->success(__('Sign up successful') . $synchtml, $url); $this->success(__('Sign up successful') . $synchtml, $url);
} }
else else
{ {
$this->error($this->auth->getError()); $this->error($this->auth->getError());
} }
} }
Session::set('redirect_url', $url); Session::set('redirect_url', $url);
$this->view->assign('title', __('Register')); $this->view->assign('title', __('Register'));
return $this->view->fetch(); return $this->view->fetch();
} }
/** /**
* 会员登录 * 会员登录
*/ */
public function login() public function login()
{ {
$url = $this->request->request('url', url('user/index')); $url = $this->request->request('url', url('user/index'));
if ($this->auth->id) if ($this->auth->id)
$this->success(__('You\'ve logged in, do not login again'), $url); $this->success(__('You\'ve logged in, do not login again'), $url);
if ($this->request->isPost()) if ($this->request->isPost())
{ {
$account = $this->request->post('account'); $account = $this->request->post('account');
$password = $this->request->post('password'); $password = $this->request->post('password');
$keeptime = (int) $this->request->post('keeptime'); $keeptime = (int) $this->request->post('keeptime');
$token = $this->request->post('__token__'); $token = $this->request->post('__token__');
$rule = [ $rule = [
'account' => 'require|length:3,50', 'account' => 'require|length:3,50',
'password' => 'require|length:6,30', 'password' => 'require|length:6,30',
'__token__' => 'token', '__token__' => 'token',
]; ];
$msg = [ $msg = [
'account.require' => 'Account can not be empty', 'account.require' => 'Account can not be empty',
'account.length' => 'Account must be 3 to 50 characters', 'account.length' => 'Account must be 3 to 50 characters',
'password.require' => 'Password can not be empty', 'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters', 'password.length' => 'Password must be 6 to 30 characters',
]; ];
$data = [ $data = [
'account' => $account, 'account' => $account,
'password' => $password, 'password' => $password,
'__token__' => $token, '__token__' => $token,
]; ];
$validate = new Validate($rule, $msg); $validate = new Validate($rule, $msg);
$result = $validate->check($data); $result = $validate->check($data);
if (!$result) if (!$result)
{ {
$this->error(__($validate->getError())); $this->error(__($validate->getError()));
return FALSE; return FALSE;
} }
if ($this->auth->login($account, $password, $keeptime)) if ($this->auth->login($account, $password, $keeptime))
{ {
$synchtml = ''; $synchtml = '';
////////////////同步到Ucenter//////////////// ////////////////同步到Ucenter////////////////
if (defined('UC_STATUS') && UC_STATUS) if (defined('UC_STATUS') && UC_STATUS)
{ {
$uc = new \addons\ucenter\library\client\Client(); $uc = new \addons\ucenter\library\client\Client();
$synchtml = $uc->uc_user_synlogin($this->auth->id); $synchtml = $uc->uc_user_synlogin($this->auth->id);
} }
$this->success(__('Logged in successful') . $synchtml, $url); $this->success(__('Logged in successful') . $synchtml, $url);
} }
else else
{ {
$this->error($this->auth->getError()); $this->error($this->auth->getError());
} }
} }
$this->view->assign('title', __('Login')); $this->view->assign('title', __('Login'));
return $this->view->fetch(); return $this->view->fetch();
} }
/** /**
* 注销登录 * 注销登录
*/ */
function logout() function logout()
{ {
//注销本站 //注销本站
$this->auth->logout(); $this->auth->logout();
$synchtml = ''; $synchtml = '';
////////////////同步到Ucenter//////////////// ////////////////同步到Ucenter////////////////
if (defined('UC_STATUS') && UC_STATUS) if (defined('UC_STATUS') && UC_STATUS)
{ {
$uc = new \addons\ucenter\library\client\Client(); $uc = new \addons\ucenter\library\client\Client();
$synchtml = $uc->uc_user_synlogout(); $synchtml = $uc->uc_user_synlogout();
} }
$this->success(__('Logout successful') . $synchtml, url('user/index')); $this->success(__('Logout successful') . $synchtml, url('user/index'));
} }
/** /**
* 第三方登录跳转和回调处理 * 第三方登录跳转和回调处理
*/ */
public function third() public function third()
{ {
$url = url('user/index'); $url = url('user/index');
$action = $this->request->param('action'); $action = $this->request->param('action');
$platform = $this->request->param('platform'); $platform = $this->request->param('platform');
$config = get_addon_config('third'); $config = get_addon_config('third');
if (!$config || !isset($config[$platform])) if (!$config || !isset($config[$platform]))
{ {
$this->error(__('Invalid parameters')); $this->error(__('Invalid parameters'));
} }
foreach ($config as $k => &$v) foreach ($config as $k => &$v)
{ {
$v['callback'] = url('user/third', ['action' => 'callback', 'platform' => $k], false, true); $v['callback'] = url('user/third', ['action' => 'callback', 'platform' => $k], false, true);
} }
unset($v); unset($v);
$app = new \addons\third\library\Application($config); $app = new \addons\third\library\Application($config);
if ($action == 'redirect') if ($action == 'redirect')
{ {
// 跳转到登录授权页面 // 跳转到登录授权页面
$this->redirect($app->{$platform}->getAuthorizeUrl()); $this->redirect($app->{$platform}->getAuthorizeUrl());
} }
else if ($action == 'callback') else if ($action == 'callback')
{ {
// 授权成功后的回调 // 授权成功后的回调
$result = $app->{$platform}->getUserInfo(); $result = $app->{$platform}->getUserInfo();
if ($result) if ($result)
{ {
$loginret = \addons\third\library\Service::connect($platform, $result); $loginret = \addons\third\library\Service::connect($platform, $result);
if ($loginret) if ($loginret)
{ {
$synchtml = ''; $synchtml = '';
////////////////同步到Ucenter//////////////// ////////////////同步到Ucenter////////////////
if (defined('UC_STATUS') && UC_STATUS) if (defined('UC_STATUS') && UC_STATUS)
{ {
$uc = new \addons\ucenter\library\client\Client(); $uc = new \addons\ucenter\library\client\Client();
$synchtml = $uc->uc_user_synlogin($this->auth->id); $synchtml = $uc->uc_user_synlogin($this->auth->id);
} }
$this->success(__('Logged in successful') . $synchtml, $url); $this->success(__('Logged in successful') . $synchtml, $url);
} }
} }
$this->error(__('Operation failed'), $url); $this->error(__('Operation failed'), $url);
} }
else else
{ {
$this->error(__('Invalid parameters')); $this->error(__('Invalid parameters'));
} }
} }
/** /**
* 个人信息 * 个人信息
*/ */
public function profile() public function profile()
{ {
$this->view->assign('title', __('Profile')); $this->view->assign('title', __('Profile'));
return $this->view->fetch(); return $this->view->fetch();
} }
/** /**
* 激活邮箱 * 激活邮箱
*/ */
public function activeemail() public function activeemail()
{ {
$code = $this->request->request('code'); $code = $this->request->request('code');
$code = base64_decode($code); $code = base64_decode($code);
parse_str($code, $params); parse_str($code, $params);
if (!isset($params['id']) || !isset($params['time']) || !isset($params['key'])) if (!isset($params['id']) || !isset($params['time']) || !isset($params['key']))
{ {
$this->error(__('Invalid parameters')); $this->error(__('Invalid parameters'));
} }
$user = \app\common\model\User::get($params['id']); $user = \app\common\model\User::get($params['id']);
if (!$user) if (!$user)
{ {
$this->error(__('User not found')); $this->error(__('User not found'));
} }
if ($user->verification->email) if ($user->verification->email)
{ {
$this->error(__('Email already activation')); $this->error(__('Email already activation'));
} }
if ($key !== md5(md5($user->id . $user->email . $time) . $user->salt) || time() - $params['time'] > 1800) if ($key !== md5(md5($user->id . $user->email . $time) . $user->salt) || time() - $params['time'] > 1800)
{ {
$this->error(__('Secrity code already invalid')); $this->error(__('Secrity code already invalid'));
} }
$verification = $user->verification; $verification = $user->verification;
$verification->email = 1; $verification->email = 1;
$user->verification = $verification; $user->verification = $verification;
$user->save(); $user->save();
$this->success(__('Active email successful'), url('user/index')); $this->success(__('Active email successful'), url('user/index'));
return; return;
} }
/** /**
* 修改密码 * 修改密码
*/ */
public function changepwd() public function changepwd()
{ {
if ($this->request->isPost()) if ($this->request->isPost())
{ {
$oldpassword = $this->request->post("oldpassword"); $oldpassword = $this->request->post("oldpassword");
$newpassword = $this->request->post("newpassword"); $newpassword = $this->request->post("newpassword");
$renewpassword = $this->request->post("renewpassword"); $renewpassword = $this->request->post("renewpassword");
$token = $this->request->post('__token__'); $token = $this->request->post('__token__');
$rule = [ $rule = [
'oldpassword' => 'require|length:6,30', 'oldpassword' => 'require|length:6,30',
'newpassword' => 'require|length:6,30', 'newpassword' => 'require|length:6,30',
'renewpassword' => 'require|length:6,30|confirm:newpassword', 'renewpassword' => 'require|length:6,30|confirm:newpassword',
'__token__' => 'token', '__token__' => 'token',
]; ];
$msg = [ $msg = [
]; ];
$data = [ $data = [
'oldpassword' => $oldpassword, 'oldpassword' => $oldpassword,
'newpassword' => $newpassword, 'newpassword' => $newpassword,
'renewpassword' => $renewpassword, 'renewpassword' => $renewpassword,
'__token__' => $token, '__token__' => $token,
]; ];
$field = [ $field = [
'oldpassword' => __('Old password'), 'oldpassword' => __('Old password'),
'newpassword' => __('New password'), 'newpassword' => __('New password'),
'renewpassword' => __('Renew password') 'renewpassword' => __('Renew password')
]; ];
$validate = new Validate($rule, $msg, $field); $validate = new Validate($rule, $msg, $field);
$result = $validate->check($data); $result = $validate->check($data);
if (!$result) if (!$result)
{ {
$this->error(__($validate->getError())); $this->error(__($validate->getError()));
return FALSE; return FALSE;
} }
$ret = $this->auth->changepwd($newpassword, $oldpassword); $ret = $this->auth->changepwd($newpassword, $oldpassword);
if ($ret) if ($ret)
{ {
$synchtml = ''; $synchtml = '';
////////////////同步到Ucenter//////////////// ////////////////同步到Ucenter////////////////
if (defined('UC_STATUS') && UC_STATUS) if (defined('UC_STATUS') && UC_STATUS)
{ {
$uc = new \addons\ucenter\library\client\Client(); $uc = new \addons\ucenter\library\client\Client();
$synchtml = $uc->uc_user_synlogout(); $synchtml = $uc->uc_user_synlogout();
} }
$this->success(__('Reset password successful') . $synchtml, url('user/login')); $this->success(__('Reset password successful') . $synchtml, url('user/login'));
} }
else else
{ {
$this->error($this->auth->getError()); $this->error($this->auth->getError());
} }
} }
$this->view->assign('title', __('Change password')); $this->view->assign('title', __('Change password'));
return $this->view->fetch(); return $this->view->fetch();
} }
} }

File diff suppressed because it is too large Load Diff