Throw PrettyPageException when cipher is invalid

This commit is contained in:
printempw 2018-07-22 11:10:33 +08:00
parent 09acc6c7d8
commit 5ae53acbb9
3 changed files with 15 additions and 12 deletions

View File

@ -5,7 +5,9 @@ namespace App\Providers;
use Event; use Event;
use Utils; use Utils;
use App\Events; use App\Events;
use ReflectionException;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use App\Exceptions\PrettyPageException;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
@ -38,6 +40,12 @@ class AppServiceProvider extends ServiceProvider
$event->addContent('<script>var blessing = '.json_encode($blessing).';</script>'); $event->addContent('<script>var blessing = '.json_encode($blessing).';</script>');
}); });
try {
$this->app->make('cipher');
} catch (ReflectionException $e) {
throw new PrettyPageException(trans('errors.cipher.unsupported', ['cipher' => config('secure.cipher')]));
}
} }
/** /**
@ -47,18 +55,7 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function register() public function register()
{ {
// Register default cipher $this->app->singleton('cipher', 'App\Services\Cipher\\'.config('secure.cipher'));
$className = "App\Services\Cipher\\".config('secure.cipher');
if (class_exists($className)) {
$this->app->singleton('cipher', $className);
} else {
die_with_utf8_encoding(sprintf(
'[Error] Unsupported encryption method: < %1$s >, please check your .env configuration <br>'.
'[错误] 不支持的密码加密方式 < %1$s >,请检查你的 .env 配置文件'
, config('secure.cipher')));
}
$this->app->singleton('users', \App\Services\Repositories\UserRepository::class); $this->app->singleton('users', \App\Services\Repositories\UserRepository::class);
$this->app->singleton('parsedown', \Parsedown::class); $this->app->singleton('parsedown', \Parsedown::class);
} }

View File

@ -16,3 +16,6 @@ exception:
plugins: plugins:
duplicate: The plugin [:dir1] has a duplicated plugin name definition which is same to plugin [:dir2]. Please check your plugins directory, remove one of them or use another name definition. duplicate: The plugin [:dir1] has a duplicated plugin name definition which is same to plugin [:dir2]. Please check your plugins directory, remove one of them or use another name definition.
directory: We can't approach the path for loading plugins specified by the PLUGINS_DIR in .env file. Please check your configuration. Error :msg directory: We can't approach the path for loading plugins specified by the PLUGINS_DIR in .env file. Please check your configuration. Error :msg
cipher:
unsupported: Unsupported encryption method `:cipher`, please check your `.env` configuration

View File

@ -17,3 +17,6 @@ exception:
plugins: plugins:
duplicate: 【插件定义重复】:dir1 目录下的插件与 :dir2 目录下的插件使用了相同的 name 定义并造成了冲突。请检查您的插件目录,移除其中一个插件或者使用不同的 name 属性。 duplicate: 【插件定义重复】:dir1 目录下的插件与 :dir2 目录下的插件使用了相同的 name 定义并造成了冲突。请检查您的插件目录,移除其中一个插件或者使用不同的 name 属性。
directory: 配置文件 .env 中指定的插件加载目录PLUGINS_DIR不存在或无法打开请检查您的配置。错误信息:msg directory: 配置文件 .env 中指定的插件加载目录PLUGINS_DIR不存在或无法打开请检查您的配置。错误信息:msg
cipher:
unsupported: 不支持的密码加密方式 `:cipher`,请检查你的 .env 配置文件