Add option to disable email verification
This commit is contained in:
parent
0e70a88e13
commit
4904e1c2a4
|
|
@ -171,6 +171,7 @@ class AdminController extends Controller
|
|||
});
|
||||
|
||||
$form->checkbox('user_can_register')->label();
|
||||
$form->checkbox('require_verification')->label();
|
||||
|
||||
$form->text('regs_per_ip');
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class AuthController extends Controller
|
|||
if (config('mail.driver') != "") {
|
||||
return view('auth.forgot');
|
||||
} else {
|
||||
throw new PrettyPageException(trans('auth.forgot.close'), 8);
|
||||
throw new PrettyPageException(trans('auth.forgot.disabled'), 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,8 +174,9 @@ class AuthController extends Controller
|
|||
if (! $this->checkCaptcha($request))
|
||||
return json(trans('auth.validation.captcha'), 1);
|
||||
|
||||
if (config('mail.driver') == "")
|
||||
return json(trans('auth.forgot.close'), 1);
|
||||
if (! config('mail.driver')) {
|
||||
return json(trans('auth.forgot.disabled'), 1);
|
||||
}
|
||||
|
||||
$rateLimit = 180;
|
||||
$lastMailCacheKey = sha1('last_mail_'.Utils::getClientIp());
|
||||
|
|
@ -273,6 +274,10 @@ class AuthController extends Controller
|
|||
|
||||
public function verify(Request $request, UserRepository $users)
|
||||
{
|
||||
if (! option('require_verification')) {
|
||||
throw new PrettyPageException(trans('user.verification.disabled'), 1);
|
||||
}
|
||||
|
||||
// Get user instance from repository
|
||||
$user = $users->get($request->get('uid'));
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,10 @@ class UserController extends Controller
|
|||
|
||||
public function sendVerificationEmail()
|
||||
{
|
||||
if (! option('require_verification')) {
|
||||
return json(trans('user.verification.disabled'), 1);
|
||||
}
|
||||
|
||||
// Rate limit of 60s
|
||||
$remain = 60 + session('last_mail_time', 0) - time();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class CheckUserVerified
|
|||
return $result;
|
||||
}
|
||||
|
||||
if (! $result->verified) {
|
||||
if (option('require_verification') && !$result->verified) {
|
||||
abort(403, trans('auth.check.verified'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'driver' => menv('MAIL_DRIVER', 'smtp'),
|
||||
'driver' => menv('MAIL_DRIVER'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ return [
|
|||
'site_name' => 'Blessing Skin',
|
||||
'site_description' => 'Open-source PHP Minecraft Skin Hosting Service',
|
||||
'user_can_register' => 'true',
|
||||
'require_verification' => 'false',
|
||||
'regs_per_ip' => '3',
|
||||
'ip_get_method' => '0',
|
||||
'api_type' => 'false',
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ forgot:
|
|||
button: Send
|
||||
message: We will send you an E-mail to verify.
|
||||
login-link: I do remember it
|
||||
close: Password resetting is not available now.
|
||||
disabled: Password resetting is not available.
|
||||
frequent-mail: You click the send button too fast. Wait for some minutes, guy.
|
||||
unregistered: The email address is not registered.
|
||||
success: Mail sent, please check your inbox. The link will be expired in 1 hour.
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ general:
|
|||
user_can_register:
|
||||
title: Open Registration
|
||||
label: Everyone is allowed to register.
|
||||
require_verification:
|
||||
title: Account Verification
|
||||
label: Users must verify their email address first.
|
||||
regs_per_ip: Max accounts of one IP
|
||||
ip_get_method:
|
||||
title: Get IP via
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ sign-remain-time: Available after :time :unit
|
|||
announcement: Announcement
|
||||
|
||||
verification:
|
||||
disabled: Email verification is not available.
|
||||
frequent-mail: You click the send button too fast. Wait for 60 secs, guy.
|
||||
verified: Your account is already verified.
|
||||
success: Verification link was sent, please check your inbox.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ forgot:
|
|||
button: 发送
|
||||
message: 我们将会向您发送一封验证邮件
|
||||
login-link: 我又想起来了
|
||||
close: 本站已关闭重置密码功能
|
||||
disabled: 本站已关闭重置密码功能
|
||||
frequent-mail: 你邮件发送得太频繁啦,过会儿再点发送吧
|
||||
unregistered: 该邮箱尚未注册
|
||||
success: 邮件已发送,一小时内有效,请注意查收。
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ general:
|
|||
user_can_register:
|
||||
title: 开放注册
|
||||
label: 任何人都可以注册
|
||||
require_verification:
|
||||
title: 邮箱验证
|
||||
label: 用户必须验证邮箱后才能使用皮肤托管等功能
|
||||
regs_per_ip: 每个 IP 限制注册数
|
||||
ip_get_method:
|
||||
title: IP 获取方式
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ sign-remain-time: :time :unit 后可签到
|
|||
announcement: 公告
|
||||
|
||||
verification:
|
||||
disabled: 本站已关闭邮箱验证功能
|
||||
frequent-mail: 你邮件发送得太频繁啦,过 60 秒后再点发送吧
|
||||
verified: 你已经验证过邮箱了
|
||||
success: 验证邮件已发送,请检查你的收件箱。
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
<!-- Main content -->
|
||||
<section class="content">
|
||||
|
||||
@if (! $user->verified)
|
||||
@if (option('require_verification') && !$user->verified)
|
||||
@include('common.email-verification')
|
||||
@endif
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<!-- Main content -->
|
||||
<section class="content">
|
||||
|
||||
@if (! $user->verified)
|
||||
@if (option('require_verification') && !$user->verified)
|
||||
@include('common.email-verification')
|
||||
@endif
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<!-- Main content -->
|
||||
<section class="content">
|
||||
|
||||
@if (! $user->verified)
|
||||
@if (option('require_verification') && !$user->verified)
|
||||
@include('common.email-verification')
|
||||
@endif
|
||||
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ class AuthControllerTest extends TestCase
|
|||
$this->visit('/auth/forgot')->see('Forgot Password');
|
||||
|
||||
config(['mail.driver' => '']);
|
||||
$this->visit('/auth/forgot')->see(trans('auth.forgot.close'));
|
||||
$this->visit('/auth/forgot')->see(trans('auth.forgot.disabled'));
|
||||
}
|
||||
|
||||
public function testHandleForgot()
|
||||
|
|
@ -421,7 +421,7 @@ class AuthControllerTest extends TestCase
|
|||
'captcha' => 'a'
|
||||
])->seeJson([
|
||||
'errno' => 1,
|
||||
'msg' => trans('auth.forgot.close')
|
||||
'msg' => trans('auth.forgot.disabled')
|
||||
]);
|
||||
config(['mail.driver' => 'smtp']);
|
||||
|
||||
|
|
@ -649,6 +649,12 @@ class AuthControllerTest extends TestCase
|
|||
{
|
||||
$user = factory(User::class, 'unverified')->create();
|
||||
|
||||
// Should be forbidden if account verification is disabled
|
||||
option(['require_verification' => false]);
|
||||
$this->visit('/auth/verify')
|
||||
->see(trans('user.verification.disabled'));
|
||||
option(['require_verification' => true]);
|
||||
|
||||
// Should be forbidden if `uid` or `token` is empty
|
||||
$this->visit('/auth/verify')
|
||||
->see(trans('auth.verify.invalid'));
|
||||
|
|
|
|||
|
|
@ -64,6 +64,14 @@ class MiddlewareTest extends TestCase
|
|||
|
||||
public function testCheckUserVerified()
|
||||
{
|
||||
option(['require_verification' => false]);
|
||||
|
||||
$this->actAs('unverified')
|
||||
->get('/skinlib/upload')
|
||||
->assertResponseOk();
|
||||
|
||||
option(['require_verification' => true]);
|
||||
|
||||
$this->actAs('unverified')
|
||||
->get('/skinlib/upload')
|
||||
->assertResponseStatus(403)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ class UserControllerTest extends TestCase
|
|||
->see($user->score);
|
||||
|
||||
$unverified = factory(User::class, 'unverified')->create();
|
||||
|
||||
$this->actAs($unverified)
|
||||
->visit('/user')
|
||||
->dontSee(trans('user.verification.notice.title'));
|
||||
|
||||
option(['require_verification' => true]);
|
||||
$this->actAs($unverified)
|
||||
->visit('/user')
|
||||
->see(trans('user.verification.notice.title'));
|
||||
|
|
@ -106,6 +112,16 @@ class UserControllerTest extends TestCase
|
|||
$user = factory(User::class, 'unverified')->create();
|
||||
$verified = factory(User::class)->create();
|
||||
|
||||
// Should be forbidden if account verification is disabled
|
||||
option(['require_verification' => false]);
|
||||
$this->actAs($user)
|
||||
->post('/user/email-verification')
|
||||
->seeJson([
|
||||
'errno' => 1,
|
||||
'msg' => trans('user.verification.disabled')
|
||||
]);
|
||||
option(['require_verification' => true]);
|
||||
|
||||
// Too fast
|
||||
$this->actAs($user)
|
||||
->withSession([
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user