fix(注册): 登记注册时,给手机号和邮箱加入校验

This commit is contained in:
Boen_Shi 2026-06-18 00:33:51 +08:00
parent 49a6411359
commit 47d4749afb
2 changed files with 23 additions and 2 deletions

View File

@ -104,7 +104,7 @@ class AuthController extends Controller
$validated = $request->validate([ $validated = $request->validate([
'nickname' => ['required', 'string', 'max:255'], 'nickname' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', 'unique:users,email'], 'email' => ['required', 'email', 'max:255', 'unique:users,email'],
'phone' => ['required', 'string', 'max:32', 'unique:users,phone'], 'phone' => ['required', 'string', 'regex:/^1[3-9]\d{9}$/', 'unique:users,phone'],
'password' => ['required', 'confirmed', Password::min(6)], 'password' => ['required', 'confirmed', Password::min(6)],
]); ]);

View File

@ -4,6 +4,8 @@ namespace Tests\Feature;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Tests\TestCase; use Tests\TestCase;
class SsoApiTest extends TestCase class SsoApiTest extends TestCase
@ -13,10 +15,14 @@ class SsoApiTest extends TestCase
public function test_user_can_login_and_get_jwt_token(): void public function test_user_can_login_and_get_jwt_token(): void
{ {
$password = 'secret123'; $password = 'secret123';
User::factory()->create([ $user = User::factory()->create([
'email' => 'admin@example.com', 'email' => 'admin@example.com',
'password' => bcrypt($password), 'password' => bcrypt($password),
]); ]);
$role = Role::query()->create(['name' => 'tester', 'guard_name' => 'api']);
$permission = Permission::query()->create(['name' => 'platform.dashboard.view', 'guard_name' => 'api']);
$role->givePermissionTo($permission);
$user->assignRole($role);
$response = $this->postJson('/auth/login', [ $response = $this->postJson('/auth/login', [
'email' => 'admin@example.com', 'email' => 'admin@example.com',
@ -28,4 +34,19 @@ class SsoApiTest extends TestCase
->assertJsonPath('code', 0) ->assertJsonPath('code', 0)
->assertJsonStructure(['data' => ['token', 'type', 'expires_in']]); ->assertJsonStructure(['data' => ['token', 'type', 'expires_in']]);
} }
public function test_apply_account_validates_email_and_phone_format(): void
{
$response = $this->postJson('/auth/apply-account', [
'nickname' => 'Tester',
'email' => 'bad-email',
'phone' => '12345',
'password' => 'secret123',
'password_confirmation' => 'secret123',
]);
$response
->assertStatus(422)
->assertJsonValidationErrors(['email', 'phone']);
}
} }