|
@@ -16,70 +16,16 @@ use app\common\library\Wechat;
|
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['login', 'mobilelogin', 'tvuser_login', 'wechatlogin', 'bindmobile','register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
+ protected $noNeedLogin = ['wechatlogin', 'bindmobile'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
|
|
|
- if (!Config::get('fastadmin.usercenter')) {
|
|
|
- $this->error(__('User center already closed'));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 会员中心
|
|
|
- */
|
|
|
- public function index()
|
|
|
- {
|
|
|
- $this->success('', ['welcome' => $this->auth->nickname]);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 手机验证码登录
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $mobile 手机号
|
|
|
- * @param string $captcha 验证码
|
|
|
- */
|
|
|
- public function mobilelogin()
|
|
|
- {
|
|
|
- $mobile = input('mobile');
|
|
|
- $captcha = input('captcha');
|
|
|
- if (!$mobile || !$captcha) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
- $this->error(__('Mobile is incorrect'));
|
|
|
- }
|
|
|
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByMobile($mobile);
|
|
|
- if ($user) {
|
|
|
- if ($user->status == -1) {
|
|
|
- $this->error('账号已注销');
|
|
|
- }
|
|
|
- if ($user->status != 1) {
|
|
|
- $this->error(__('Account is locked'));
|
|
|
- }
|
|
|
- //如果已经有账号则直接登录
|
|
|
- $ret = $this->auth->direct($user->id);
|
|
|
- } else {
|
|
|
- $ret = $this->auth->register('', '', '', $mobile, []);
|
|
|
- }
|
|
|
- if ($ret) {
|
|
|
- Sms::flush($mobile, 'mobilelogin');
|
|
|
- $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
//微信登录,预先假注册
|
|
|
public function wechatlogin(){
|
|
|
$code = input('code','');
|
|
@@ -213,48 +159,7 @@ class User extends Api
|
|
|
|
|
|
}
|
|
|
|
|
|
- //电视用户登录。
|
|
|
- public function tvuser_login(){
|
|
|
- $tv_userid = input('tv_userid','');
|
|
|
- $tv_mobile = input('tv_mobile','');
|
|
|
- $tv_signtime = input('tv_signtime','');
|
|
|
- $tv_sign = input('tv_sign','');
|
|
|
- if(empty($tv_userid) || empty($tv_mobile) || empty($tv_signtime) || empty($tv_sign)){
|
|
|
- $this->error('登录参数缺失');
|
|
|
- }
|
|
|
|
|
|
- //验签
|
|
|
- $salt = 'be7bcf1499b0fec801406f6aafbd04c4';
|
|
|
- $get_sign = md5(md5($tv_userid) . $tv_signtime . $salt);
|
|
|
- if($tv_sign != $get_sign){
|
|
|
- $this->error('验签失败');
|
|
|
- }
|
|
|
- if(time() - $tv_signtime > 300){
|
|
|
- $this->error('验签过期');
|
|
|
- }
|
|
|
-
|
|
|
- //找到用户
|
|
|
- $user = Db::name('user')->where('comefrom',2)->where('tv_userid',$tv_userid)->find();
|
|
|
- if ($user) {
|
|
|
- /*if ($user['status'] == -1) {
|
|
|
- $this->error('账号已注销');
|
|
|
- }
|
|
|
- if ($user['status'] != 1) {
|
|
|
- $this->error(__('Account is locked'));
|
|
|
- }*/
|
|
|
- //如果已经有账号则直接登录
|
|
|
- $ret = $this->auth->direct($user['id']);
|
|
|
- } else {
|
|
|
- $extend = ['tv_mobile'=>$tv_mobile];
|
|
|
- $ret = $this->auth->tv_register($tv_userid,$extend);
|
|
|
- }
|
|
|
-
|
|
|
- if ($ret) {
|
|
|
- $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
//用户详细资料
|
|
|
public function userInfo(){
|
|
@@ -288,7 +193,7 @@ class User extends Api
|
|
|
public function profile()
|
|
|
{
|
|
|
$field_array = [
|
|
|
- 'avatar','nickname','gender','tuijian_switch'
|
|
|
+ 'avatar','nickname'
|
|
|
];
|
|
|
|
|
|
$data = [];
|
|
@@ -308,19 +213,10 @@ class User extends Api
|
|
|
$newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
|
}
|
|
|
|
|
|
- if($field == 'nickname'){
|
|
|
- $newone = Keyworld::sensitive($newone);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
$data[$field] = $newone;
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
- if(isset($data['birthday'])){
|
|
|
- $data['birthday'] = strtotime($data['birthday']);
|
|
|
- }
|
|
|
-
|
|
|
if(empty($data)){
|
|
|
$this->success();
|
|
|
}
|
|
@@ -390,220 +286,5 @@ class User extends Api
|
|
|
$this->success('注销成功');
|
|
|
}
|
|
|
|
|
|
- //绑定盒子手机号
|
|
|
- public function bind_tv(){
|
|
|
- $tv_mobile = input('tv_mobile','');
|
|
|
- if(empty($tv_mobile)){
|
|
|
- $this->error();
|
|
|
- }
|
|
|
-
|
|
|
- //跨数据库查询
|
|
|
- $tv_user = Db::connect('database_tv')->name('hu_user')->where('mobile',$tv_mobile)->find();
|
|
|
- if(empty($tv_user)){
|
|
|
- $this->error('没有找到该终端用户');
|
|
|
- }
|
|
|
-
|
|
|
- $update = [
|
|
|
- 'tv_userid'=>$tv_user['id'],
|
|
|
- 'tv_mobile'=>$tv_user['mobile'],
|
|
|
- ];
|
|
|
- $rs = Db::name('user')->where('id',$this->auth->id)->update($update);
|
|
|
- if($rs === false){
|
|
|
- $this->error('绑定失败');
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('绑定成功');
|
|
|
- }
|
|
|
|
|
|
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改邮箱
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $email 邮箱
|
|
|
- * @param string $captcha 验证码
|
|
|
- */
|
|
|
- public function changeemail()
|
|
|
- {
|
|
|
- $user = $this->auth->getUser();
|
|
|
- $email = input('email');
|
|
|
- $captcha = input('captcha');
|
|
|
- if (!$email || !$captcha) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- if (!Validate::is($email, "email")) {
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
- }
|
|
|
- if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
|
|
- $this->error(__('Email already exists'));
|
|
|
- }
|
|
|
- $result = Ems::check($email, $captcha, 'changeemail');
|
|
|
- if (!$result) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- $verification = $user->verification;
|
|
|
- $verification->email = 1;
|
|
|
- $user->verification = $verification;
|
|
|
- $user->email = $email;
|
|
|
- $user->save();
|
|
|
-
|
|
|
- Ems::flush($email, 'changeemail');
|
|
|
- $this->success();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 第三方登录
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $platform 平台名称
|
|
|
- * @param string $code Code码
|
|
|
- */
|
|
|
- public function third()
|
|
|
- {
|
|
|
- $url = url('user/index');
|
|
|
- $platform = input("platform");
|
|
|
- $code = input("code");
|
|
|
- $config = get_addon_config('third');
|
|
|
- if (!$config || !isset($config[$platform])) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- $app = new \addons\third\library\Application($config);
|
|
|
- //通过code换access_token和绑定会员
|
|
|
- $result = $app->{$platform}->getUserInfo(['code' => $code]);
|
|
|
- if ($result) {
|
|
|
- $loginret = \addons\third\library\Service::connect($platform, $result);
|
|
|
- if ($loginret) {
|
|
|
- $data = [
|
|
|
- 'userinfo' => $this->auth->getUserinfo(),
|
|
|
- 'thirdinfo' => $result
|
|
|
- ];
|
|
|
- $this->success(__('Logged in successful'), $data);
|
|
|
- }
|
|
|
- }
|
|
|
- $this->error(__('Operation failed'), $url);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重置密码
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $mobile 手机号
|
|
|
- * @param string $newpassword 新密码
|
|
|
- * @param string $captcha 验证码
|
|
|
- */
|
|
|
- public function resetpwd()
|
|
|
- {
|
|
|
- $type = input("type", "mobile");
|
|
|
- $mobile = input("mobile");
|
|
|
- $email = input("email");
|
|
|
- $newpassword = input("newpassword");
|
|
|
- $captcha = input("captcha");
|
|
|
- if (!$newpassword || !$captcha) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- //验证Token
|
|
|
- if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
|
|
- $this->error(__('Password must be 6 to 30 characters'));
|
|
|
- }
|
|
|
- if ($type == 'mobile') {
|
|
|
- if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
- $this->error(__('Mobile is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByMobile($mobile);
|
|
|
- if (!$user) {
|
|
|
- $this->error(__('User not found'));
|
|
|
- }
|
|
|
- $ret = Sms::check($mobile, $captcha, 'resetpwd');
|
|
|
- if (!$ret) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- Sms::flush($mobile, 'resetpwd');
|
|
|
- } else {
|
|
|
- if (!Validate::is($email, "email")) {
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByEmail($email);
|
|
|
- if (!$user) {
|
|
|
- $this->error(__('User not found'));
|
|
|
- }
|
|
|
- $ret = Ems::check($email, $captcha, 'resetpwd');
|
|
|
- if (!$ret) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- Ems::flush($email, 'resetpwd');
|
|
|
- }
|
|
|
- //模拟一次登录
|
|
|
- $this->auth->direct($user->id);
|
|
|
- $ret = $this->auth->changepwd($newpassword, '', true);
|
|
|
- if ($ret) {
|
|
|
- $this->success(__('Reset password successful'));
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 会员登录
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $account 账号
|
|
|
- * @param string $password 密码
|
|
|
- */
|
|
|
- public function login()
|
|
|
- {
|
|
|
- $account = input('account');
|
|
|
- $password = input('password');
|
|
|
- if (!$account || !$password) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- $ret = $this->auth->login($account, $password);
|
|
|
- if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
- $this->success(__('Logged in successful'), $data);
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 注册会员
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $username 用户名
|
|
|
- * @param string $password 密码
|
|
|
- * @param string $email 邮箱
|
|
|
- * @param string $mobile 手机号
|
|
|
- * @param string $code 验证码
|
|
|
- */
|
|
|
- public function register()
|
|
|
- {
|
|
|
- $username = input('username');
|
|
|
- $password = input('password');
|
|
|
- $email = input('email');
|
|
|
- $mobile = input('mobile');
|
|
|
- $code = input('code');
|
|
|
- if (!$username || !$password) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- if ($email && !Validate::is($email, "email")) {
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
- }
|
|
|
- if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
- $this->error(__('Mobile is incorrect'));
|
|
|
- }
|
|
|
- $ret = Sms::check($mobile, $code, 'register');
|
|
|
- if (!$ret) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- $ret = $this->auth->register($username, $password, $email, $mobile, []);
|
|
|
- if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
- $this->success(__('Sign up successful'), $data);
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
}
|