123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938 |
- <?php
- namespace App\Http\Controllers;
- use App\Components\Helpers;
- use App\Components\IP;
- use App\Http\Requests\Auth\RegisterRequest;
- use App\Models\EmailFilter;
- use App\Models\Invite;
- use App\Models\User;
- use App\Models\UserLoginLog;
- use App\Models\Verify;
- use App\Models\VerifyCode;
- use App\Notifications\AccountActivation;
- use App\Notifications\PasswordReset;
- use App\Notifications\Verification;
- use Auth;
- use Cache;
- use Captcha;
- use Cookie;
- use Hash;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Log;
- use Notification;
- use Redirect;
- use Response;
- use Session;
- use Str;
- use Validator;
- class AuthController extends Controller
- {
-
- public function showLoginForm()
- {
-
- if (Auth::check()) {
- if (Auth::getUser()->can('admin.index')) {
- return Redirect::route('admin.index');
- }
- return Redirect::route('home');
-
- }
- return view('auth.login');
- }
- public function login(Request $request)
- {
- $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
-
- $captcha = $this->check_captcha($request);
- if ($captcha !== false) {
- return $captcha;
- }
-
- if (! Auth::attempt($validator->validated(), $request->input('remember'))) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_failed'));
- }
- $user = Auth::getUser();
- if (! $user) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_error'));
- }
- if ($request->routeIs('admin.login.post') && $user->cannot('admin.index')) {
-
-
- Auth::logout();
- return Redirect::route('login');
- }
-
- if ($user->status === -1) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.error.account_baned'));
- }
- if ($user->status === 0 && sysConfig('is_activate_account')) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.active.promotion.0').'<a href="'.route('active').'?email='.$user->email.
- '" target="_blank">👉【'.trans('common.active_item', ['attribute' => trans('common.account')]).'】👈</span></a><br>'.trans('auth.active.promotion.1'));
- }
-
-
-
-
- $this->addUserLoginLog($user->id, IP::getClientIp());
-
- $user->update(['last_login' => time()]);
- return redirect()->back();
- }
- public function logina(Request $request)
- {
- $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
-
- $captcha = $this->check_captcha($request);
- if ($captcha !== false) {
- return $captcha;
- }
-
- if (! Auth::attempt($validator->validated(), $request->input('remember'))) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_failed'));
- }
- $user = Auth::getUser();
- if (! $user) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_error'));
- }
- if ($request->routeIs('admin.login.post') && $user->cannot('admin.index')) {
-
-
- Auth::logout();
- return Redirect::route('login');
- }
-
- if ($user->status === -1) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.error.account_baned'));
- }
- if ($user->status === 0 && sysConfig('is_activate_account')) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.active.promotion.0').'<a href="'.route('active').'?email='.$user->email.
- '" target="_blank">👉【'.trans('common.active_item', ['attribute' => trans('common.account')]).'】👈</span></a><br>'.trans('auth.active.promotion.1'));
- }
-
- $this->addUserLoginLog($user->id, IP::getClientIp());
-
- $user->update(['last_login' => time()]);
- return Redirect::route('shop');
- }
-
- public function logintoticket(Request $request)
- {
- $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
-
- $captcha = $this->check_captcha($request);
- if ($captcha !== false) {
- return $captcha;
- }
-
- if (! Auth::attempt($validator->validated(), $request->input('remember'))) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_failed'));
- }
- $user = Auth::getUser();
- if (! $user) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_error'));
- }
- if ($request->routeIs('admin.login.post') && $user->cannot('admin.index')) {
-
-
- Auth::logout();
- return Redirect::route('login');
- }
-
- if ($user->status === -1) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.error.account_baned'));
- }
- if ($user->status === 0 && sysConfig('is_activate_account')) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.active.promotion.0').'<a href="'.route('active').'?email='.$user->email.
- '" target="_blank">👉【'.trans('common.active_item', ['attribute' => trans('common.account')]).'】👈</span></a><br>'.trans('auth.active.promotion.1'));
- }
-
- $this->addUserLoginLog($user->id, IP::getClientIp());
-
- $user->update(['last_login' => time()]);
- return Redirect::route('ticket');
- }
-
- public function Loginprofile(Request $request)
- {
- $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
-
- $captcha = $this->check_captcha($request);
- if ($captcha !== false) {
- return $captcha;
- }
-
- if (! Auth::attempt($validator->validated(), $request->input('remember'))) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_failed'));
- }
- $user = Auth::getUser();
- if (! $user) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_error'));
- }
- if ($request->routeIs('admin.login.post') && $user->cannot('admin.index')) {
-
-
- Auth::logout();
- return Redirect::route('login');
- }
-
- if ($user->status === -1) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.error.account_baned'));
- }
- if ($user->status === 0 && sysConfig('is_activate_account')) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.active.promotion.0').'<a href="'.route('active').'?email='.$user->email.
- '" target="_blank">👉【'.trans('common.active_item', ['attribute' => trans('common.account')]).'】👈</span></a><br>'.trans('auth.active.promotion.1'));
- }
-
- $this->addUserLoginLog($user->id, IP::getClientIp());
-
- $user->update(['last_login' => time()]);
- return Redirect::route('profile');
- }
-
- public function logintoreferral(Request $request)
- {
- $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
-
- $captcha = $this->check_captcha($request);
- if ($captcha !== false) {
- return $captcha;
- }
-
- if (! Auth::attempt($validator->validated(), $request->input('remember'))) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_failed'));
- }
- $user = Auth::getUser();
- if (! $user) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.login_error'));
- }
- if ($request->routeIs('admin.login.post') && $user->cannot('admin.index')) {
-
-
- Auth::logout();
- return Redirect::route('login');
- }
-
- if ($user->status === -1) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.error.account_baned'));
- }
- if ($user->status === 0 && sysConfig('is_activate_account')) {
- Auth::logout();
- return Redirect::back()->withInput()->withErrors(trans('auth.active.promotion.0').'<a href="'.route('active').'?email='.$user->email.
- '" target="_blank">👉【'.trans('common.active_item', ['attribute' => trans('common.account')]).'】👈</span></a><br>'.trans('auth.active.promotion.1'));
- }
-
- $this->addUserLoginLog($user->id, IP::getClientIp());
-
- $user->update(['last_login' => time()]);
- return Redirect::route('commission');
- }
-
- private function check_captcha(Request $request)
- {
- switch (sysConfig('is_captcha')) {
- case 1:
- if (! Captcha::check($request->input('captcha'))) {
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha.error.failed'));
- }
- break;
- case 2:
- $validator = Validator::make($request->all(), [
- 'geetest_challenge' => 'required|geetest',
- ]);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha.error.failed'));
- }
- break;
- case 3:
- $validator = Validator::make($request->all(), [
- 'g-recaptcha-response' => 'required|NoCaptcha',
- ]);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha.error.failed'));
- }
- break;
- case 4:
- $validator = Validator::make($request->all(), [
- 'h-captcha-response' => 'required|HCaptcha',
- ]);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha.error.failed'));
- }
- break;
- default:
- break;
- }
- return false;
- }
-
- public function addUserLoginLog(int $userId, string $ip): void
- {
- $ipInfo = IP::getIPInfo($ip);
- UserLoginLog::create([
- 'user_id' => $userId,
- 'ip' => $ip,
- 'country' => $ipInfo['country'] ?? '',
- 'province' => $ipInfo['province'] ?? '',
- 'city' => $ipInfo['city'] ?? '',
- 'county' => $ipInfo['county'] ?? '',
- 'isp' => $ipInfo['isp'] ?? '',
- 'area' => $ipInfo['area'] ?? '',
- ]);
- }
-
- public function logout(): RedirectResponse
- {
- Auth::logout();
- return Redirect::route('login');
- }
- public function showRegistrationForm()
- {
- 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)
- {
- $cacheKey = 'register_times_'.md5(IP::getClientIp());
- $validator = Validator::make($request->all(), [
- 'username' => 'required',
- 'email' => 'required|email|unique:user',
- 'password' => 'required|min:6|confirmed',
- 'term' => 'accepted',
- ]);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
- $data = $request->validated();
- $register_token = $request->input('register_token');
- $code = $request->input('code');
- $verify_code = $request->input('verify_code');
- $aff = (int) $request->input('aff');
-
- if ($register_token !== Session::get('register_token')) {
- return Redirect::back()->withInput()->withErrors(trans('auth.error.repeat_request'));
- }
- Session::forget('register_token');
- if ($aff < 0){
- var_dump($aff);
- die();
- }
- Session::put("register_aff",strval($aff));
-
- if (! sysConfig('is_register')) {
- return Redirect::back()->withErrors(trans('auth.register.error.disable'));
- }
-
- if (sysConfig('is_email_filtering')) {
- $result = $this->emailChecker($data['email'], 1);
- if ($result !== false) {
- return $result;
- }
- }
-
- if (sysConfig('is_invite_register')) {
-
- if ($code) {
- if (Invite::whereCode($code)->whereStatus(0)->doesntExist()) {
- return Redirect::back()->withInput($request->except('code'))->withErrors(trans('auth.invite.error.unavailable'));
- }
- } elseif ((int) sysConfig('is_invite_register') === 2) {
- return Redirect::back()->withInput()->withErrors(trans('validation.required', ['attribute' => trans('auth.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'));
- }
- $verifyCode = VerifyCode::whereAddress($data['email'])->whereCode($verify_code)->whereStatus(0)->first();
- if (! $verifyCode) {
- return Redirect::back()->withInput($request->except('verify_code'))->withErrors(trans('auth.captcha.error.timeout'));
- }
- $verifyCode->status = 1;
- $verifyCode->save();
- }
-
- $captcha = $this->check_captcha($request);
- if ($captcha !== false) {
- return $captcha;
- }
-
- 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'));
- }
- }
-
- $port = Helpers::getPort();
- if ($port > sysConfig('max_port')) {
- return Redirect::back()->withInput()->withErrors(trans('auth.register.error.disable'));
- }
-
- $affArr = $this->getAff($code, $aff);
- $inviter_id = $affArr['inviter_id'];
- $transfer_enable = MB * ((int) sysConfig('default_traffic') + ($inviter_id ? (int) sysConfig('referral_traffic') : 0));
-
- $user = Helpers::addUser($data['email'], $data['password'], $transfer_enable, sysConfig('default_days'), $inviter_id, $data['username']);
-
- if (! $user) {
- return Redirect::back()->withInput()->withErrors(trans('auth.register.failed'));
- }
-
- if (Cache::has($cacheKey)) {
- Cache::increment($cacheKey);
- } else {
- Cache::put($cacheKey, 1, Day);
- }
-
- if ($affArr['code_id'] && sysConfig('is_invite_register')) {
- $invite = Invite::find($affArr['code_id']);
- if ($invite) {
- $invite->update(['invitee_id' => $user->id, 'status' => 1]);
- }
- }
-
- Cookie::unqueue('register_aff');
-
- if ((int) sysConfig('is_activate_account') === 2) {
-
- $token = $this->addVerifyUrl($user->id, $user->email);
- $activeUserUrl = route('activeAccount', $token);
- $user->notifyNow(new AccountActivation($activeUserUrl));
- Session::flash('successMsg',
- __("Thanks for signing up! Before getting started, could you verify your email address by clicking on the link we just emailed to you? If you didn't receive the email, we will gladly send you another."));
- } else {
-
- if ($inviter_id) {
- $referralUser = User::find($inviter_id);
- if ($referralUser && $referralUser->expired_at >= date('Y-m-d')) {
- $referralUser->incrementData(sysConfig('referral_traffic') * MB);
- }
- }
- if ((int) sysConfig('is_activate_account') === 1) {
- $user->update(['status' => 1]);
- }
- Session::flash('successMsg', trans('auth.register.success'));
- }
- return Redirect::route('login')->withInput();
- }
-
- private function emailChecker($email, $returnType = 0)
- {
- $emailFilterList = EmailFilter::whereType(sysConfig('is_email_filtering'))->pluck('words')->toArray();
- $emailSuffix = explode('@', $email);
- switch (sysConfig('is_email_filtering')) {
-
- case 1:
- if (in_array(strtolower($emailSuffix[1]), $emailFilterList, true)) {
- if ($returnType) {
- return Redirect::back()->withErrors(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 Response::json(['status' => 'fail', 'message' => trans('auth.email.error.invalid')]);
- }
- break;
- default:
- if ($returnType) {
- return Redirect::back()->withErrors(trans('auth.email.error.invalid'));
- }
- return Response::json(['status' => 'fail', 'message' => trans('auth.email.error.invalid')]);
- }
- return false;
- }
-
- private function getAff($code = null, $aff = null): array
- {
- $data = ['inviter_id' => null, 'code_id' => 0];
-
- if ($code) {
- $inviteCode = Invite::whereCode($code)->whereStatus(0)->first();
- if ($inviteCode) {
- $data['inviter_id'] = $inviteCode->inviter_id;
- $data['code_id'] = $inviteCode->id;
- }
- }
-
- if (! $data['inviter_id']) {
-
- $data['inviter_id'] = User::find($aff) ? $aff : null;
- }
- return $data;
- }
-
- private function addVerifyUrl($uid, $email)
- {
- $token = md5(sysConfig('website_name').$email.microtime());
- $verify = new Verify();
- $verify->user_id = $uid;
- $verify->token = $token;
- $verify->save();
- return $token;
- }
-
- public function resetPassword(Request $request)
- {
- if ($request->isMethod('POST')) {
-
- $validator = Validator::make($request->all(), [
- 'email' => 'required|email|exists:user,email',
- ]);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
- $email = $request->input('email');
-
- if (! sysConfig('password_reset_notification')) {
- return Redirect::back()->withErrors(trans('auth.password.reset.error.disabled', ['email' => sysConfig('webmaster_email')]));
- }
-
- $user = User::whereEmail($email)->firstOrFail();
-
- $resetTimes = 0;
- if (Cache::has('resetPassword_'.md5($email))) {
- $resetTimes = Cache::get('resetPassword_'.md5($email));
- if ($resetTimes >= sysConfig('reset_password_times')) {
- return Redirect::back()->withErrors(trans('auth.password.reset.error.throttle', ['time' => sysConfig('reset_password_times')]));
- }
- }
-
- $token = $this->addVerifyUrl($user->id, $email);
-
- $resetUrl = route('resettingPasswd', $token);
- $user->notifyNow(new PasswordReset($resetUrl));
- Cache::put('resetPassword_'.md5($email), $resetTimes + 1, Day);
- return Redirect::back()->with('successMsg', trans('auth.password.reset.sent'));
- }
- return view('auth.resetPassword');
- }
-
- public function reset(Request $request, $token)
- {
- if (! $token) {
- return Redirect::route('login');
- }
- if ($request->isMethod('POST')) {
- $validator = Validator::make($request->all(), [
- 'password' => 'required|min:6|confirmed',
- ]);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
- $password = $request->input('password');
-
- $verify = Verify::type(1)->whereToken($token)->firstOrFail();
- $user = $verify->user;
- if (! $verify) {
- return Redirect::route('login');
- }
- if ($user->status === -1) {
- return Redirect::back()->withErrors(trans('auth.error.account_baned'));
- }
- if ($verify->status === 1) {
- 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'));
- }
-
- if (! $user->update(['password' => $password])) {
- return Redirect::back()->withErrors(trans('auth.password.reset.error.failed'));
- }
-
- $verify->status = 1;
- $verify->save();
- return Redirect::route('login')->with('successMsg', trans('auth.password.reset.success'));
- }
- $verify = Verify::type(1)->whereToken($token)->first();
- if (! $verify) {
- return Redirect::route('login');
- }
- if (time() - strtotime($verify->created_at) >= 1800) {
-
- $verify->status = 2;
- $verify->save();
- }
- return view('auth.reset', ['verify' => Verify::type(1)->whereToken($token)->first()]);
- }
-
- public function activeUser(Request $request)
- {
- if ($request->isMethod('POST')) {
- $validator = Validator::make($request->all(), ['email' => 'required|email|exists:user,email']);
- if ($validator->fails()) {
- return Redirect::back()->withInput()->withErrors($validator->errors());
- }
- $email = $request->input('email');
-
- if (! sysConfig('is_activate_account')) {
- return Redirect::back()->withInput()->withErrors(trans('auth.active.error.disable'));
- }
-
- $user = User::whereEmail($email)->firstOrFail();
- if ($user->status === -1) {
- return Redirect::back()->withErrors(trans('auth.error.account_baned'));
- }
- if ($user->status === 1) {
- return Redirect::back()->withErrors(trans('auth.active.error.activated'));
- }
-
- $activeTimes = 0;
- if (Cache::has('activeUser_'.md5($email))) {
- $activeTimes = Cache::get('activeUser_'.md5($email));
- if ($activeTimes >= sysConfig('active_times')) {
- return Redirect::back()->withErrors(trans('auth.active.error.throttle', ['email' => sysConfig('webmaster_email')]));
- }
- }
-
- $token = $this->addVerifyUrl($user->id, $email);
-
- $activeUserUrl = route('activeAccount', $token);
- Notification::route('mail', $email)->notifyNow(new AccountActivation($activeUserUrl));
- Cache::put('activeUser_'.md5($email), $activeTimes + 1, Day);
- return Redirect::back()->with('successMsg', trans('auth.active.sent'));
- }
- return view('auth.activeUser');
- }
-
- public function active($token)
- {
- if (! $token) {
- return Redirect::route('login');
- }
- $verify = Verify::type(1)->with('user')->whereToken($token)->firstOrFail();
- $user = $verify->user;
- if (! $verify) {
- return Redirect::route('login');
- }
- if (empty($user) || $verify->status > 0) {
- Session::flash('errorMsg', trans('auth.error.url_timeout'));
- return view('auth.active');
- }
- if ($user->status === 1) {
- 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'));
-
- $verify->status = 2;
- $verify->save();
- return view('auth.active');
- }
-
- if (! $user->update(['status' => 1])) {
- Session::flash('errorMsg', trans('common.active_item', ['attribute' => trans('common.failed')]));
- return Redirect::back();
- }
-
- $verify->status = 1;
- $verify->save();
-
- $inviter = $user->inviter;
- if ($inviter) {
- $inviter->incrementData(sysConfig('referral_traffic') * MB);
- }
- Session::flash('successMsg', trans('common.active_item', ['attribute' => trans('common.success')]));
- return view('auth.active');
- }
-
- public function sendCode(Request $request)
- {
- $validator = Validator::make($request->all(), ['email' => 'required|email|unique:user,email']);
- $email = $request->input('email');
- if ($validator->fails()) {
- return Response::json(['status' => 'fail', 'message' => $validator->getMessageBag()->first()]);
- }
- $ip = IP::getClientIP();
-
- if (sysConfig('is_email_filtering')) {
- $result = $this->emailChecker($email);
- if ($result !== false) {
- return $result;
- }
- }
-
- if ((int) sysConfig('is_activate_account') !== 1) {
- 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')]);
- }
-
- $code = Str::random(6);
- if (VerifyCode::create(['address' => $email, 'code' => $code])) {
- Notification::route('mail', $email)->notifyNow(new Verification($code));
- }
- Cache::put('send_verify_code_'.md5($ip), $ip, Minute);
- return Response::json(['status' => 'success', 'message' => trans('auth.captcha.sent')]);
- }
-
- public function free()
- {
- return view('auth.free', ['inviteList' => Invite::whereInviterId(null)->whereStatus(0)->paginate()]);
- }
-
- public function switchLang(string $locale): RedirectResponse
- {
- Session::put('locale', $locale);
- return Redirect::back();
- }
- }
|