diff --git a/app/Domains/Account/Services/AccountService.php b/app/Domains/Account/Services/AccountService.php index e6abec7d..e47e23b1 100644 --- a/app/Domains/Account/Services/AccountService.php +++ b/app/Domains/Account/Services/AccountService.php @@ -113,9 +113,9 @@ class AccountService extends Service implements JwtServiceContract DB::beginTransaction(); - if($attributes['password']){ + if ($attributes['password']) { $attributes['salt'] = Str::random(6); - $attributes['password'] = md5(md5($attributes['password']).$attributes['salt']); + $attributes['password'] = md5($attributes['password'].$attributes['salt']); } if (!$attributes['id']) { diff --git a/app/Domains/Company/Http/Controllers/AccountController.php b/app/Domains/Company/Http/Controllers/AccountController.php new file mode 100644 index 00000000..465cfd16 --- /dev/null +++ b/app/Domains/Company/Http/Controllers/AccountController.php @@ -0,0 +1,84 @@ +request = $request; + $this->companyAccountService = $companyAccountService; + $this->account = $request->user('company'); + } + + /** + * 修改密码. + * + * @return \Illuminate\Http\Response + */ + public function passwordByOld() + { + $oldPassword = $this->request->get('old_password'); + $password = $this->request->get('password'); + + if ($this->account->password !== md5($oldPassword . $this->account->salt)) { + return err('原密码不正确'); + } + + if ($this->account->password === md5($password . $this->account->salt)) { + return err('密码未修改'); + } + + $attributes = [ + 'id' => $this->account->id, + 'password' => $password, + ]; + + $account = $this->companyAccountService->store($attributes); + + return res($account, '修改成功'); + } + + /** + * 修改密码. + * + * @return \Illuminate\Http\Response + */ + public function password() + { + $attributes = [ + 'id' => $this->account->id, + 'password' => $this->request->get('password'), + ]; + + $account = $this->companyAccountService->store($attributes); + + return res($account, '修改成功'); + } + + /** + * 绑定手机. + * + * @return \Illuminate\Http\Response + */ + public function mobile() + { + $attributes = [ + 'id' => $this->account->id, + 'mobile' => $this->request->get('mobile'), + ]; + + $account = $this->companyAccountService->store($attributes); + + return res($account, '修改成功'); + } +} diff --git a/app/Domains/Company/Routes/api.php b/app/Domains/Company/Routes/api.php index 236110bc..6a3b6eb8 100644 --- a/app/Domains/Company/Routes/api.php +++ b/app/Domains/Company/Routes/api.php @@ -1,10 +1,13 @@ group(['prefix' => 'companies', 'as' => 'companies'], function($router) { +$router->group(['prefix' => 'companies', 'as' => 'companies', 'middleware' => ['companyAuth']], function ($router) { // The controllers live in Domains/Company/Http/Controllers - $router->get('/', ['as' => 'index', 'uses' => 'CompanyController@index']); + $router->get('/', ['as' => 'index', 'uses' => 'AccountController@index']); + $router->post('/account/password_by_old', ['as' => 'account.passwordByOld', 'uses' => 'AccountController@passwordByOld']); + $router->post('/account/password', ['as' => 'account.password', 'uses' => 'AccountController@password', 'middleware' => ['verify_code']]); + $router->post('/account/mobile', ['as' => 'account.mobile', 'uses' => 'AccountController@mobile', 'middleware' => ['verify_code']]); /** * 需要认证的接口 @@ -12,4 +15,4 @@ $router->group(['prefix' => 'companies', 'as' => 'companies'], function($router) // $router->group(['middleware' => ['adminAuth']], function($router) { // // $router->post('delete', ['as' => 'delete', 'uses' => 'CompanyController@delete']); // }); -}); \ No newline at end of file +}); diff --git a/app/Domains/Sms/Http/Middleware/VerifyCodeAuthenticate.php b/app/Domains/Sms/Http/Middleware/VerifyCodeAuthenticate.php index 6bd58d05..696403e6 100644 --- a/app/Domains/Sms/Http/Middleware/VerifyCodeAuthenticate.php +++ b/app/Domains/Sms/Http/Middleware/VerifyCodeAuthenticate.php @@ -14,9 +14,9 @@ class VerifyCodeAuthenticate { $mobile = $request->get('mobile', ''); - $verify_code = $request->get('verify_code', ''); + $verifyCode = $request->get('verify_code', ''); - app(SmsService::class)->verifyCode($mobile, $code); + app(SmsService::class)->verifyCode($mobile, $verifyCode); return $next($request); } diff --git a/app/Domains/Sms/Providers/MiddlewareServiceProvider.php b/app/Domains/Sms/Providers/MiddlewareServiceProvider.php index 801e6cc4..389791b3 100644 --- a/app/Domains/Sms/Providers/MiddlewareServiceProvider.php +++ b/app/Domains/Sms/Providers/MiddlewareServiceProvider.php @@ -24,6 +24,6 @@ class MiddlewareServiceProvider extends ServiceProvider * @var array */ protected $routeMiddleware = [ - 'verifyCode' => \App\Domains\Sms\Http\Middleware\VerifyCodeAuthenticate::class, + 'verify_code' => \App\Domains\Sms\Http\Middleware\VerifyCodeAuthenticate::class, ]; } diff --git a/app/Domains/Sms/Services/SmsService.php b/app/Domains/Sms/Services/SmsService.php index 99efb4a4..91f7db0b 100755 --- a/app/Domains/Sms/Services/SmsService.php +++ b/app/Domains/Sms/Services/SmsService.php @@ -71,14 +71,14 @@ class SmsService extends Service $freqsecs = 60; // 重试时间 - $code = rand(100000, 999999); + $verifyCode = rand(100000, 999999); $message = new VcodeMessage(['code' => $code, 'product' => $product]); $this->send($mobile, $message); Cache::put(self::$cacheVcodePrefix.$mobile, [ 'mobile' => $mobile, 'created_time' => time(), - 'vcode' => $code, + 'verify_code' => $verifyCode, 'freq' => $freqsecs, ], self::$cacheVcodeMinutes); @@ -90,13 +90,13 @@ class SmsService extends Service * * @return void */ - public function verifyCode($mobile, $code) + public function verifyCode($mobile, $verifyCode) { $key = self::$cacheVcodePrefix.$mobile; $cacheCode = Cache::get($key); - if ((!$cacheCode['verifycode'] || $cacheCode['verifycode'] != $code) && $code != 998877) { + if ((!$cacheCode['verify_code'] || $cacheCode['verify_code'] != $verifyCode) && $verifyCode != 998877) { throw new InvalidArgumentException('验证码错误, 请重新输入'); } else { Cache::forget($key); diff --git a/app/Domains/Virtual/Services/CompanyAccountService.php b/app/Domains/Virtual/Services/CompanyAccountService.php index cd6bc2c4..725243b0 100644 --- a/app/Domains/Virtual/Services/CompanyAccountService.php +++ b/app/Domains/Virtual/Services/CompanyAccountService.php @@ -97,7 +97,7 @@ class CompanyAccountService extends Service implements JwtServiceContract if ($attributes['password']) { $attributes['salt'] = Str::random(6); - $attributes['password'] = md5(md5($attributes['password']).$attributes['salt']); + $attributes['password'] = md5($attributes['password'].$attributes['salt']); } if (!$attributes['id']) {