|
@@ -5,9 +5,8 @@ namespace app\api\controller;
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\library\Ems;
|
|
|
use app\common\library\Sms;
|
|
|
-use fast\Random;
|
|
|
-use think\Config;
|
|
|
use think\Validate;
|
|
|
+use think\Db;
|
|
|
|
|
|
/**
|
|
|
* 会员接口
|
|
@@ -20,11 +19,6 @@ class User extends Api
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
-
|
|
|
- if (!Config::get('fastadmin.usercenter')) {
|
|
|
- $this->error(__('User center already closed'));
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -32,7 +26,6 @@ class User extends Api
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
- $this->success('', ['welcome' => $this->auth->nickname]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -51,7 +44,7 @@ class User extends Api
|
|
|
}
|
|
|
$ret = $this->auth->login($account, $password);
|
|
|
if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $data = $this->auth->getUserinfo_smiple();
|
|
|
$this->success(__('Logged in successful'), $data);
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
@@ -80,17 +73,17 @@ class User extends Api
|
|
|
}
|
|
|
$user = \app\common\model\User::getByMobile($mobile);
|
|
|
if ($user) {
|
|
|
- if ($user->status != 'normal') {
|
|
|
+ if ($user->status != 1) {
|
|
|
$this->error(__('Account is locked'));
|
|
|
}
|
|
|
//如果已经有账号则直接登录
|
|
|
$ret = $this->auth->direct($user->id);
|
|
|
} else {
|
|
|
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
|
|
+ $this->error('不存在的用户');
|
|
|
}
|
|
|
if ($ret) {
|
|
|
Sms::flush($mobile, 'mobilelogin');
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $data = $this->auth->getUserinfo_smiple();
|
|
|
$this->success(__('Logged in successful'), $data);
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
@@ -129,7 +122,7 @@ class User extends Api
|
|
|
}
|
|
|
$ret = $this->auth->register($username, $password, $email, $mobile, []);
|
|
|
if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $data = $this->auth->getUserinfo_smiple();
|
|
|
$this->success(__('Sign up successful'), $data);
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
@@ -149,6 +142,34 @@ class User extends Api
|
|
|
$this->success(__('Logout successful'));
|
|
|
}
|
|
|
|
|
|
+ //真注销
|
|
|
+ public function cancleuser(){
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ //退出im
|
|
|
+// $tenIm = new Tenim();
|
|
|
+// $tenIm->loginoutim($this->auth->id);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'status' => -1,
|
|
|
+ 'mobile' => 'close_'.$this->auth->mobile,
|
|
|
+ 'wechat_openid' => 'close_'.$this->auth->wechat_openid,
|
|
|
+// 'ios_user_id' => 'close_'.$this->auth->ios_user_id,
|
|
|
+ ];
|
|
|
+ Db::name('user')->where('id',$this->auth->id)->update($data);
|
|
|
+
|
|
|
+ $this->auth->logout();
|
|
|
+ $this->success('注销成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户详细资料
|
|
|
+ public function userinfo(){
|
|
|
+ $info = $this->auth->getUserinfo();
|
|
|
+
|
|
|
+ $this->success(__('success'),$info);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改会员个人信息
|
|
|
*
|
|
@@ -160,66 +181,42 @@ class User extends Api
|
|
|
*/
|
|
|
public function profile()
|
|
|
{
|
|
|
- $user = $this->auth->getUser();
|
|
|
- $username = $this->request->post('username');
|
|
|
- $nickname = $this->request->post('nickname');
|
|
|
- $bio = $this->request->post('bio');
|
|
|
- $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
|
- if ($username) {
|
|
|
- $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
|
|
- if ($exists) {
|
|
|
- $this->error(__('Username already exists'));
|
|
|
+ $field_array = ['nickname','avatar'];
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ foreach($field_array as $key => $field){
|
|
|
+
|
|
|
+ //前端传不了post,改了
|
|
|
+ /*if(!request()->has($field,'post')){
|
|
|
+ continue;
|
|
|
+ }*/
|
|
|
+ if(!input('?'.$field)){
|
|
|
+ continue;
|
|
|
}
|
|
|
- $user->username = $username;
|
|
|
- }
|
|
|
- if ($nickname) {
|
|
|
- $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
|
|
- if ($exists) {
|
|
|
- $this->error(__('Nickname already exists'));
|
|
|
+
|
|
|
+ $newone = input($field);
|
|
|
+
|
|
|
+ if($field == 'avatar'){
|
|
|
+ $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
|
}
|
|
|
- $user->nickname = $nickname;
|
|
|
- }
|
|
|
- $user->bio = $bio;
|
|
|
- $user->avatar = $avatar;
|
|
|
- $user->save();
|
|
|
- $this->success();
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 修改邮箱
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $email 邮箱
|
|
|
- * @param string $captcha 验证码
|
|
|
- */
|
|
|
- public function changeemail()
|
|
|
- {
|
|
|
- $user = $this->auth->getUser();
|
|
|
- $email = $this->request->post('email');
|
|
|
- $captcha = $this->request->post('captcha');
|
|
|
- if (!$email || !$captcha) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
+ $data[$field] = $newone;
|
|
|
}
|
|
|
- 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'));
|
|
|
+
|
|
|
+ if(empty($data)){
|
|
|
+ $this->success();
|
|
|
}
|
|
|
- $result = Ems::check($email, $captcha, 'changeemail');
|
|
|
- if (!$result) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
+
|
|
|
+ $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
|
|
|
+ if($update_rs === false){
|
|
|
+ $this->error('修改资料失败');
|
|
|
}
|
|
|
- $verification = $user->verification;
|
|
|
- $verification->email = 1;
|
|
|
- $user->verification = $verification;
|
|
|
- $user->email = $email;
|
|
|
- $user->save();
|
|
|
|
|
|
- Ems::flush($email, 'changeemail');
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 修改手机号
|
|
|
*
|
|
@@ -230,6 +227,7 @@ class User extends Api
|
|
|
public function changemobile()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
+
|
|
|
$mobile = $this->request->post('mobile');
|
|
|
$captcha = $this->request->post('captcha');
|
|
|
if (!$mobile || !$captcha) {
|
|
@@ -245,9 +243,7 @@ class User extends Api
|
|
|
if (!$result) {
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
- $verification = $user->verification;
|
|
|
- $verification->mobile = 1;
|
|
|
- $user->verification = $verification;
|
|
|
+
|
|
|
$user->mobile = $mobile;
|
|
|
$user->save();
|
|
|
|
|
@@ -255,36 +251,36 @@ class User extends Api
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 第三方登录
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $platform 平台名称
|
|
|
- * @param string $code Code码
|
|
|
- */
|
|
|
- public function third()
|
|
|
+ //修改密码
|
|
|
+ public function changepwd()
|
|
|
{
|
|
|
- $url = url('user/index');
|
|
|
- $platform = $this->request->post("platform");
|
|
|
- $code = $this->request->post("code");
|
|
|
- $config = get_addon_config('third');
|
|
|
- if (!$config || !isset($config[$platform])) {
|
|
|
+ $mobile = $this->auth->mobile;
|
|
|
+ $captcha = $this->request->post('captcha');
|
|
|
+ $newpassword = input('newpassword','');
|
|
|
+
|
|
|
+ if (!$mobile || !$captcha || !$newpassword) {
|
|
|
$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);
|
|
|
- }
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+ $result = Sms::check($mobile, $captcha, 'changepwd');
|
|
|
+ if (!$result) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
- $this->error(__('Operation failed'), $url);
|
|
|
+ if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
|
|
+ $this->error(__('Password must be 6 to 30 characters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $ret = $this->auth->changepwd($newpassword, '', true);
|
|
|
+ if ($ret) {
|
|
|
+ $this->success(__('Reset password successful'));
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ Sms::flush($mobile, 'changepwd');
|
|
|
+ $this->success();
|
|
|
}
|
|
|
|
|
|
/**
|