修改密码
This commit is contained in:
parent
881c48398d
commit
d0f649a337
@ -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']) {
|
||||
|
84
app/Domains/Company/Http/Controllers/AccountController.php
Normal file
84
app/Domains/Company/Http/Controllers/AccountController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace App\Domains\Company\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domains\Virtual\Services\CompanyAccountService;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
protected $request;
|
||||
protected $companyAccountService;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request, CompanyAccountService $companyAccountService)
|
||||
{
|
||||
$this->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, '修改成功');
|
||||
}
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
// Prefix: /api/companies
|
||||
$router->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']);
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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']) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user