|
@@ -3,8 +3,11 @@
|
|
|
namespace App\Modules\Mini\Controllers;
|
|
|
|
|
|
use App\Base\BaseController;
|
|
|
+use App\Base\Validation\Phone;
|
|
|
+use App\Exceptions\ClientException;
|
|
|
use App\Models\User\User;
|
|
|
use App\Modules\Mini\Services\AuthService;
|
|
|
+use App\Modules\Mini\Services\CaptchaService;
|
|
|
use App\Modules\Mini\Services\WechatService;
|
|
|
use App\Modules\Mini\Services\EmailService;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
@@ -96,19 +99,34 @@ class AuthController extends BaseController
|
|
|
|
|
|
public function register()
|
|
|
{
|
|
|
+ $params = $this->valid([
|
|
|
+ "email" => "required|email",
|
|
|
+ "phone" => ["required", new Phone()],
|
|
|
+ "password" => "required",
|
|
|
+ "captcha" => "required",
|
|
|
+ ]);
|
|
|
+ if (!app(CaptchaService::class)->checkCaptcha($params['email'], $params['captcha'])) {
|
|
|
+ throw new ClientException("验证码错误");
|
|
|
+ }
|
|
|
+ $user = app(AuthService::class)->register($params);
|
|
|
return $this->ok([
|
|
|
- "token" => "token",
|
|
|
- "name" => "",
|
|
|
- "phone" => "",
|
|
|
+ "token" => app(AuthService::class)->encryptToken($user->id),
|
|
|
+ "name" => $user->name,
|
|
|
+ "phone" => $user->phone,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public function login()
|
|
|
{
|
|
|
+ $params = $this->valid([
|
|
|
+ "userinfo" => "required",
|
|
|
+ "password" => "required",
|
|
|
+ ]);
|
|
|
+ $user = app(AuthService::class)->login($params);
|
|
|
return $this->ok([
|
|
|
- "token" => "token",
|
|
|
- "name" => "",
|
|
|
- "phone" => "",
|
|
|
+ "token" => app(AuthService::class)->encryptToken($user->id),
|
|
|
+ "name" => $user->name,
|
|
|
+ "phone" => $user->phone,
|
|
|
]);
|
|
|
}
|
|
|
|