mirror of https://gitee.com/karson/fastadmin.git
'update.gitignore'
parent
1176dfe6d5
commit
5d05d2f1bb
|
|
@ -0,0 +1,4 @@
|
|||
##ignore this file##
|
||||
/.idea/*
|
||||
/Runtime/*
|
||||
/application/database.php
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -1,114 +1,114 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Sms as Smslib;
|
||||
use app\common\model\User;
|
||||
|
||||
/**
|
||||
* 短信接口
|
||||
*/
|
||||
class Sms extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = '*';
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $event 事件名称
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$mobile = $this->request->request("mobile");
|
||||
$event = $this->request->request("event");
|
||||
$event = $event ? $event : 'register';
|
||||
|
||||
$last = Smslib::get($mobile, $event);
|
||||
if ($last && time() - $last['createtime'] < 60)
|
||||
{
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
if ($event)
|
||||
{
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo)
|
||||
{
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
}
|
||||
else if (in_array($event, ['changemobile']) && $userinfo)
|
||||
{
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
}
|
||||
else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
|
||||
{
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Smslib::send($mobile, NULL, $event);
|
||||
if ($ret)
|
||||
{
|
||||
$this->success(__('发送成功'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(__('发送失败'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $event 事件名称
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$mobile = $this->request->request("mobile");
|
||||
$event = $this->request->request("event");
|
||||
$event = $event ? $event : 'register';
|
||||
$captcha = $this->request->request("captcha");
|
||||
|
||||
if ($event)
|
||||
{
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo)
|
||||
{
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
}
|
||||
else if (in_array($event, ['changemobile']) && $userinfo)
|
||||
{
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
}
|
||||
else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
|
||||
{
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Smslib::check($mobile, $captcha, $event);
|
||||
if ($ret)
|
||||
{
|
||||
$this->success(__('成功'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Sms as Smslib;
|
||||
use app\common\model\User;
|
||||
|
||||
/**
|
||||
* 短信接口
|
||||
*/
|
||||
class Sms extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = '*';
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $event 事件名称
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$mobile = $this->request->request("mobile");
|
||||
$event = $this->request->request("event");
|
||||
$event = $event ? $event : 'register';
|
||||
|
||||
$last = Smslib::get($mobile, $event);
|
||||
if ($last && time() - $last['createtime'] < 60)
|
||||
{
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
if ($event)
|
||||
{
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo)
|
||||
{
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
}
|
||||
else if (in_array($event, ['changemobile']) && $userinfo)
|
||||
{
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
}
|
||||
else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
|
||||
{
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Smslib::send($mobile, NULL, $event);
|
||||
if ($ret)
|
||||
{
|
||||
$this->success(__('发送成功'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(__('发送失败'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $event 事件名称
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$mobile = $this->request->request("mobile");
|
||||
$event = $this->request->request("event");
|
||||
$event = $event ? $event : 'register';
|
||||
$captcha = $this->request->request("captcha");
|
||||
|
||||
if ($event)
|
||||
{
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo)
|
||||
{
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
}
|
||||
else if (in_array($event, ['changemobile']) && $userinfo)
|
||||
{
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
}
|
||||
else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
|
||||
{
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Smslib::check($mobile, $captcha, $event);
|
||||
if ($ret)
|
||||
{
|
||||
$this->success(__('成功'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,112 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\model\User;
|
||||
|
||||
/**
|
||||
* 验证接口
|
||||
*/
|
||||
class Validate extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = '*';
|
||||
protected $layout = '';
|
||||
protected $error = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱
|
||||
*
|
||||
* @param string $email 邮箱
|
||||
* @param string $id 会员ID
|
||||
*/
|
||||
public function check_email_available()
|
||||
{
|
||||
$email = $this->request->request('email');
|
||||
$id = (int) $this->request->request('id');
|
||||
$count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
$this->error(__('邮箱已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户名
|
||||
*
|
||||
* @param string $username 用户名
|
||||
* @param string $id 会员ID
|
||||
*/
|
||||
public function check_username_available()
|
||||
{
|
||||
$email = $this->request->request('username');
|
||||
$id = (int) $this->request->request('id');
|
||||
$count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
$this->error(__('用户名已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $id 会员ID
|
||||
*/
|
||||
public function check_mobile_available()
|
||||
{
|
||||
$email = $this->request->request('mobile');
|
||||
$id = (int) $this->request->request('id');
|
||||
$count = User::where('mobile', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
$this->error(__('已经使用该手机号注册'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
*/
|
||||
public function check_mobile_exist()
|
||||
{
|
||||
$email = $this->request->request('mobile');
|
||||
$count = User::where('mobile', '=', $email)->count();
|
||||
if (!$count)
|
||||
{
|
||||
$this->error(__('手机号不存在'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $captcha 验证码
|
||||
* @param string $event 事件
|
||||
*/
|
||||
public function check_sms_correct()
|
||||
{
|
||||
$mobile = $this->request->request('mobile');
|
||||
$captcha = $this->request->request('captcha');
|
||||
$event = $this->request->request('event');
|
||||
if (!\app\common\library\Sms::check($mobile, $captcha, $event))
|
||||
{
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\model\User;
|
||||
|
||||
/**
|
||||
* 验证接口
|
||||
*/
|
||||
class Validate extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = '*';
|
||||
protected $layout = '';
|
||||
protected $error = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱
|
||||
*
|
||||
* @param string $email 邮箱
|
||||
* @param string $id 会员ID
|
||||
*/
|
||||
public function check_email_available()
|
||||
{
|
||||
$email = $this->request->request('email');
|
||||
$id = (int) $this->request->request('id');
|
||||
$count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
$this->error(__('邮箱已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户名
|
||||
*
|
||||
* @param string $username 用户名
|
||||
* @param string $id 会员ID
|
||||
*/
|
||||
public function check_username_available()
|
||||
{
|
||||
$email = $this->request->request('username');
|
||||
$id = (int) $this->request->request('id');
|
||||
$count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
$this->error(__('用户名已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $id 会员ID
|
||||
*/
|
||||
public function check_mobile_available()
|
||||
{
|
||||
$email = $this->request->request('mobile');
|
||||
$id = (int) $this->request->request('id');
|
||||
$count = User::where('mobile', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
$this->error(__('已经使用该手机号注册'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
*/
|
||||
public function check_mobile_exist()
|
||||
{
|
||||
$email = $this->request->request('mobile');
|
||||
$count = User::where('mobile', '=', $email)->count();
|
||||
if (!$count)
|
||||
{
|
||||
$this->error(__('手机号不存在'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $captcha 验证码
|
||||
* @param string $event 事件
|
||||
*/
|
||||
public function check_sms_correct()
|
||||
{
|
||||
$mobile = $this->request->request('mobile');
|
||||
$captcha = $this->request->request('captcha');
|
||||
$event = $this->request->request('event');
|
||||
if (!\app\common\library\Sms::check($mobile, $captcha, $event))
|
||||
{
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,93 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 地区数据模型
|
||||
*/
|
||||
class Area extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 根据经纬度获取当前地区信息
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array 城市信息
|
||||
*/
|
||||
public static function getAreaFromLngLat($lng, $lat, $level = 3)
|
||||
{
|
||||
$namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
|
||||
$rangearr = [1 => 15000, 2 => 1000, 3 => 200];
|
||||
$geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3];
|
||||
$georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3];
|
||||
$neararea = [];
|
||||
// 读取范围内的ID
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$georadiuslist = [];
|
||||
if (method_exists($redis, 'georadius'))
|
||||
{
|
||||
$georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
|
||||
}
|
||||
|
||||
if ($georadiuslist)
|
||||
{
|
||||
list($id, $distance) = $georadiuslist[0];
|
||||
}
|
||||
$id = isset($id) && $id ? $id : 3;
|
||||
return self::get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取省份
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array
|
||||
*/
|
||||
public static function getProvinceFromLngLat($lng, $lat)
|
||||
{
|
||||
$provincedata = [];
|
||||
$citydata = self::getCityFromLngLat($lng, $lat);
|
||||
if ($citydata)
|
||||
{
|
||||
$provincedata = self::get($citydata['pid']);
|
||||
}
|
||||
return $provincedata;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取城市
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array
|
||||
*/
|
||||
public static function getCityFromLngLat($lng, $lat)
|
||||
{
|
||||
$citydata = [];
|
||||
$districtdata = self::getDistrictFromLngLat($lng, $lat);
|
||||
if ($districtdata)
|
||||
{
|
||||
$citydata = self::get($districtdata['pid']);
|
||||
}
|
||||
return $citydata;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取地区
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array
|
||||
*/
|
||||
public static function getDistrictFromLngLat($lng, $lat)
|
||||
{
|
||||
$districtdata = self::getAreaFromLngLat($lng, $lat, 3);
|
||||
return $districtdata;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 地区数据模型
|
||||
*/
|
||||
class Area extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 根据经纬度获取当前地区信息
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array 城市信息
|
||||
*/
|
||||
public static function getAreaFromLngLat($lng, $lat, $level = 3)
|
||||
{
|
||||
$namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
|
||||
$rangearr = [1 => 15000, 2 => 1000, 3 => 200];
|
||||
$geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3];
|
||||
$georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3];
|
||||
$neararea = [];
|
||||
// 读取范围内的ID
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$georadiuslist = [];
|
||||
if (method_exists($redis, 'georadius'))
|
||||
{
|
||||
$georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
|
||||
}
|
||||
|
||||
if ($georadiuslist)
|
||||
{
|
||||
list($id, $distance) = $georadiuslist[0];
|
||||
}
|
||||
$id = isset($id) && $id ? $id : 3;
|
||||
return self::get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取省份
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array
|
||||
*/
|
||||
public static function getProvinceFromLngLat($lng, $lat)
|
||||
{
|
||||
$provincedata = [];
|
||||
$citydata = self::getCityFromLngLat($lng, $lat);
|
||||
if ($citydata)
|
||||
{
|
||||
$provincedata = self::get($citydata['pid']);
|
||||
}
|
||||
return $provincedata;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取城市
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array
|
||||
*/
|
||||
public static function getCityFromLngLat($lng, $lat)
|
||||
{
|
||||
$citydata = [];
|
||||
$districtdata = self::getDistrictFromLngLat($lng, $lat);
|
||||
if ($districtdata)
|
||||
{
|
||||
$citydata = self::get($districtdata['pid']);
|
||||
}
|
||||
return $citydata;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取地区
|
||||
*
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
* @return array
|
||||
*/
|
||||
public static function getDistrictFromLngLat($lng, $lat)
|
||||
{
|
||||
$districtdata = self::getAreaFromLngLat($lng, $lat, 3);
|
||||
return $districtdata;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,143 +1,143 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 验证码类
|
||||
*/
|
||||
class Sms
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证码有效时长
|
||||
* @var int
|
||||
*/
|
||||
protected static $expire = 120;
|
||||
|
||||
/**
|
||||
* 最大允许检测的次数
|
||||
* @var int
|
||||
*/
|
||||
protected static $maxCheckNums = 10;
|
||||
|
||||
/**
|
||||
* 获取最后一次手机发送的数据
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param string $event 事件
|
||||
* @return Sms
|
||||
*/
|
||||
public static function get($mobile, $event = 'default')
|
||||
{
|
||||
$sms = \app\common\model\Sms::
|
||||
where(['mobile' => $mobile, 'event' => $event])
|
||||
->order('id', 'DESC')
|
||||
->find();
|
||||
Hook::listen('sms_get', $sms, null, true);
|
||||
return $sms ? $sms : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param int $code 验证码,为空时将自动生成4位数字
|
||||
* @param string $event 事件
|
||||
* @return boolean
|
||||
*/
|
||||
public static function send($mobile, $code = NULL, $event = 'default')
|
||||
{
|
||||
$code = is_null($code) ? mt_rand(1000, 9999) : $code;
|
||||
$time = time();
|
||||
$sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'createtime' => $time]);
|
||||
$result = Hook::listen('sms_send', $sms, null, true);
|
||||
if (!$result)
|
||||
{
|
||||
$sms->delete();
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送通知
|
||||
*
|
||||
* @param mixed $mobile 手机号,多个以,分隔
|
||||
* @param string $msg 消息内容
|
||||
* @param string $template 消息模板
|
||||
* @return boolean
|
||||
*/
|
||||
public static function notice($mobile, $msg = '', $template = NULL)
|
||||
{
|
||||
$params = [
|
||||
'mobile' => $mobile,
|
||||
'msg' => $msg,
|
||||
'template' => $template
|
||||
];
|
||||
$result = Hook::listen('sms_notice', $params, null, true);
|
||||
return $result ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param int $code 验证码
|
||||
* @param string $event 事件
|
||||
* @return boolean
|
||||
*/
|
||||
public static function check($mobile, $code, $event = 'default')
|
||||
{
|
||||
$time = time() - self::$expire;
|
||||
$sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
|
||||
->order('id', 'DESC')
|
||||
->find();
|
||||
if ($sms)
|
||||
{
|
||||
if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums)
|
||||
{
|
||||
$correct = $code == $sms['code'];
|
||||
if (!$correct)
|
||||
{
|
||||
$sms->times = $sms->times + 1;
|
||||
$sms->save();
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = Hook::listen('sms_check', $sms, null, true);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 过期则清空该手机验证码
|
||||
self::flush($mobile, $event);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空指定手机号验证码
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param string $event 事件
|
||||
* @return boolean
|
||||
*/
|
||||
public static function flush($mobile, $event = 'default')
|
||||
{
|
||||
\app\common\model\Sms::
|
||||
where(['mobile' => $mobile, 'event' => $event])
|
||||
->delete();
|
||||
Hook::listen('sms_flush');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 验证码类
|
||||
*/
|
||||
class Sms
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证码有效时长
|
||||
* @var int
|
||||
*/
|
||||
protected static $expire = 120;
|
||||
|
||||
/**
|
||||
* 最大允许检测的次数
|
||||
* @var int
|
||||
*/
|
||||
protected static $maxCheckNums = 10;
|
||||
|
||||
/**
|
||||
* 获取最后一次手机发送的数据
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param string $event 事件
|
||||
* @return Sms
|
||||
*/
|
||||
public static function get($mobile, $event = 'default')
|
||||
{
|
||||
$sms = \app\common\model\Sms::
|
||||
where(['mobile' => $mobile, 'event' => $event])
|
||||
->order('id', 'DESC')
|
||||
->find();
|
||||
Hook::listen('sms_get', $sms, null, true);
|
||||
return $sms ? $sms : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param int $code 验证码,为空时将自动生成4位数字
|
||||
* @param string $event 事件
|
||||
* @return boolean
|
||||
*/
|
||||
public static function send($mobile, $code = NULL, $event = 'default')
|
||||
{
|
||||
$code = is_null($code) ? mt_rand(1000, 9999) : $code;
|
||||
$time = time();
|
||||
$sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'createtime' => $time]);
|
||||
$result = Hook::listen('sms_send', $sms, null, true);
|
||||
if (!$result)
|
||||
{
|
||||
$sms->delete();
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送通知
|
||||
*
|
||||
* @param mixed $mobile 手机号,多个以,分隔
|
||||
* @param string $msg 消息内容
|
||||
* @param string $template 消息模板
|
||||
* @return boolean
|
||||
*/
|
||||
public static function notice($mobile, $msg = '', $template = NULL)
|
||||
{
|
||||
$params = [
|
||||
'mobile' => $mobile,
|
||||
'msg' => $msg,
|
||||
'template' => $template
|
||||
];
|
||||
$result = Hook::listen('sms_notice', $params, null, true);
|
||||
return $result ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param int $code 验证码
|
||||
* @param string $event 事件
|
||||
* @return boolean
|
||||
*/
|
||||
public static function check($mobile, $code, $event = 'default')
|
||||
{
|
||||
$time = time() - self::$expire;
|
||||
$sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
|
||||
->order('id', 'DESC')
|
||||
->find();
|
||||
if ($sms)
|
||||
{
|
||||
if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums)
|
||||
{
|
||||
$correct = $code == $sms['code'];
|
||||
if (!$correct)
|
||||
{
|
||||
$sms->times = $sms->times + 1;
|
||||
$sms->save();
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = Hook::listen('sms_check', $sms, null, true);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 过期则清空该手机验证码
|
||||
self::flush($mobile, $event);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空指定手机号验证码
|
||||
*
|
||||
* @param int $mobile 手机号
|
||||
* @param string $event 事件
|
||||
* @return boolean
|
||||
*/
|
||||
public static function flush($mobile, $event = 'default')
|
||||
{
|
||||
\app\common\model\Sms::
|
||||
where(['mobile' => $mobile, 'event' => $event])
|
||||
->delete();
|
||||
Hook::listen('sms_flush');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
|
|
@ -1,358 +1,358 @@
|
|||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
use think\Cookie;
|
||||
use think\Hook;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
class User extends Frontend
|
||||
{
|
||||
|
||||
protected $layout = 'default';
|
||||
protected $noNeedLogin = ['login', 'register', 'third'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$auth = $this->auth;
|
||||
|
||||
$ucenter = get_addon_info('ucenter');
|
||||
if ($ucenter && $ucenter['state'])
|
||||
{
|
||||
include ADDON_PATH . 'ucenter' . DS . 'uc.php';
|
||||
}
|
||||
|
||||
//监听注册登录注销的事件
|
||||
Hook::add('user_login_successed', function($user) use($auth) {
|
||||
Cookie::set('uid', $user->id);
|
||||
Cookie::set('token', $auth->getToken());
|
||||
});
|
||||
Hook::add('user_register_successed', function($user) use($auth) {
|
||||
Cookie::set('uid', $user->id);
|
||||
Cookie::set('token', $auth->getToken());
|
||||
});
|
||||
Hook::add('user_delete_successed', function($user) use($auth) {
|
||||
Cookie::delete('uid');
|
||||
Cookie::delete('token');
|
||||
});
|
||||
Hook::add('user_logout_successed', function($user) use($auth) {
|
||||
Cookie::delete('uid');
|
||||
Cookie::delete('token');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->view->assign('title', __('User center'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册会员
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$url = $this->request->request('url', url('user/index'));
|
||||
if ($this->auth->id)
|
||||
$this->success(__('You\'ve logged in, do not login again'), $url);
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
$username = $this->request->post('username');
|
||||
$password = $this->request->post('password');
|
||||
$email = $this->request->post('email');
|
||||
$mobile = $this->request->post('mobile', '');
|
||||
$captcha = $this->request->post('captcha');
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'username' => 'require|length:3,30',
|
||||
'password' => 'require|length:6,30',
|
||||
'email' => 'require|email',
|
||||
'mobile' => 'regex:/^1\d{10}$/',
|
||||
'captcha' => 'require|captcha',
|
||||
'__token__' => 'token',
|
||||
];
|
||||
|
||||
$msg = [
|
||||
'username.require' => 'Username can not be empty',
|
||||
'username.length' => 'Username must be 3 to 30 characters',
|
||||
'password.require' => 'Password can not be empty',
|
||||
'password.length' => 'Password must be 6 to 30 characters',
|
||||
'captcha.require' => 'Captcha can not be empty',
|
||||
'captcha.captcha' => 'Captcha is incorrect',
|
||||
'email' => 'Email is incorrect',
|
||||
'mobile' => 'Mobile is incorrect',
|
||||
];
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'email' => $email,
|
||||
'mobile' => $mobile,
|
||||
'captcha' => $captcha,
|
||||
'__token__' => $token,
|
||||
];
|
||||
$validate = new Validate($rule, $msg);
|
||||
$result = $validate->check($data);
|
||||
if (!$result)
|
||||
{
|
||||
$this->error(__($validate->getError()));
|
||||
}
|
||||
if ($this->auth->register($username, $password, $email, $mobile))
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synregister($this->auth->id, $password);
|
||||
}
|
||||
$this->success(__('Sign up successful') . $synchtml, $url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
Session::set('redirect_url', $url);
|
||||
$this->view->assign('title', __('Register'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员登录
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$url = $this->request->request('url', url('user/index'));
|
||||
if ($this->auth->id)
|
||||
$this->success(__('You\'ve logged in, do not login again'), $url);
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
$account = $this->request->post('account');
|
||||
$password = $this->request->post('password');
|
||||
$keeptime = (int) $this->request->post('keeptime');
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'account' => 'require|length:3,50',
|
||||
'password' => 'require|length:6,30',
|
||||
'__token__' => 'token',
|
||||
];
|
||||
|
||||
$msg = [
|
||||
'account.require' => 'Account can not be empty',
|
||||
'account.length' => 'Account must be 3 to 50 characters',
|
||||
'password.require' => 'Password can not be empty',
|
||||
'password.length' => 'Password must be 6 to 30 characters',
|
||||
];
|
||||
$data = [
|
||||
'account' => $account,
|
||||
'password' => $password,
|
||||
'__token__' => $token,
|
||||
];
|
||||
$validate = new Validate($rule, $msg);
|
||||
$result = $validate->check($data);
|
||||
if (!$result)
|
||||
{
|
||||
$this->error(__($validate->getError()));
|
||||
return FALSE;
|
||||
}
|
||||
if ($this->auth->login($account, $password, $keeptime))
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogin($this->auth->id);
|
||||
}
|
||||
$this->success(__('Logged in successful') . $synchtml, $url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
$this->view->assign('title', __('Login'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销登录
|
||||
*/
|
||||
function logout()
|
||||
{
|
||||
//注销本站
|
||||
$this->auth->logout();
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogout();
|
||||
}
|
||||
$this->success(__('Logout successful') . $synchtml, url('user/index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方登录跳转和回调处理
|
||||
*/
|
||||
public function third()
|
||||
{
|
||||
$url = url('user/index');
|
||||
$action = $this->request->param('action');
|
||||
$platform = $this->request->param('platform');
|
||||
$config = get_addon_config('third');
|
||||
if (!$config || !isset($config[$platform]))
|
||||
{
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
foreach ($config as $k => &$v)
|
||||
{
|
||||
$v['callback'] = url('user/third', ['action' => 'callback', 'platform' => $k], false, true);
|
||||
}
|
||||
unset($v);
|
||||
$app = new \addons\third\library\Application($config);
|
||||
if ($action == 'redirect')
|
||||
{
|
||||
// 跳转到登录授权页面
|
||||
$this->redirect($app->{$platform}->getAuthorizeUrl());
|
||||
}
|
||||
else if ($action == 'callback')
|
||||
{
|
||||
// 授权成功后的回调
|
||||
$result = $app->{$platform}->getUserInfo();
|
||||
if ($result)
|
||||
{
|
||||
$loginret = \addons\third\library\Service::connect($platform, $result);
|
||||
if ($loginret)
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogin($this->auth->id);
|
||||
}
|
||||
$this->success(__('Logged in successful') . $synchtml, $url);
|
||||
}
|
||||
}
|
||||
$this->error(__('Operation failed'), $url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$this->view->assign('title', __('Profile'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活邮箱
|
||||
*/
|
||||
public function activeemail()
|
||||
{
|
||||
$code = $this->request->request('code');
|
||||
$code = base64_decode($code);
|
||||
parse_str($code, $params);
|
||||
if (!isset($params['id']) || !isset($params['time']) || !isset($params['key']))
|
||||
{
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$user = \app\common\model\User::get($params['id']);
|
||||
if (!$user)
|
||||
{
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
if ($user->verification->email)
|
||||
{
|
||||
$this->error(__('Email already activation'));
|
||||
}
|
||||
if ($key !== md5(md5($user->id . $user->email . $time) . $user->salt) || time() - $params['time'] > 1800)
|
||||
{
|
||||
$this->error(__('Secrity code already invalid'));
|
||||
}
|
||||
$verification = $user->verification;
|
||||
$verification->email = 1;
|
||||
$user->verification = $verification;
|
||||
$user->save();
|
||||
$this->success(__('Active email successful'), url('user/index'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public function changepwd()
|
||||
{
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
$oldpassword = $this->request->post("oldpassword");
|
||||
$newpassword = $this->request->post("newpassword");
|
||||
$renewpassword = $this->request->post("renewpassword");
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'oldpassword' => 'require|length:6,30',
|
||||
'newpassword' => 'require|length:6,30',
|
||||
'renewpassword' => 'require|length:6,30|confirm:newpassword',
|
||||
'__token__' => 'token',
|
||||
];
|
||||
|
||||
$msg = [
|
||||
];
|
||||
$data = [
|
||||
'oldpassword' => $oldpassword,
|
||||
'newpassword' => $newpassword,
|
||||
'renewpassword' => $renewpassword,
|
||||
'__token__' => $token,
|
||||
];
|
||||
$field = [
|
||||
'oldpassword' => __('Old password'),
|
||||
'newpassword' => __('New password'),
|
||||
'renewpassword' => __('Renew password')
|
||||
];
|
||||
$validate = new Validate($rule, $msg, $field);
|
||||
$result = $validate->check($data);
|
||||
if (!$result)
|
||||
{
|
||||
$this->error(__($validate->getError()));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$ret = $this->auth->changepwd($newpassword, $oldpassword);
|
||||
if ($ret)
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogout();
|
||||
}
|
||||
$this->success(__('Reset password successful') . $synchtml, url('user/login'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
$this->view->assign('title', __('Change password'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
use think\Cookie;
|
||||
use think\Hook;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
class User extends Frontend
|
||||
{
|
||||
|
||||
protected $layout = 'default';
|
||||
protected $noNeedLogin = ['login', 'register', 'third'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$auth = $this->auth;
|
||||
|
||||
$ucenter = get_addon_info('ucenter');
|
||||
if ($ucenter && $ucenter['state'])
|
||||
{
|
||||
include ADDON_PATH . 'ucenter' . DS . 'uc.php';
|
||||
}
|
||||
|
||||
//监听注册登录注销的事件
|
||||
Hook::add('user_login_successed', function($user) use($auth) {
|
||||
Cookie::set('uid', $user->id);
|
||||
Cookie::set('token', $auth->getToken());
|
||||
});
|
||||
Hook::add('user_register_successed', function($user) use($auth) {
|
||||
Cookie::set('uid', $user->id);
|
||||
Cookie::set('token', $auth->getToken());
|
||||
});
|
||||
Hook::add('user_delete_successed', function($user) use($auth) {
|
||||
Cookie::delete('uid');
|
||||
Cookie::delete('token');
|
||||
});
|
||||
Hook::add('user_logout_successed', function($user) use($auth) {
|
||||
Cookie::delete('uid');
|
||||
Cookie::delete('token');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->view->assign('title', __('User center'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册会员
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$url = $this->request->request('url', url('user/index'));
|
||||
if ($this->auth->id)
|
||||
$this->success(__('You\'ve logged in, do not login again'), $url);
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
$username = $this->request->post('username');
|
||||
$password = $this->request->post('password');
|
||||
$email = $this->request->post('email');
|
||||
$mobile = $this->request->post('mobile', '');
|
||||
$captcha = $this->request->post('captcha');
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'username' => 'require|length:3,30',
|
||||
'password' => 'require|length:6,30',
|
||||
'email' => 'require|email',
|
||||
'mobile' => 'regex:/^1\d{10}$/',
|
||||
'captcha' => 'require|captcha',
|
||||
'__token__' => 'token',
|
||||
];
|
||||
|
||||
$msg = [
|
||||
'username.require' => 'Username can not be empty',
|
||||
'username.length' => 'Username must be 3 to 30 characters',
|
||||
'password.require' => 'Password can not be empty',
|
||||
'password.length' => 'Password must be 6 to 30 characters',
|
||||
'captcha.require' => 'Captcha can not be empty',
|
||||
'captcha.captcha' => 'Captcha is incorrect',
|
||||
'email' => 'Email is incorrect',
|
||||
'mobile' => 'Mobile is incorrect',
|
||||
];
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'email' => $email,
|
||||
'mobile' => $mobile,
|
||||
'captcha' => $captcha,
|
||||
'__token__' => $token,
|
||||
];
|
||||
$validate = new Validate($rule, $msg);
|
||||
$result = $validate->check($data);
|
||||
if (!$result)
|
||||
{
|
||||
$this->error(__($validate->getError()));
|
||||
}
|
||||
if ($this->auth->register($username, $password, $email, $mobile))
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synregister($this->auth->id, $password);
|
||||
}
|
||||
$this->success(__('Sign up successful') . $synchtml, $url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
Session::set('redirect_url', $url);
|
||||
$this->view->assign('title', __('Register'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员登录
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$url = $this->request->request('url', url('user/index'));
|
||||
if ($this->auth->id)
|
||||
$this->success(__('You\'ve logged in, do not login again'), $url);
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
$account = $this->request->post('account');
|
||||
$password = $this->request->post('password');
|
||||
$keeptime = (int) $this->request->post('keeptime');
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'account' => 'require|length:3,50',
|
||||
'password' => 'require|length:6,30',
|
||||
'__token__' => 'token',
|
||||
];
|
||||
|
||||
$msg = [
|
||||
'account.require' => 'Account can not be empty',
|
||||
'account.length' => 'Account must be 3 to 50 characters',
|
||||
'password.require' => 'Password can not be empty',
|
||||
'password.length' => 'Password must be 6 to 30 characters',
|
||||
];
|
||||
$data = [
|
||||
'account' => $account,
|
||||
'password' => $password,
|
||||
'__token__' => $token,
|
||||
];
|
||||
$validate = new Validate($rule, $msg);
|
||||
$result = $validate->check($data);
|
||||
if (!$result)
|
||||
{
|
||||
$this->error(__($validate->getError()));
|
||||
return FALSE;
|
||||
}
|
||||
if ($this->auth->login($account, $password, $keeptime))
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogin($this->auth->id);
|
||||
}
|
||||
$this->success(__('Logged in successful') . $synchtml, $url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
$this->view->assign('title', __('Login'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销登录
|
||||
*/
|
||||
function logout()
|
||||
{
|
||||
//注销本站
|
||||
$this->auth->logout();
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogout();
|
||||
}
|
||||
$this->success(__('Logout successful') . $synchtml, url('user/index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方登录跳转和回调处理
|
||||
*/
|
||||
public function third()
|
||||
{
|
||||
$url = url('user/index');
|
||||
$action = $this->request->param('action');
|
||||
$platform = $this->request->param('platform');
|
||||
$config = get_addon_config('third');
|
||||
if (!$config || !isset($config[$platform]))
|
||||
{
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
foreach ($config as $k => &$v)
|
||||
{
|
||||
$v['callback'] = url('user/third', ['action' => 'callback', 'platform' => $k], false, true);
|
||||
}
|
||||
unset($v);
|
||||
$app = new \addons\third\library\Application($config);
|
||||
if ($action == 'redirect')
|
||||
{
|
||||
// 跳转到登录授权页面
|
||||
$this->redirect($app->{$platform}->getAuthorizeUrl());
|
||||
}
|
||||
else if ($action == 'callback')
|
||||
{
|
||||
// 授权成功后的回调
|
||||
$result = $app->{$platform}->getUserInfo();
|
||||
if ($result)
|
||||
{
|
||||
$loginret = \addons\third\library\Service::connect($platform, $result);
|
||||
if ($loginret)
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogin($this->auth->id);
|
||||
}
|
||||
$this->success(__('Logged in successful') . $synchtml, $url);
|
||||
}
|
||||
}
|
||||
$this->error(__('Operation failed'), $url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$this->view->assign('title', __('Profile'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活邮箱
|
||||
*/
|
||||
public function activeemail()
|
||||
{
|
||||
$code = $this->request->request('code');
|
||||
$code = base64_decode($code);
|
||||
parse_str($code, $params);
|
||||
if (!isset($params['id']) || !isset($params['time']) || !isset($params['key']))
|
||||
{
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$user = \app\common\model\User::get($params['id']);
|
||||
if (!$user)
|
||||
{
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
if ($user->verification->email)
|
||||
{
|
||||
$this->error(__('Email already activation'));
|
||||
}
|
||||
if ($key !== md5(md5($user->id . $user->email . $time) . $user->salt) || time() - $params['time'] > 1800)
|
||||
{
|
||||
$this->error(__('Secrity code already invalid'));
|
||||
}
|
||||
$verification = $user->verification;
|
||||
$verification->email = 1;
|
||||
$user->verification = $verification;
|
||||
$user->save();
|
||||
$this->success(__('Active email successful'), url('user/index'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public function changepwd()
|
||||
{
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
$oldpassword = $this->request->post("oldpassword");
|
||||
$newpassword = $this->request->post("newpassword");
|
||||
$renewpassword = $this->request->post("renewpassword");
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'oldpassword' => 'require|length:6,30',
|
||||
'newpassword' => 'require|length:6,30',
|
||||
'renewpassword' => 'require|length:6,30|confirm:newpassword',
|
||||
'__token__' => 'token',
|
||||
];
|
||||
|
||||
$msg = [
|
||||
];
|
||||
$data = [
|
||||
'oldpassword' => $oldpassword,
|
||||
'newpassword' => $newpassword,
|
||||
'renewpassword' => $renewpassword,
|
||||
'__token__' => $token,
|
||||
];
|
||||
$field = [
|
||||
'oldpassword' => __('Old password'),
|
||||
'newpassword' => __('New password'),
|
||||
'renewpassword' => __('Renew password')
|
||||
];
|
||||
$validate = new Validate($rule, $msg, $field);
|
||||
$result = $validate->check($data);
|
||||
if (!$result)
|
||||
{
|
||||
$this->error(__($validate->getError()));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$ret = $this->auth->changepwd($newpassword, $oldpassword);
|
||||
if ($ret)
|
||||
{
|
||||
$synchtml = '';
|
||||
////////////////同步到Ucenter////////////////
|
||||
if (defined('UC_STATUS') && UC_STATUS)
|
||||
{
|
||||
$uc = new \addons\ucenter\library\client\Client();
|
||||
$synchtml = $uc->uc_user_synlogout();
|
||||
}
|
||||
$this->success(__('Reset password successful') . $synchtml, url('user/login'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
$this->view->assign('title', __('Change password'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue