|
@@ -57,10 +57,15 @@ class AuthController extends Controller
|
|
|
'password.required' => trans('auth.password_null')
|
|
|
]);
|
|
|
|
|
|
+ $username = $request->input('username');
|
|
|
+ $captcha = $request->input('captcha');
|
|
|
+ $password = $request->input('password');
|
|
|
+ $remember = $request->input('remember');
|
|
|
+
|
|
|
// 是否校验验证码
|
|
|
switch(self::$systemConfig['is_captcha']){
|
|
|
case 1: // 默认图形验证码
|
|
|
- if(!Captcha::check($request->captcha)){
|
|
|
+ if(!Captcha::check($captcha)){
|
|
|
return Redirect::back()->withInput()->withErrors(trans('auth.captcha_error'));
|
|
|
}
|
|
|
break;
|
|
@@ -89,7 +94,7 @@ class AuthController extends Controller
|
|
|
}
|
|
|
|
|
|
// 验证账号并创建会话
|
|
|
- if(!Auth::attempt(['username' => $request->username, 'password' => $request->password], $request->remember)){
|
|
|
+ if(!Auth::attempt(['username' => $username, 'password' => $password], $remember)){
|
|
|
return Redirect::back()->withInput()->withErrors(trans('auth.login_error'));
|
|
|
}
|
|
|
|
|
@@ -98,13 +103,11 @@ class AuthController extends Controller
|
|
|
if(Auth::user()->status < 0){
|
|
|
Auth::logout(); // 强制销毁会话,因为Auth::attempt的时候会产生会话
|
|
|
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.login_ban', ['email' => self::$systemConfig['admin_email']]));
|
|
|
- }
|
|
|
-
|
|
|
- if(Auth::user()->status == 0 && self::$systemConfig['is_active_register']){
|
|
|
+ return Redirect::back()->withInput()->withErrors(trans('auth.login_ban', ['email' => self::$systemConfig['webmaster_email']]));
|
|
|
+ }elseif(Auth::user()->status == 0 && (self::$systemConfig['is_active_register'] || self::$systemConfig['is_verify_register'])){
|
|
|
Auth::logout(); // 强制销毁会话,因为Auth::attempt的时候会产生会话
|
|
|
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.active_tip').'<a href="/activeUser?username='.$request->username.'" target="_blank"><span style="color:#000">【'.trans('auth.active_account').'】</span></a>');
|
|
|
+ return Redirect::back()->withInput()->withErrors(trans('auth.active_tip').'<a href="/activeUser?username='.$username.'" target="_blank"><span style="color:#000">【'.trans('auth.active_account').'】</span></a>');
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -133,8 +136,56 @@ class AuthController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加用户登录日志
|
|
|
+ *
|
|
|
+ * @param string $userId 用户ID
|
|
|
+ * @param string $ip IP地址
|
|
|
+ */
|
|
|
+ private function addUserLoginLog($userId, $ip)
|
|
|
+ {
|
|
|
+ if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
|
|
|
+ Log::info('识别到IPv6,尝试解析:'.$ip);
|
|
|
+ $ipInfo = getIPv6($ip);
|
|
|
+ }else{
|
|
|
+ $ipInfo = QQWry::ip($ip); // 通过纯真IP库解析IPv4信息
|
|
|
+ if(isset($ipInfo['error'])){
|
|
|
+ Log::info('无法识别IPv4,尝试使用IPIP的IP库解析:'.$ip);
|
|
|
+ $ipip = IPIP::ip($ip);
|
|
|
+ $ipInfo = [
|
|
|
+ 'country' => $ipip['country_name'],
|
|
|
+ 'province' => $ipip['region_name'],
|
|
|
+ 'city' => $ipip['city_name']
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ // 判断纯真IP库获取的国家信息是否与IPIP的IP库获取的信息一致,不一致则用IPIP的(因为纯真IP库的非大陆IP准确率较低)
|
|
|
+ $ipip = IPIP::ip($ip);
|
|
|
+ if($ipInfo['country'] != $ipip['country_name']){
|
|
|
+ $ipInfo['country'] = $ipip['country_name'];
|
|
|
+ $ipInfo['province'] = $ipip['region_name'];
|
|
|
+ $ipInfo['city'] = $ipip['city_name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($ipInfo) || empty($ipInfo['country'])){
|
|
|
+ Log::warning("获取IP信息异常:".$ip);
|
|
|
+ }
|
|
|
+
|
|
|
+ $log = new UserLoginLog();
|
|
|
+ $log->user_id = $userId;
|
|
|
+ $log->ip = $ip;
|
|
|
+ $log->country = $ipInfo['country'] ?? '';
|
|
|
+ $log->province = $ipInfo['province'] ?? '';
|
|
|
+ $log->city = $ipInfo['city'] ?? '';
|
|
|
+ $log->county = $ipInfo['county'] ?? '';
|
|
|
+ $log->isp = $ipInfo['isp'] ?? ($ipInfo['organization'] ?? '');
|
|
|
+ $log->area = $ipInfo['area'] ?? '';
|
|
|
+ $log->save();
|
|
|
+ }
|
|
|
+
|
|
|
// 退出
|
|
|
- public function logout(Request $request)
|
|
|
+ public function logout()
|
|
|
{
|
|
|
Auth::logout();
|
|
|
|
|
@@ -148,23 +199,31 @@ class AuthController extends Controller
|
|
|
|
|
|
if($request->isMethod('POST')){
|
|
|
$this->validate($request, [
|
|
|
- 'username' => 'required|email|unique:user',
|
|
|
- 'password' => 'required|min:6',
|
|
|
- 'repassword' => 'required|same:password',
|
|
|
- 'term' => 'accepted'
|
|
|
+ 'username' => 'required|email|unique:user',
|
|
|
+ 'password' => 'required|min:6',
|
|
|
+ 'confirmPassword' => 'required|same:password',
|
|
|
+ 'term' => 'accepted'
|
|
|
], [
|
|
|
- 'username.required' => trans('auth.email_null'),
|
|
|
- 'username.email' => trans('auth.email_legitimate'),
|
|
|
- 'username.unique' => trans('auth.email_exist'),
|
|
|
- 'password.required' => trans('auth.password_null'),
|
|
|
- 'password.min' => trans('auth.password_limit'),
|
|
|
- 'repassword.required' => trans('auth.retype_password'),
|
|
|
- 'repassword.same' => trans('auth.password_same'),
|
|
|
- 'term.accepted' => trans('auth.unaccepted')
|
|
|
+ 'username.required' => trans('auth.email_null'),
|
|
|
+ 'username.email' => trans('auth.email_legitimate'),
|
|
|
+ 'username.unique' => trans('auth.email_exist'),
|
|
|
+ 'password.required' => trans('auth.password_null'),
|
|
|
+ 'password.min' => trans('auth.password_limit'),
|
|
|
+ 'confirmPassword.required' => trans('auth.confirm_password'),
|
|
|
+ 'confirmPassword.same' => trans('auth.password_same'),
|
|
|
+ 'term.accepted' => trans('auth.unaccepted')
|
|
|
]);
|
|
|
|
|
|
+ $username = $request->input('username');
|
|
|
+ $password = $request->input('password');
|
|
|
+ $register_token = $request->input('register_token');
|
|
|
+ $code = $request->input('code');
|
|
|
+ $verify_code = $request->input('verify_code');
|
|
|
+ $captcha = $request->input('captcha');
|
|
|
+ $aff = intval($request->input('aff'));
|
|
|
+
|
|
|
// 防止重复提交
|
|
|
- if($request->register_token != Session::get('register_token')){
|
|
|
+ if($register_token != Session::get('register_token')){
|
|
|
return Redirect::back()->withInput()->withErrors(trans('auth.repeat_request'));
|
|
|
}else{
|
|
|
Session::forget('register_token');
|
|
@@ -179,13 +238,13 @@ class AuthController extends Controller
|
|
|
if(self::$systemConfig['sensitiveType']){
|
|
|
// 校验域名邮箱是否在黑名单中
|
|
|
$sensitiveWords = $this->sensitiveWords(1);
|
|
|
- $usernameSuffix = explode('@', $request->username); // 提取邮箱后缀
|
|
|
+ $usernameSuffix = explode('@', $username); // 提取邮箱后缀
|
|
|
if(in_array(strtolower($usernameSuffix[1]), $sensitiveWords)){
|
|
|
return Redirect::back()->withInput()->withErrors(trans('auth.email_banned'));
|
|
|
}
|
|
|
}else{
|
|
|
$sensitiveWords = $this->sensitiveWords(2);
|
|
|
- $usernameSuffix = explode('@', $request->username); // 提取邮箱后缀
|
|
|
+ $usernameSuffix = explode('@', $username); // 提取邮箱后缀
|
|
|
if(!in_array(strtolower($usernameSuffix[1]), $sensitiveWords)){
|
|
|
return Redirect::back()->withInput()->withErrors(trans('auth.email_invalid'));
|
|
|
}
|
|
@@ -194,14 +253,14 @@ class AuthController extends Controller
|
|
|
// 如果需要邀请注册
|
|
|
if(self::$systemConfig['is_invite_register']){
|
|
|
// 必须使用邀请码
|
|
|
- if(self::$systemConfig['is_invite_register'] == 2 && !$request->code){
|
|
|
+ if(self::$systemConfig['is_invite_register'] == 2 && !$code){
|
|
|
return Redirect::back()->withInput()->withErrors(trans('auth.code_null'));
|
|
|
}
|
|
|
|
|
|
// 校验邀请码合法性
|
|
|
- if($request->code){
|
|
|
- $codeEnable = Invite::query()->where('code', $request->code)->where('status', 0)->first();
|
|
|
- if(!$codeEnable){
|
|
|
+ if($code){
|
|
|
+ $codeEnable = Invite::query()->where('code', $code)->where('status', 0)->doesntExist();
|
|
|
+ if($codeEnable){
|
|
|
return Redirect::back()->withInput($request->except(['code']))->withErrors(trans('auth.code_error'));
|
|
|
}
|
|
|
}
|
|
@@ -209,10 +268,10 @@ class AuthController extends Controller
|
|
|
|
|
|
// 如果开启注册发送验证码
|
|
|
if(self::$systemConfig['is_verify_register']){
|
|
|
- if(!$request->verify_code){
|
|
|
+ if(!$verify_code){
|
|
|
return Redirect::back()->withInput($request->except(['verify_code']))->withErrors(trans('auth.captcha_null'));
|
|
|
}else{
|
|
|
- $verifyCode = VerifyCode::query()->where('username', $request->username)->where('code', $request->verify_code)->where('status', 0)->first();
|
|
|
+ $verifyCode = VerifyCode::query()->where('username', $username)->where('code', $verify_code)->where('status', 0)->first();
|
|
|
if(!$verifyCode){
|
|
|
return Redirect::back()->withInput($request->except(['verify_code']))->withErrors(trans('auth.captcha_overtime'));
|
|
|
}
|
|
@@ -220,36 +279,37 @@ class AuthController extends Controller
|
|
|
$verifyCode->status = 1;
|
|
|
$verifyCode->save();
|
|
|
}
|
|
|
- }elseif(self::$systemConfig['is_captcha']){ // 是否校验验证码
|
|
|
- switch(self::$systemConfig['is_captcha']){
|
|
|
- case 1: // 默认图形验证码
|
|
|
- if(!Captcha::check($request->captcha)){
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha_error'));
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2: // Geetest
|
|
|
- $result = $this->validate($request, [
|
|
|
- 'geetest_challenge' => 'required|geetest'
|
|
|
- ], [
|
|
|
- 'geetest' => trans('auth.captcha_fail')
|
|
|
- ]);
|
|
|
-
|
|
|
- if(!$result){
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha_fail'));
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3: // Google reCAPTCHA
|
|
|
- $result = $this->validate($request, [
|
|
|
- 'g-recaptcha-response' => 'required|NoCaptcha'
|
|
|
- ]);
|
|
|
-
|
|
|
- if(!$result){
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.captcha_fail'));
|
|
|
- }
|
|
|
- break;
|
|
|
- default: // 不启用验证码
|
|
|
- break;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否校验验证码
|
|
|
+ switch(self::$systemConfig['is_captcha']){
|
|
|
+ case 1: // 默认图形验证码
|
|
|
+ if(!Captcha::check($captcha)){
|
|
|
+ return Redirect::back()->withInput()->withErrors(trans('auth.captcha_error'));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: // Geetest
|
|
|
+ $result = $this->validate($request, [
|
|
|
+ 'geetest_challenge' => 'required|geetest'
|
|
|
+ ], [
|
|
|
+ 'geetest' => trans('auth.captcha_fail')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(!$result){
|
|
|
+ return Redirect::back()->withInput()->withErrors(trans('auth.captcha_fail'));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: // Google reCAPTCHA
|
|
|
+ $result = $this->validate($request, [
|
|
|
+ 'g-recaptcha-response' => 'required|NoCaptcha'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(!$result){
|
|
|
+ return Redirect::back()->withInput()->withErrors(trans('auth.captcha_fail'));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default: // 不启用验证码
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
// 24小时内同IP注册限制
|
|
@@ -269,13 +329,13 @@ class AuthController extends Controller
|
|
|
}
|
|
|
|
|
|
// 获取aff
|
|
|
- $affArr = $this->getAff($request->code, intval($request->aff));
|
|
|
+ $affArr = $this->getAff($code, $aff);
|
|
|
$referral_uid = $affArr['referral_uid'];
|
|
|
|
|
|
- $transfer_enable = $referral_uid? (self::$systemConfig['default_traffic']+self::$systemConfig['referral_traffic'])*1048576 : self::$systemConfig['default_traffic']*1048576;
|
|
|
+ $transfer_enable = 1048576*(self::$systemConfig['default_traffic']+($referral_uid? self::$systemConfig['referral_traffic'] : 0));
|
|
|
|
|
|
// 创建新用户
|
|
|
- $uid = Helpers::addUser($request->username, Hash::make($request->password), $transfer_enable, self::$systemConfig['default_days'], $referral_uid);
|
|
|
+ $uid = Helpers::addUser($username, Hash::make($password), $transfer_enable, self::$systemConfig['default_days'], $referral_uid);
|
|
|
|
|
|
// 注册失败,抛出异常
|
|
|
if(!$uid){
|
|
@@ -293,7 +353,7 @@ class AuthController extends Controller
|
|
|
if(Cache::has($cacheKey)){
|
|
|
Cache::increment($cacheKey);
|
|
|
}else{
|
|
|
- Cache::put($cacheKey, 1, 1440); // 24小时
|
|
|
+ Cache::put($cacheKey, 1, 86400); // 24小时
|
|
|
}
|
|
|
|
|
|
// 初始化默认标签
|
|
@@ -315,30 +375,26 @@ class AuthController extends Controller
|
|
|
// 清除邀请人Cookie
|
|
|
Cookie::unqueue('register_aff');
|
|
|
|
|
|
-
|
|
|
- // 发送激活邮件
|
|
|
+ // 邮箱验证码关闭情况下,发送激活邮件
|
|
|
if(!self::$systemConfig['is_verify_register'] && self::$systemConfig['is_active_register']){
|
|
|
// 生成激活账号的地址
|
|
|
- $token = md5(self::$systemConfig['website_name'].$request->username.microtime());
|
|
|
+ $token = $this->addVerifyUrl($uid, $username);
|
|
|
$activeUserUrl = self::$systemConfig['website_url'].'/active/'.$token;
|
|
|
- $this->addVerify($uid, $token);
|
|
|
|
|
|
- $logId = Helpers::addEmailLog($request->username, '注册激活', '请求地址:'.$activeUserUrl);
|
|
|
- Mail::to($request->username)->send(new activeUser($logId, $activeUserUrl));
|
|
|
+ $logId = Helpers::addEmailLog($username, '注册激活', '请求地址:'.$activeUserUrl);
|
|
|
+ Mail::to($username)->send(new activeUser($logId, $activeUserUrl));
|
|
|
|
|
|
- Session::flash('regSuccessMsg', trans('auth.register_success_tip'));
|
|
|
+ Session::flash('regSuccessMsg', trans('auth.register_active_tip'));
|
|
|
}else{
|
|
|
// 则直接给推荐人加流量
|
|
|
if($referral_uid){
|
|
|
- $transfer_enable = self::$systemConfig['referral_traffic']*1048576;
|
|
|
$referralUser = User::query()->where('id', $referral_uid)->first();
|
|
|
if($referralUser){
|
|
|
if($referralUser->expire_time >= date('Y-m-d')){
|
|
|
- User::query()->where('id', $referral_uid)->increment('transfer_enable', $transfer_enable);
|
|
|
+ User::query()->where('id', $referral_uid)->increment('transfer_enable', self::$systemConfig['referral_traffic']*1048576);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
User::query()->where('id', $uid)->update(['status' => 1, 'enable' => 1]);
|
|
|
|
|
|
Session::flash('regSuccessMsg', trans('auth.register_success'));
|
|
@@ -353,6 +409,64 @@ class AuthController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取AFF
|
|
|
+ *
|
|
|
+ * @param string $code 邀请码
|
|
|
+ * @param int $aff URL中的aff参数
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getAff($code = '', $aff = NULL)
|
|
|
+ {
|
|
|
+ // 邀请人ID
|
|
|
+ $referral_uid = 0;
|
|
|
+
|
|
|
+ // 邀请码ID
|
|
|
+ $code_id = 0;
|
|
|
+
|
|
|
+ // 有邀请码先用邀请码,用谁的邀请码就给谁返利
|
|
|
+ if($code){
|
|
|
+ $inviteCode = Invite::query()->where('code', $code)->where('status', 0)->first();
|
|
|
+ if($inviteCode){
|
|
|
+ $referral_uid = $inviteCode->uid;
|
|
|
+ $code_id = $inviteCode->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 没有用邀请码或者邀请码是管理员生成的,则检查cookie或者url链接
|
|
|
+ if(!$referral_uid){
|
|
|
+ // 检查一下cookie里有没有aff
|
|
|
+ $cookieAff = \Request::hasCookie('register_aff')? \Request::cookie('register_aff') : 0;
|
|
|
+ if($cookieAff){
|
|
|
+ $affUser = User::query()->where('id', $cookieAff)->exists();
|
|
|
+ $referral_uid = $affUser? $cookieAff : 0;
|
|
|
+ }elseif($aff){ // 如果cookie里没有aff,就再检查一下请求的url里有没有aff,因为有些人的浏览器会禁用了cookie,比如chrome开了隐私模式
|
|
|
+ $affUser = User::query()->where('id', $aff)->exists();
|
|
|
+ $referral_uid = $affUser? $aff : 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'referral_uid' => $referral_uid,
|
|
|
+ 'code_id' => $code_id
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成申请的请求地址
|
|
|
+ private function addVerifyUrl($uid, $username)
|
|
|
+ {
|
|
|
+ $token = md5(self::$systemConfig['website_name'].$username.microtime());
|
|
|
+ $verify = new Verify();
|
|
|
+ $verify->type = 1;
|
|
|
+ $verify->user_id = $uid;
|
|
|
+ $verify->token = $token;
|
|
|
+ $verify->status = 0;
|
|
|
+ $verify->save();
|
|
|
+
|
|
|
+ return $token;
|
|
|
+ }
|
|
|
+
|
|
|
// 重设密码页
|
|
|
public function resetPassword(Request $request)
|
|
|
{
|
|
@@ -365,36 +479,38 @@ class AuthController extends Controller
|
|
|
'username.email' => trans('auth.email_legitimate')
|
|
|
]);
|
|
|
|
|
|
+ $username = $request->input('username');
|
|
|
+
|
|
|
// 是否开启重设密码
|
|
|
if(!self::$systemConfig['is_reset_password']){
|
|
|
- return Redirect::back()->withErrors(trans('auth.reset_password_close', ['email' => self::$systemConfig['admin_email']]));
|
|
|
+ return Redirect::back()->withErrors(trans('auth.reset_password_close', ['email' => self::$systemConfig['webmaster_email']]));
|
|
|
}
|
|
|
|
|
|
// 查找账号
|
|
|
- $user = User::query()->where('username', $request->username)->first();
|
|
|
+ $user = User::query()->where('username', $username)->first();
|
|
|
if(!$user){
|
|
|
return Redirect::back()->withErrors(trans('auth.email_notExist'));
|
|
|
}
|
|
|
|
|
|
// 24小时内重设密码次数限制
|
|
|
$resetTimes = 0;
|
|
|
- if(Cache::has('resetPassword_'.md5($request->username))){
|
|
|
- $resetTimes = Cache::get('resetPassword_'.md5($request->username));
|
|
|
+ if(Cache::has('resetPassword_'.md5($username))){
|
|
|
+ $resetTimes = Cache::get('resetPassword_'.md5($username));
|
|
|
if($resetTimes >= self::$systemConfig['reset_password_times']){
|
|
|
return Redirect::back()->withErrors(trans('auth.reset_password_limit', ['time' => self::$systemConfig['reset_password_times']]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 生成取回密码的地址
|
|
|
- $token = $this->addVerifyUrl($user->id, $request->username);
|
|
|
+ $token = $this->addVerifyUrl($user->id, $username);
|
|
|
|
|
|
// 发送邮件
|
|
|
$resetPasswordUrl = self::$systemConfig['website_url'].'/reset/'.$token;
|
|
|
|
|
|
- $logId = Helpers::addEmailLog($request->username, '重置密码', '请求地址:'.$resetPasswordUrl);
|
|
|
- Mail::to($request->username)->send(new resetPassword($logId, $resetPasswordUrl));
|
|
|
+ $logId = Helpers::addEmailLog($username, '重置密码', '请求地址:'.$resetPasswordUrl);
|
|
|
+ Mail::to($username)->send(new resetPassword($logId, $resetPasswordUrl));
|
|
|
|
|
|
- Cache::put('resetPassword_'.md5($request->username), $resetTimes+1, 1440);
|
|
|
+ Cache::put('resetPassword_'.md5($username), $resetTimes+1, 86400);
|
|
|
|
|
|
return Redirect::back()->with('successMsg', trans('auth.reset_password_success_tip'));
|
|
|
}else{
|
|
@@ -411,16 +527,16 @@ class AuthController extends Controller
|
|
|
|
|
|
if($request->isMethod('POST')){
|
|
|
$this->validate($request, [
|
|
|
- 'password' => 'required|min:6',
|
|
|
- 'repassword' => 'required|same:password'
|
|
|
+ 'password' => 'required|min:6',
|
|
|
+ 'confirmPassword' => 'required|same:password'
|
|
|
], [
|
|
|
- 'password.required' => trans('auth.password_null'),
|
|
|
- 'password.min' => trans('auth.password_limit'),
|
|
|
- 'repassword.required' => trans('auth.password_null'),
|
|
|
- 'repassword.min' => trans('auth.password_limit'),
|
|
|
- 'repassword.same' => trans('auth.password_same'),
|
|
|
+ 'password.required' => trans('auth.password_null'),
|
|
|
+ 'password.min' => trans('auth.password_limit'),
|
|
|
+ 'confirmPassword.required' => trans('auth.password_null'),
|
|
|
+ 'confirmPassword.min' => trans('auth.password_limit'),
|
|
|
+ 'confirmPassword.same' => trans('auth.password_same'),
|
|
|
]);
|
|
|
-
|
|
|
+ $password = $request->input('password');
|
|
|
// 校验账号
|
|
|
$verify = Verify::type(1)->with('user')->where('token', $token)->first();
|
|
|
if(!$verify){
|
|
@@ -429,12 +545,12 @@ class AuthController extends Controller
|
|
|
return Redirect::back()->withErrors(trans('auth.overtime'));
|
|
|
}elseif($verify->user->status < 0){
|
|
|
return Redirect::back()->withErrors(trans('auth.email_banned'));
|
|
|
- }elseif(Hash::check($request->password, $verify->user->password)){
|
|
|
+ }elseif(Hash::check($password, $verify->user->password)){
|
|
|
return Redirect::back()->withErrors(trans('auth.reset_password_same_fail'));
|
|
|
}
|
|
|
|
|
|
// 更新密码
|
|
|
- $ret = User::query()->where('id', $verify->user_id)->update(['password' => Hash::make($request->password)]);
|
|
|
+ $ret = User::query()->where('id', $verify->user_id)->update(['password' => Hash::make($password)]);
|
|
|
if(!$ret){
|
|
|
return Redirect::back()->withErrors(trans('auth.reset_password_fail'));
|
|
|
}
|
|
@@ -472,48 +588,49 @@ class AuthController extends Controller
|
|
|
'username.email' => trans('auth.email_legitimate'),
|
|
|
'username.exists' => trans('auth.email_notExist')
|
|
|
]);
|
|
|
+ $username = $request->input('username');
|
|
|
|
|
|
// 是否开启账号激活
|
|
|
if(!self::$systemConfig['is_active_register']){
|
|
|
- return Redirect::back()->withInput()->withErrors(trans('auth.active_close', ['email' => self::$systemConfig['admin_email']]));
|
|
|
+ return Redirect::back()->withInput()->withErrors(trans('auth.active_close', ['email' => self::$systemConfig['webmaster_email']]));
|
|
|
}
|
|
|
|
|
|
// 查找账号
|
|
|
- $user = User::query()->where('username', $request->username)->first();
|
|
|
+ $user = User::query()->where('username', $username)->first();
|
|
|
if($user->status < 0){
|
|
|
- return Redirect::back()->withErrors(trans('auth.login_ban', ['email' => self::$systemConfig['admin_email']]));
|
|
|
+ return Redirect::back()->withErrors(trans('auth.login_ban', ['email' => self::$systemConfig['webmaster_email']]));
|
|
|
}elseif($user->status > 0){
|
|
|
return Redirect::back()->withErrors(trans('auth.email_normal'));
|
|
|
}
|
|
|
|
|
|
// 24小时内激活次数限制
|
|
|
$activeTimes = 0;
|
|
|
- if(Cache::has('activeUser_'.md5($request->username))){
|
|
|
- $activeTimes = Cache::get('activeUser_'.md5($request->username));
|
|
|
+ if(Cache::has('activeUser_'.md5($username))){
|
|
|
+ $activeTimes = Cache::get('activeUser_'.md5($username));
|
|
|
if($activeTimes >= self::$systemConfig['active_times']){
|
|
|
- return Redirect::back()->withErrors(trans('auth.active_limit', ['time' => self::$systemConfig['admin_email']]));
|
|
|
+ return Redirect::back()->withErrors(trans('auth.active_limit', ['time' => self::$systemConfig['webmaster_email']]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 生成激活账号的地址
|
|
|
- $token = $this->addVerifyUrl($user->id, $request->username);
|
|
|
+ $token = $this->addVerifyUrl($user->id, $username);
|
|
|
|
|
|
// 发送邮件
|
|
|
$activeUserUrl = self::$systemConfig['website_url'].'/active/'.$token;
|
|
|
|
|
|
- $logId = Helpers::addEmailLog($request->username, '激活账号', '请求地址:'.$activeUserUrl);
|
|
|
- Mail::to($request->username)->send(new activeUser($logId, $activeUserUrl));
|
|
|
+ $logId = Helpers::addEmailLog($username, '激活账号', '请求地址:'.$activeUserUrl);
|
|
|
+ Mail::to($username)->send(new activeUser($logId, $activeUserUrl));
|
|
|
|
|
|
- Cache::put('activeUser_'.md5($request->username), $activeTimes+1, 1440);
|
|
|
+ Cache::put('activeUser_'.md5($username), $activeTimes+1, 86400);
|
|
|
|
|
|
- return Redirect::back()->with('successMsg', trans('auth.register_success_tip'));
|
|
|
+ return Redirect::back()->with('successMsg', trans('auth.register_active_tip'));
|
|
|
}else{
|
|
|
return Response::view('auth.activeUser');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 激活账号
|
|
|
- public function active(Request $request, $token)
|
|
|
+ public function active($token)
|
|
|
{
|
|
|
if(!$token){
|
|
|
return Redirect::to('login');
|
|
@@ -560,8 +677,7 @@ class AuthController extends Controller
|
|
|
if($verify->user->referral_uid){
|
|
|
$transfer_enable = self::$systemConfig['referral_traffic']*1048576;
|
|
|
|
|
|
- User::query()->where('id', $verify->user->referral_uid)->increment('transfer_enable', $transfer_enable);
|
|
|
- User::query()->where('id', $verify->user->referral_uid)->update(['enable' => 1]);
|
|
|
+ User::query()->where('id', $verify->user->referral_uid)->increment('transfer_enable', $transfer_enable, ['enable' => 1]);
|
|
|
}
|
|
|
|
|
|
Session::flash('successMsg', trans('auth.active_success'));
|
|
@@ -580,6 +696,8 @@ class AuthController extends Controller
|
|
|
'username.unique' => trans('auth.email_exist')
|
|
|
]);
|
|
|
|
|
|
+ $username = $request->input('username');
|
|
|
+
|
|
|
if($validator->fails()){
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => $validator->getMessageBag()->first()]);
|
|
|
}
|
|
@@ -588,13 +706,13 @@ class AuthController extends Controller
|
|
|
if(self::$systemConfig['sensitiveType']){
|
|
|
// 校验域名邮箱是否在黑名单中
|
|
|
$sensitiveWords = $this->sensitiveWords(1);
|
|
|
- $usernameSuffix = explode('@', $request->username); // 提取邮箱后缀
|
|
|
+ $usernameSuffix = explode('@', $username); // 提取邮箱后缀
|
|
|
if(in_array(strtolower($usernameSuffix[1]), $sensitiveWords)){
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => trans('auth.email_banned')]);
|
|
|
}
|
|
|
}else{
|
|
|
$sensitiveWords = $this->sensitiveWords(2);
|
|
|
- $usernameSuffix = explode('@', $request->username); // 提取邮箱后缀
|
|
|
+ $usernameSuffix = explode('@', $username); // 提取邮箱后缀
|
|
|
if(!in_array(strtolower($usernameSuffix[1]), $sensitiveWords)){
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => trans('auth.email_invalid')]);
|
|
|
}
|
|
@@ -612,135 +730,16 @@ class AuthController extends Controller
|
|
|
|
|
|
// 发送邮件
|
|
|
$code = makeRandStr(6, TRUE);
|
|
|
- $logId = Helpers::addEmailLog($request->username, '发送注册验证码', '验证码:'.$code);
|
|
|
- Mail::to($request->username)->send(new sendVerifyCode($logId, $code));
|
|
|
+ $logId = Helpers::addEmailLog($username, '发送注册验证码', '验证码:'.$code);
|
|
|
+ Mail::to($username)->send(new sendVerifyCode($logId, $code));
|
|
|
|
|
|
- $this->addVerifyCode($request->username, $code);
|
|
|
+ $this->addVerifyCode($username, $code);
|
|
|
|
|
|
- Cache::put('send_verify_code_'.md5(getClientIP()), getClientIP(), 1);
|
|
|
+ Cache::put('send_verify_code_'.md5(getClientIP()), getClientIP(), 60);
|
|
|
|
|
|
return Response::json(['status' => 'success', 'data' => '', 'message' => trans('auth.captcha_send')]);
|
|
|
}
|
|
|
|
|
|
- // 公开的邀请码列表
|
|
|
- public function free(Request $request)
|
|
|
- {
|
|
|
- $view['inviteList'] = Invite::query()->where('uid', 0)->where('status', 0)->paginate();
|
|
|
-
|
|
|
- return Response::view('auth.free', $view);
|
|
|
- }
|
|
|
-
|
|
|
- // 切换语言
|
|
|
- public function switchLang(Request $request, $locale)
|
|
|
- {
|
|
|
- Session::put("locale", $locale);
|
|
|
-
|
|
|
- return Redirect::back();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加用户登录日志
|
|
|
- *
|
|
|
- * @param string $userId 用户ID
|
|
|
- * @param string $ip IP地址
|
|
|
- */
|
|
|
- private function addUserLoginLog($userId, $ip)
|
|
|
- {
|
|
|
- if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
|
|
|
- Log::info('识别到IPv6,尝试解析:'.$ip);
|
|
|
- $ipInfo = getIPv6($ip);
|
|
|
- }else{
|
|
|
- $ipInfo = QQWry::ip($ip); // 通过纯真IP库解析IPv4信息
|
|
|
- if(isset($ipInfo['error'])){
|
|
|
- Log::info('无法识别IPv4,尝试使用IPIP的IP库解析:'.$ip);
|
|
|
- $ipip = IPIP::ip($ip);
|
|
|
- $ipInfo = [
|
|
|
- 'country' => $ipip['country_name'],
|
|
|
- 'province' => $ipip['region_name'],
|
|
|
- 'city' => $ipip['city_name']
|
|
|
- ];
|
|
|
- }else{
|
|
|
- // 判断纯真IP库获取的国家信息是否与IPIP的IP库获取的信息一致,不一致则用IPIP的(因为纯真IP库的非大陆IP准确率较低)
|
|
|
- $ipip = IPIP::ip($ip);
|
|
|
- if($ipInfo['country'] != $ipip['country_name']){
|
|
|
- $ipInfo['country'] = $ipip['country_name'];
|
|
|
- $ipInfo['province'] = $ipip['region_name'];
|
|
|
- $ipInfo['city'] = $ipip['city_name'];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($ipInfo) || empty($ipInfo['country'])){
|
|
|
- Log::warning("获取IP信息异常:".$ip);
|
|
|
- }
|
|
|
-
|
|
|
- $log = new UserLoginLog();
|
|
|
- $log->user_id = $userId;
|
|
|
- $log->ip = $ip;
|
|
|
- $log->country = $ipInfo['country'] ?? '';
|
|
|
- $log->province = $ipInfo['province'] ?? '';
|
|
|
- $log->city = $ipInfo['city'] ?? '';
|
|
|
- $log->county = $ipInfo['county'] ?? '';
|
|
|
- $log->isp = $ipInfo['isp'] ?? ($ipInfo['organization'] ?? '');
|
|
|
- $log->area = $ipInfo['area'] ?? '';
|
|
|
- $log->save();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取AFF
|
|
|
- *
|
|
|
- * @param string $code 邀请码
|
|
|
- * @param int $aff URL中的aff参数
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- private function getAff($code = '', $aff = '')
|
|
|
- {
|
|
|
- // 邀请人ID
|
|
|
- $referral_uid = 0;
|
|
|
-
|
|
|
- // 邀请码ID
|
|
|
- $code_id = 0;
|
|
|
-
|
|
|
- // 有邀请码先用邀请码,用谁的邀请码就给谁返利
|
|
|
- if($code){
|
|
|
- $inviteCode = Invite::query()->where('code', $code)->where('status', 0)->first();
|
|
|
- if($inviteCode){
|
|
|
- $referral_uid = $inviteCode->uid;
|
|
|
- $code_id = $inviteCode->id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 没有用邀请码或者邀请码是管理员生成的,则检查cookie或者url链接
|
|
|
- if(!$referral_uid){
|
|
|
- // 检查一下cookie里有没有aff
|
|
|
- $cookieAff = \Request::hasCookie('register_aff')? \Request::cookie('register_aff') : 0;
|
|
|
- if($cookieAff){
|
|
|
- $affUser = User::query()->where('id', $cookieAff)->exists();
|
|
|
- $referral_uid = $affUser? $cookieAff : 0;
|
|
|
- }elseif($aff){ // 如果cookie里没有aff,就再检查一下请求的url里有没有aff,因为有些人的浏览器会禁用了cookie,比如chrome开了隐私模式
|
|
|
- $affUser = User::query()->where('id', $aff)->exists();
|
|
|
- $referral_uid = $affUser? $aff : 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return [
|
|
|
- 'referral_uid' => $referral_uid,
|
|
|
- 'code_id' => $code_id
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- // 写入生成激活账号验证记录
|
|
|
- private function addVerify($userId, $token)
|
|
|
- {
|
|
|
- $verify = new Verify();
|
|
|
- $verify->type = 1;
|
|
|
- $verify->user_id = $userId;
|
|
|
- $verify->token = $token;
|
|
|
- $verify->status = 0;
|
|
|
- $verify->save();
|
|
|
- }
|
|
|
-
|
|
|
// 生成注册验证码
|
|
|
private function addVerifyCode($username, $code)
|
|
|
{
|
|
@@ -751,17 +750,19 @@ class AuthController extends Controller
|
|
|
$verify->save();
|
|
|
}
|
|
|
|
|
|
- // 生成激活账号的地址
|
|
|
- private function addVerifyUrl($uid, $username)
|
|
|
+ // 公开的邀请码列表
|
|
|
+ public function free()
|
|
|
{
|
|
|
- $token = md5(self::$systemConfig['website_name'].$username.microtime());
|
|
|
- $verify = new Verify();
|
|
|
- $verify->type = 1;
|
|
|
- $verify->user_id = $uid;
|
|
|
- $verify->token = $token;
|
|
|
- $verify->status = 0;
|
|
|
- $verify->save();
|
|
|
+ $view['inviteList'] = Invite::query()->where('uid', 0)->where('status', 0)->paginate();
|
|
|
|
|
|
- return $token;
|
|
|
+ return Response::view('auth.free', $view);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 切换语言
|
|
|
+ public function switchLang($locale)
|
|
|
+ {
|
|
|
+ Session::put("locale", $locale);
|
|
|
+
|
|
|
+ return Redirect::back();
|
|
|
}
|
|
|
}
|