|
@@ -14,33 +14,29 @@ use App\Notifications\PasswordReset;
|
|
|
use App\Notifications\Verification;
|
|
|
use App\Utils\Helpers;
|
|
|
use App\Utils\IP;
|
|
|
-use Auth;
|
|
|
-use Cache;
|
|
|
-use Cookie;
|
|
|
use Hash;
|
|
|
use Hashids\Hashids;
|
|
|
+use Illuminate\Contracts\View\View;
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Notification;
|
|
|
-use Redirect;
|
|
|
-use Response;
|
|
|
use romanzipp\Turnstile\Rules\TurnstileCaptcha;
|
|
|
-use Session;
|
|
|
use Str;
|
|
|
use Validator;
|
|
|
|
|
|
class AuthController extends Controller
|
|
|
{
|
|
|
// 登录
|
|
|
- public function showLoginForm()
|
|
|
+ public function showLoginForm(): RedirectResponse|View
|
|
|
{
|
|
|
// 根据权限跳转
|
|
|
- if (Auth::check()) {
|
|
|
- if (Auth::getUser()->can('admin.index')) {
|
|
|
- return Redirect::route('admin.index');
|
|
|
+ if (auth()->check()) {
|
|
|
+ if (auth()->getUser()?->can('admin.index')) {
|
|
|
+ return redirect()->route('admin.index');
|
|
|
}
|
|
|
|
|
|
- return Redirect::route('home');
|
|
|
+ return redirect()->route('home');
|
|
|
}
|
|
|
|
|
|
return view('auth.login');
|
|
@@ -57,13 +53,13 @@ class AuthController extends Controller
|
|
|
}
|
|
|
|
|
|
// 验证账号并创建会话
|
|
|
- if (! Auth::attempt($data, $request->has('remember'))) {
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_failed'));
|
|
|
+ if (! auth()->attempt($data, $request->has('remember'))) {
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.error.login_failed'));
|
|
|
}
|
|
|
- $user = Auth::getUser();
|
|
|
+ $user = auth()->getUser();
|
|
|
|
|
|
if (! $user) {
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_error'));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.error.login_error'));
|
|
|
}
|
|
|
|
|
|
if ($user->can('admin.index')) {
|
|
@@ -72,22 +68,22 @@ class AuthController extends Controller
|
|
|
|
|
|
if ($request->routeIs('admin.login.post')) {
|
|
|
// 管理页面登录, 非权限者清场
|
|
|
- Auth::logout();
|
|
|
+ auth()->logout();
|
|
|
|
|
|
- return Redirect::route('login')->withErrors(trans('common.failed_item', ['attribute' => trans('auth.login')]));
|
|
|
+ return redirect()->route('login')->withErrors(trans('common.failed_item', ['attribute' => trans('auth.login')]));
|
|
|
}
|
|
|
|
|
|
// 校验普通用户账号状态
|
|
|
if ($user->status === -1) {
|
|
|
- Auth::logout(); // 强制销毁会话,因为Auth::attempt的时候会产生会话
|
|
|
+ auth()->logout(); // 强制销毁会话,因为Auth::attempt的时候会产生会话
|
|
|
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.error.account_baned'));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.error.account_baned'));
|
|
|
}
|
|
|
|
|
|
if ($user->status === 0 && sysConfig('is_activate_account')) {
|
|
|
- Auth::logout(); // 强制销毁会话,因为Auth::attempt的时候会产生会话
|
|
|
+ auth()->logout(); // 强制销毁会话,因为Auth::attempt的时候会产生会话
|
|
|
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.active.promotion',
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.active.promotion',
|
|
|
['action' => '<a href="'.route('active', ['username' => $user->username]).'" target="_blank">'.trans('common.active_item', ['attribute' => trans('common.account')]).'</a>']));
|
|
|
}
|
|
|
|
|
@@ -115,7 +111,7 @@ class AuthController extends Controller
|
|
|
$validator = Validator::make($request->all(), $rules[$captchaType]);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha.error.failed'));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.captcha.error.failed'));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -124,21 +120,21 @@ class AuthController extends Controller
|
|
|
|
|
|
public function logout(Request $request): RedirectResponse
|
|
|
{ // 退出
|
|
|
- Auth::logout();
|
|
|
+ auth()->logout();
|
|
|
$request->session()->invalidate();
|
|
|
$request->session()->regenerateToken();
|
|
|
|
|
|
- return Redirect::route('login');
|
|
|
+ return redirect()->route('login');
|
|
|
}
|
|
|
|
|
|
- public function showRegistrationForm()
|
|
|
+ public function showRegistrationForm(): View
|
|
|
{
|
|
|
- Session::put('register_token', Str::random());
|
|
|
+ session()->put('register_token', Str::random());
|
|
|
|
|
|
return view('auth.register', ['emailList' => (int) sysConfig('is_email_filtering') !== 2 ? false : EmailFilter::whereType(2)->get()]);
|
|
|
}
|
|
|
|
|
|
- public function register(RegisterRequest $request)
|
|
|
+ public function register(RegisterRequest $request): RedirectResponse
|
|
|
{ // 注册
|
|
|
$cacheKey = 'register_times_'.md5(IP::getClientIp()); // 注册限制缓存key
|
|
|
|
|
@@ -149,13 +145,13 @@ class AuthController extends Controller
|
|
|
$aff = $request->input('aff');
|
|
|
|
|
|
// 防止重复提交
|
|
|
- if ($register_token !== Session::pull('register_token')) {
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.error.repeat_request'));
|
|
|
+ if ($register_token !== session()->pull('register_token')) {
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.error.repeat_request'));
|
|
|
}
|
|
|
|
|
|
// 是否开启注册
|
|
|
if (! sysConfig('is_register')) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.register.error.disable'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.register.error.disable'));
|
|
|
}
|
|
|
|
|
|
// 校验域名邮箱黑白名单
|
|
@@ -171,22 +167,22 @@ class AuthController extends Controller
|
|
|
// 校验邀请码合法性
|
|
|
if ($invite_code) {
|
|
|
if (Invite::whereCode($invite_code)->whereStatus(0)->doesntExist()) {
|
|
|
- return Redirect::back()->withInput($request->except('code'))->withErrors(trans('auth.invite.unavailable'));
|
|
|
+ return redirect()->back()->withInput($request->except('code'))->withErrors(trans('auth.invite.unavailable'));
|
|
|
}
|
|
|
} elseif ((int) sysConfig('is_invite_register') === 2) { // 必须使用邀请码
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('validation.required', ['attribute' => trans('user.invite.attribute')]));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('validation.required', ['attribute' => trans('user.invite.attribute')]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 注册前发送激活码
|
|
|
if ((int) sysConfig('is_activate_account') === 1) {
|
|
|
if (! $verify_code) {
|
|
|
- return Redirect::back()->withInput($request->except('verify_code'))->withErrors(trans('auth.captcha.required'));
|
|
|
+ return redirect()->back()->withInput($request->except('verify_code'))->withErrors(trans('auth.captcha.required'));
|
|
|
}
|
|
|
|
|
|
$verifyCode = VerifyCode::whereAddress($data['username'])->whereCode($verify_code)->whereStatus(0)->first();
|
|
|
if (! $verifyCode) {
|
|
|
- return Redirect::back()->withInput($request->except('verify_code'))->withErrors(trans('auth.captcha.error.timeout'));
|
|
|
+ return redirect()->back()->withInput($request->except('verify_code'))->withErrors(trans('auth.captcha.error.timeout'));
|
|
|
}
|
|
|
|
|
|
$verifyCode->status = 1;
|
|
@@ -200,17 +196,17 @@ class AuthController extends Controller
|
|
|
}
|
|
|
|
|
|
// 24小时内同IP注册限制
|
|
|
- if (sysConfig('register_ip_limit') && Cache::has($cacheKey)) {
|
|
|
- $registerTimes = Cache::get($cacheKey);
|
|
|
+ if (sysConfig('register_ip_limit') && cache()->has($cacheKey)) {
|
|
|
+ $registerTimes = cache()->get($cacheKey);
|
|
|
if ($registerTimes >= sysConfig('register_ip_limit')) {
|
|
|
- return Redirect::back()->withInput($request->except('code'))->withErrors(trans('auth.register.error.throttle'));
|
|
|
+ return redirect()->back()->withInput($request->except('code'))->withErrors(trans('auth.register.error.throttle'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取可用端口
|
|
|
$port = Helpers::getPort();
|
|
|
if ($port > sysConfig('max_port')) {
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.register.error.disable'));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.register.error.disable'));
|
|
|
}
|
|
|
|
|
|
// 获取aff
|
|
@@ -221,26 +217,23 @@ class AuthController extends Controller
|
|
|
|
|
|
// 创建新用户
|
|
|
if (! $user = Helpers::addUser($data['username'], $data['password'], $transfer_enable, (int) sysConfig('default_days'), $inviter_id, $data['nickname'])) { // 注册失败,抛出异常
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.register.failed'));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.register.failed'));
|
|
|
}
|
|
|
|
|
|
// 注册次数+1
|
|
|
- if (Cache::has($cacheKey)) {
|
|
|
- Cache::increment($cacheKey);
|
|
|
+ if (cache()->has($cacheKey)) {
|
|
|
+ cache()->increment($cacheKey);
|
|
|
} else {
|
|
|
- Cache::put($cacheKey, 1, Day); // 24小时
|
|
|
+ cache()->put($cacheKey, 1, Day); // 24小时
|
|
|
}
|
|
|
|
|
|
// 更新邀请码
|
|
|
if ($affArr['code_id'] && sysConfig('is_invite_register')) {
|
|
|
- $invite = Invite::find($affArr['code_id']);
|
|
|
- if ($invite) {
|
|
|
- $invite->update(['invitee_id' => $user->id, 'status' => 1]);
|
|
|
- }
|
|
|
+ Invite::find($affArr['code_id'])?->update(['invitee_id' => $user->id, 'status' => 1]);
|
|
|
}
|
|
|
|
|
|
// 清除邀请人Cookie
|
|
|
- Cookie::unqueue('register_aff');
|
|
|
+ cookie()->unqueue('register_aff');
|
|
|
|
|
|
// 注册后发送激活码
|
|
|
if ((int) sysConfig('is_activate_account') === 2) {
|
|
@@ -250,7 +243,7 @@ class AuthController extends Controller
|
|
|
|
|
|
$user->notifyNow(new AccountActivation($activeUserUrl));
|
|
|
|
|
|
- Session::flash('successMsg',
|
|
|
+ session()->flash('successMsg',
|
|
|
__("Thank you for signing up! Before you start, you need to verify your email by clicking on the link we have just sent to your email! If you haven't received an email, we would be happy to send another one."));
|
|
|
} else {
|
|
|
// 则直接给推荐人加流量
|
|
@@ -265,13 +258,13 @@ class AuthController extends Controller
|
|
|
$user->update(['status' => 1]);
|
|
|
}
|
|
|
|
|
|
- Session::flash('successMsg', trans('common.success_item', ['attribute' => trans('auth.register.attribute')]));
|
|
|
+ session()->flash('successMsg', trans('common.success_item', ['attribute' => trans('auth.register.attribute')]));
|
|
|
}
|
|
|
|
|
|
- return Redirect::route('login')->withInput();
|
|
|
+ return redirect()->route('login')->withInput();
|
|
|
}
|
|
|
|
|
|
- private function emailChecker($email, $returnType = 0)
|
|
|
+ private function emailChecker(string $email, int $returnType = 0): RedirectResponse|JsonResponse|false
|
|
|
{ // 邮箱检查
|
|
|
$emailFilterList = EmailFilter::whereType(sysConfig('is_email_filtering'))->pluck('words')->toArray();
|
|
|
$emailSuffix = explode('@', $email); // 提取邮箱后缀
|
|
@@ -281,27 +274,27 @@ class AuthController extends Controller
|
|
|
case 1: // 黑名单
|
|
|
if (in_array(strtolower($emailSuffix[1]), $emailFilterList, true)) {
|
|
|
if ($returnType) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.email.error.banned'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.email.error.banned'));
|
|
|
}
|
|
|
|
|
|
- return Response::json(['status' => 'fail', 'message' => trans('auth.email.error.banned')]);
|
|
|
+ return response()->json(['status' => 'fail', 'message' => trans('auth.email.error.banned')]);
|
|
|
}
|
|
|
break;
|
|
|
case 2: // 白名单
|
|
|
if (! in_array(strtolower($emailSuffix[1]), $emailFilterList, true)) {
|
|
|
if ($returnType) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.email.error.invalid'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.email.error.invalid'));
|
|
|
}
|
|
|
|
|
|
- return Response::json(['status' => 'fail', 'message' => trans('auth.email.error.invalid')]);
|
|
|
+ return response()->json(['status' => 'fail', 'message' => trans('auth.email.error.invalid')]);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
if ($returnType) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.email.error.invalid'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.email.error.invalid'));
|
|
|
}
|
|
|
|
|
|
- return Response::json(['status' => 'fail', 'message' => trans('auth.email.error.invalid')]);
|
|
|
+ return response()->json(['status' => 'fail', 'message' => trans('auth.email.error.invalid')]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -347,7 +340,7 @@ class AuthController extends Controller
|
|
|
return $uid && User::whereId($uid)->exists() ? $uid : null;
|
|
|
}
|
|
|
|
|
|
- private function addVerifyUrl($uid, $email): string
|
|
|
+ private function addVerifyUrl(int $uid, string $email): string
|
|
|
{ // 生成申请的请求地址
|
|
|
$token = md5(sysConfig('website_name').$email.microtime());
|
|
|
$verify = new Verify;
|
|
@@ -358,21 +351,21 @@ class AuthController extends Controller
|
|
|
return $token;
|
|
|
}
|
|
|
|
|
|
- public function resetPassword(Request $request)
|
|
|
+ public function resetPassword(Request $request): RedirectResponse|View
|
|
|
{ // 重设密码页
|
|
|
if ($request->isMethod('POST')) {
|
|
|
// 校验请求
|
|
|
$validator = Validator::make($request->all(), ['username' => 'required|'.(sysConfig('username_type') ?? 'email').'|exists:user,username']);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
- return Redirect::back()->withInput()->withErrors($validator->errors());
|
|
|
+ return redirect()->back()->withInput()->withErrors($validator->errors());
|
|
|
}
|
|
|
|
|
|
$username = $request->input('username');
|
|
|
|
|
|
// 是否开启重设密码
|
|
|
if (! sysConfig('password_reset_notification')) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.password.reset.error.disabled', ['email' => sysConfig('webmaster_email')]));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.password.reset.error.disabled', ['email' => sysConfig('webmaster_email')]));
|
|
|
}
|
|
|
|
|
|
// 查找账号
|
|
@@ -380,10 +373,10 @@ class AuthController extends Controller
|
|
|
|
|
|
// 24小时内重设密码次数限制
|
|
|
$resetTimes = 0;
|
|
|
- if (Cache::has('resetPassword_'.md5($username))) {
|
|
|
- $resetTimes = Cache::get('resetPassword_'.md5($username));
|
|
|
+ if (cache()->has('resetPassword_'.md5($username))) {
|
|
|
+ $resetTimes = cache()->get('resetPassword_'.md5($username));
|
|
|
if ($resetTimes >= sysConfig('reset_password_times')) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.password.reset.error.throttle', ['time' => sysConfig('reset_password_times')]));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.password.reset.error.throttle', ['time' => sysConfig('reset_password_times')]));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -394,18 +387,18 @@ class AuthController extends Controller
|
|
|
$resetUrl = route('resettingPasswd', $token);
|
|
|
$user->notifyNow(new PasswordReset($resetUrl));
|
|
|
|
|
|
- Cache::put('resetPassword_'.md5($username), $resetTimes + 1, Day);
|
|
|
+ cache()->put('resetPassword_'.md5($username), $resetTimes + 1, Day);
|
|
|
|
|
|
- return Redirect::back()->with('successMsg', trans('auth.password.reset.sent'));
|
|
|
+ return redirect()->back()->with('successMsg', trans('auth.password.reset.sent'));
|
|
|
}
|
|
|
|
|
|
return view('auth.resetPassword');
|
|
|
}
|
|
|
|
|
|
- public function reset(Request $request, $token)
|
|
|
+ public function reset(Request $request, ?string $token): RedirectResponse|View
|
|
|
{ // 重设密码
|
|
|
if (! $token) {
|
|
|
- return Redirect::route('login');
|
|
|
+ return redirect()->route('login');
|
|
|
}
|
|
|
|
|
|
if ($request->isMethod('POST')) {
|
|
@@ -414,7 +407,7 @@ class AuthController extends Controller
|
|
|
]);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
- return Redirect::back()->withInput()->withErrors($validator->errors());
|
|
|
+ return redirect()->back()->withInput()->withErrors($validator->errors());
|
|
|
}
|
|
|
|
|
|
$password = $request->input('password');
|
|
@@ -422,36 +415,36 @@ class AuthController extends Controller
|
|
|
$verify = Verify::type(1)->whereToken($token)->firstOrFail();
|
|
|
$user = $verify->user;
|
|
|
if (! $verify) {
|
|
|
- return Redirect::route('login');
|
|
|
+ return redirect()->route('login');
|
|
|
}
|
|
|
|
|
|
if ($user->status === -1) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.error.account_baned'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.error.account_baned'));
|
|
|
}
|
|
|
|
|
|
if ($verify->status === 1) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.error.url_timeout'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.error.url_timeout'));
|
|
|
}
|
|
|
|
|
|
if (Hash::check($password, $verify->user->password)) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.password.reset.error.same'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.password.reset.error.same'));
|
|
|
}
|
|
|
|
|
|
// 更新密码
|
|
|
if (! $user->update(['password' => $password])) {
|
|
|
- return Redirect::back()->withErrors(trans('common.failed_item', ['attribute' => trans('auth.password.reset.attribute')]));
|
|
|
+ return redirect()->back()->withErrors(trans('common.failed_item', ['attribute' => trans('auth.password.reset.attribute')]));
|
|
|
}
|
|
|
|
|
|
// 置为已使用
|
|
|
$verify->status = 1;
|
|
|
$verify->save();
|
|
|
|
|
|
- return Redirect::route('login')->with('successMsg', trans('auth.password.reset.success'));
|
|
|
+ return redirect()->route('login')->with('successMsg', trans('auth.password.reset.success'));
|
|
|
}
|
|
|
|
|
|
$verify = Verify::type(1)->whereToken($token)->first();
|
|
|
if (! $verify) {
|
|
|
- return Redirect::route('login');
|
|
|
+ return redirect()->route('login');
|
|
|
}
|
|
|
|
|
|
if (time() - strtotime($verify->created_at) >= 1800) {
|
|
@@ -463,38 +456,38 @@ class AuthController extends Controller
|
|
|
return view('auth.reset', ['verify' => Verify::type(1)->whereToken($token)->first()]); // 重新获取一遍verify
|
|
|
}
|
|
|
|
|
|
- public function activeUser(Request $request)
|
|
|
+ public function activeUser(Request $request): RedirectResponse|View
|
|
|
{ // 激活账号页
|
|
|
if ($request->isMethod('POST')) {
|
|
|
$validator = Validator::make($request->all(), ['username' => 'required|'.(sysConfig('username_type') ?? 'email').'|exists:user,username']);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
- return Redirect::back()->withInput()->withErrors($validator->errors());
|
|
|
+ return redirect()->back()->withInput()->withErrors($validator->errors());
|
|
|
}
|
|
|
|
|
|
$username = $request->input('username');
|
|
|
|
|
|
// 是否开启账号激活
|
|
|
if (! sysConfig('is_activate_account')) {
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.active.error.disable'));
|
|
|
+ return redirect()->back()->withInput()->withErrors(trans('auth.active.error.disable'));
|
|
|
}
|
|
|
|
|
|
// 查找账号
|
|
|
$user = User::whereUsername($username)->firstOrFail();
|
|
|
if ($user->status === -1) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.error.account_baned'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.error.account_baned'));
|
|
|
}
|
|
|
|
|
|
if ($user->status === 1) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.active.error.activated'));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.active.error.activated'));
|
|
|
}
|
|
|
|
|
|
// 24小时内激活次数限制
|
|
|
$activeTimes = 0;
|
|
|
- if (Cache::has('activeUser_'.md5($username))) {
|
|
|
- $activeTimes = Cache::get('activeUser_'.md5($username));
|
|
|
+ if (cache()->has('activeUser_'.md5($username))) {
|
|
|
+ $activeTimes = cache()->get('activeUser_'.md5($username));
|
|
|
if ($activeTimes >= sysConfig('active_times')) {
|
|
|
- return Redirect::back()->withErrors(trans('auth.active.error.throttle', ['email' => sysConfig('webmaster_email')]));
|
|
|
+ return redirect()->back()->withErrors(trans('auth.active.error.throttle', ['email' => sysConfig('webmaster_email')]));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -506,40 +499,36 @@ class AuthController extends Controller
|
|
|
|
|
|
Notification::route('mail', $username)->notifyNow(new AccountActivation($activeUserUrl));
|
|
|
|
|
|
- Cache::put('activeUser_'.md5($username), $activeTimes + 1, Day);
|
|
|
+ cache()->put('activeUser_'.md5($username), $activeTimes + 1, Day);
|
|
|
|
|
|
- return Redirect::back()->with('successMsg', trans('auth.active.sent'));
|
|
|
+ return redirect()->back()->with('successMsg', trans('auth.active.sent'));
|
|
|
}
|
|
|
|
|
|
return view('auth.activeUser');
|
|
|
}
|
|
|
|
|
|
- public function active($token)
|
|
|
+ public function active(string $token): RedirectResponse|View
|
|
|
{ // 激活账号
|
|
|
- if (! $token) {
|
|
|
- return Redirect::route('login');
|
|
|
- }
|
|
|
-
|
|
|
$verify = Verify::type(1)->with('user')->whereToken($token)->firstOrFail();
|
|
|
$user = $verify->user;
|
|
|
if (! $verify) {
|
|
|
- return Redirect::route('login');
|
|
|
+ return redirect()->route('login');
|
|
|
}
|
|
|
|
|
|
if (empty($user) || $verify->status > 0) {
|
|
|
- Session::flash('errorMsg', trans('auth.error.url_timeout'));
|
|
|
+ session()->flash('errorMsg', trans('auth.error.url_timeout'));
|
|
|
|
|
|
return view('auth.active');
|
|
|
}
|
|
|
|
|
|
if ($user->status === 1) {
|
|
|
- Session::flash('errorMsg', trans('auth.active.error.activated'));
|
|
|
+ session()->flash('errorMsg', trans('auth.active.error.activated'));
|
|
|
|
|
|
return view('auth.active');
|
|
|
}
|
|
|
|
|
|
if (time() - strtotime($verify->created_at) >= 1800) {
|
|
|
- Session::flash('errorMsg', trans('auth.error.url_timeout'));
|
|
|
+ session()->flash('errorMsg', trans('auth.error.url_timeout'));
|
|
|
|
|
|
// 置为已失效
|
|
|
$verify->status = 2;
|
|
@@ -550,9 +539,9 @@ class AuthController extends Controller
|
|
|
|
|
|
// 更新账号状态
|
|
|
if (! $user->update(['status' => 1])) {
|
|
|
- Session::flash('errorMsg', trans('common.active_item', ['attribute' => trans('common.failed')]));
|
|
|
+ session()->flash('errorMsg', trans('common.active_item', ['attribute' => trans('common.failed')]));
|
|
|
|
|
|
- return Redirect::back();
|
|
|
+ return redirect()->back();
|
|
|
}
|
|
|
|
|
|
// 置为已使用
|
|
@@ -565,17 +554,17 @@ class AuthController extends Controller
|
|
|
$inviter->incrementData(sysConfig('referral_traffic') * MiB);
|
|
|
}
|
|
|
|
|
|
- Session::flash('successMsg', trans('common.active_item', ['attribute' => trans('common.success')]));
|
|
|
+ session()->flash('successMsg', trans('common.active_item', ['attribute' => trans('common.success')]));
|
|
|
|
|
|
return view('auth.active');
|
|
|
}
|
|
|
|
|
|
- public function sendCode(Request $request)
|
|
|
+ public function sendCode(Request $request): JsonResponse
|
|
|
{ // 发送注册验证码
|
|
|
$validator = Validator::make($request->all(), ['username' => 'required|'.(sysConfig('username_type') ?? 'email').'|unique:user,username']);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
- return Response::json(['status' => 'fail', 'message' => $validator->getMessageBag()->first()]);
|
|
|
+ return response()->json(['status' => 'fail', 'message' => $validator->getMessageBag()->first()]);
|
|
|
}
|
|
|
$email = $request->input('username');
|
|
|
$ip = IP::getClientIP();
|
|
@@ -590,12 +579,12 @@ class AuthController extends Controller
|
|
|
|
|
|
// 是否开启注册发送验证码
|
|
|
if ((int) sysConfig('is_activate_account') !== 1) {
|
|
|
- return Response::json(['status' => 'fail', 'message' => trans('auth.active.error.disable')]);
|
|
|
+ return response()->json(['status' => 'fail', 'message' => trans('auth.active.error.disable')]);
|
|
|
}
|
|
|
|
|
|
// 防刷机制
|
|
|
- if (Cache::has('send_verify_code_'.md5($ip))) {
|
|
|
- return Response::json(['status' => 'fail', 'message' => trans('auth.register.error.throttle')]);
|
|
|
+ if (cache()->has('send_verify_code_'.md5($ip))) {
|
|
|
+ return response()->json(['status' => 'fail', 'message' => trans('auth.register.error.throttle')]);
|
|
|
}
|
|
|
|
|
|
// 发送邮件
|
|
@@ -604,12 +593,12 @@ class AuthController extends Controller
|
|
|
Notification::route('mail', $email)->notifyNow(new Verification($code));
|
|
|
}
|
|
|
|
|
|
- Cache::put('send_verify_code_'.md5($ip), $ip, Minute);
|
|
|
+ cache()->put('send_verify_code_'.md5($ip), $ip, Minute);
|
|
|
|
|
|
- return Response::json(['status' => 'success', 'message' => trans('auth.captcha.sent')]);
|
|
|
+ return response()->json(['status' => 'success', 'message' => trans('auth.captcha.sent')]);
|
|
|
}
|
|
|
|
|
|
- public function free()
|
|
|
+ public function free(): View
|
|
|
{ // 公开的邀请码列表
|
|
|
return view('auth.free', ['inviteList' => Invite::whereInviterId(null)->whereStatus(0)->paginate()]);
|
|
|
}
|
|
@@ -617,9 +606,9 @@ class AuthController extends Controller
|
|
|
public function switchLang(string $locale): RedirectResponse
|
|
|
{ // 切换语言
|
|
|
if (array_key_exists($locale, config('common.language'))) {
|
|
|
- Session::put('locale', $locale);
|
|
|
+ session()->put('locale', $locale);
|
|
|
}
|
|
|
|
|
|
- return Redirect::back();
|
|
|
+ return redirect()->back();
|
|
|
}
|
|
|
}
|