Skip to content

Commit

Permalink
增加用户注册功能是否启用配置
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Apr 1, 2021
1 parent c5f19ba commit 92d4acc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@ WIZARD_MARKDOWN_STRICT=true
# 启用后,用户注册时必须提供邀请码
WIZARD_REGISTER_INVITATION=false
# 静态邀请码,所有用户注册时必须提供此邀请码,邀请码对所有用户固定不变
WIZARD_REGISTER_INVITATION_STATIC=eb092be4a8970338c06a37900a7116f1
WIZARD_REGISTER_INVITATION_STATIC=eb092be4a8970338c06a37900a7116f1

# 是否启用用户注册功能
WIZARD_REGISTER_ENABLED=true
15 changes: 15 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,21 @@ function ldap_enabled(): bool
return $enabled;
}

/**
* 是否启用注册功能支持
*
* @return bool
*/
function register_enabled(): bool
{
static $enabled = null;
if (is_null($enabled)) {
$enabled = (bool)config('wizard.register_enabled');
}

return $enabled;
}

/**
* 站长统计代码区域
*
Expand Down
4 changes: 4 additions & 0 deletions config/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* 新注册账号是否需要邮箱激活
*/
'need_activate' => env('WIZARD_NEED_ACTIVATE', false),
/**
* 是否启用用户注册支持
*/
'register_enabled' => env('WIZARD_REGISTER_ENABLED', true),
/**
* 新账号注册是否需要邀请码
*/
Expand Down
2 changes: 2 additions & 0 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
</button>

@if (!ldap_enabled())
@if(register_enabled())
<a class="btn btn-link" href="{{ wzRoute('register') }}">
@lang('common.register')
</a>
@endif

<a class="btn btn-link" href="{{ wzRoute('password.request') }}">
@lang('common.password_back')?
Expand Down
23 changes: 12 additions & 11 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@

use Illuminate\Support\Facades\Route;

Route::group(['middleware' => 'locale'], function() {
Route::group(['middleware' => 'locale'], function () {
// 如果启用 LDAP ,则不允许用户注册和重置密码
$ldapDisabled = !ldap_enabled();
Auth::routes([
'reset' => $ldapDisabled,
'verify' => $ldapDisabled,
'register' => $ldapDisabled,
]);

Route::group(['middleware' => 'global-auth'], function() {
$authRoutes = [
'reset' => $ldapDisabled,
'verify' => $ldapDisabled,
'register' => $ldapDisabled && register_enabled(),
];
Auth::routes($authRoutes);

Route::group(['middleware' => 'global-auth'], function () {
// 公共首页
Route::get('/{catalog?}', 'HomeController@home')->name('home');
// 项目公共页面
Expand Down Expand Up @@ -67,7 +68,7 @@
// 项目分享
Route::get('/{id}/doc/{page_id}.json', 'DocumentController@getPageJSON')->name('doc:json');
Route::get('/{id}/doc/{page_id}/histories/{history_id}.json',
'HistoryController@getPageJSON')->name('doc:history:json');
'HistoryController@getPageJSON')->name('doc:history:json');
});

Route::group(['prefix' => 'swagger', 'as' => 'swagger:'], function () {
Expand All @@ -77,7 +78,7 @@
});

// 用户扮演
Route::group(['prefix' => 'impersonate', 'as' => 'impersonate:'], function() {
Route::group(['prefix' => 'impersonate', 'as' => 'impersonate:'], function () {
Route::post('/{id}', 'ImpersonateController@impersonate')->name('start');
Route::delete('/', 'ImpersonateController@stopImpersonate')->name('stop');
});
Expand Down Expand Up @@ -208,7 +209,7 @@ function () {
Route::get('/{id}/doc/{page_id}/attachments', 'AttachmentController@page')
->name('doc:attachment');
Route::delete('/{id}/doc/{page_id}/attachments/{attachment_id}',
'AttachmentController@delete')->name('doc:attachment:delete');
'AttachmentController@delete')->name('doc:attachment:delete');
Route::post('/{id}/doc/{page_id}/attachments', 'AttachmentController@upload')
->name('doc:attachment:upload');

Expand Down

0 comments on commit 92d4acc

Please sign in to comment.