Throw PrettyPageException when cipher is invalid

This commit is contained in:
Pig Fang 2018-07-22 16:23:49 +08:00
parent d16483bacb
commit d05cd4aab2
3 changed files with 15 additions and 13 deletions

View File

@ -7,7 +7,9 @@ use Event;
use Utils;
use App\Events;
use App\Models\User;
use ReflectionException;
use Illuminate\Support\ServiceProvider;
use App\Exceptions\PrettyPageException;
class AppServiceProvider extends ServiceProvider
{
@ -40,6 +42,12 @@ class AppServiceProvider extends ServiceProvider
$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')]));
}
}
/**
@ -49,19 +57,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
// Register default cipher
$className = "App\Services\Cipher\\".config('secure.cipher');
if (class_exists($className)) {
$this->app->singleton('cipher', $className);
} else {
header('Content-Type: text/html; charset=UTF-8');
exit(sprintf(
'[Error] Unsupported encryption method: < %1$s >, please check your .env configuration <br>'.
'[错误] 不支持的密码加密方式 < %1$s >,请检查你的 .env 配置文件'
, config('secure.cipher')));
}
$this->app->singleton('cipher', 'App\Services\Cipher\\'.config('secure.cipher'));
$this->app->singleton('users', \App\Services\Repositories\UserRepository::class);
$this->app->singleton('parsedown', \Parsedown::class);

View File

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