feat: 完成独立的邀请与达人榜系统架构
This commit is contained in:
@@ -105,6 +105,16 @@ class AuthController extends Controller
|
||||
return response()->json(['status' => 'error', 'message' => '该用户名已被系统禁止注册,请更换其他名称。'], 422);
|
||||
}
|
||||
|
||||
// --- 提取邀请人 Cookie ---
|
||||
$inviterIdCookie = $request->cookie('inviter_id');
|
||||
$inviterId = null;
|
||||
if ($inviterIdCookie && is_numeric($inviterIdCookie)) {
|
||||
// 简单校验邀请人是否存在,防止脏数据
|
||||
if (User::where('id', $inviterIdCookie)->exists()) {
|
||||
$inviterId = (int) $inviterIdCookie;
|
||||
}
|
||||
}
|
||||
|
||||
$newUser = User::create([
|
||||
'username' => $username,
|
||||
'password' => Hash::make($password),
|
||||
@@ -113,10 +123,16 @@ class AuthController extends Controller
|
||||
'user_level' => 1, // 默认普通用户等级
|
||||
'sex' => $sex,
|
||||
'usersf' => '1.gif', // 默认头像
|
||||
'inviter_id' => $inviterId, // 记录邀请人
|
||||
]);
|
||||
|
||||
$this->performLogin($newUser, $ip);
|
||||
|
||||
// 如果是通过邀请注册的,响应成功后建议清除 Cookie,防止污染后续注册
|
||||
if ($inviterId) {
|
||||
\Illuminate\Support\Facades\Cookie::queue(\Illuminate\Support\Facades\Cookie::forget('inviter_id'));
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => '注册并登录成功!']);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user