我已经开始学习 Laravel 5.1,到目前为止我很喜欢它!但有一件事我还没有明白。
在我之前的项目中,我有 2 个特定的控制器(例如:“正常”、“扩展”),在成功登录后,它们根据user_group数据库中的用户被调用。
如果“Foo.Bar”输入了他的有效凭据并拥有normal他被重定向到的组NormalControler。由于我没有使用任何框架,因此我通过为组设置 a$_SESSION并检查它来限制对另一个组的访问。因此,如果另一个组试图访问该控制器,他就会被重定向。
这在 Laravel 5 中如何实现?到目前为止,我有一个无需身份验证即可调用的控制器,并且受以下代码限制routes.php:
// All routes in the group are protected, only authed user are allowed to access them
Route::group(array('before' => 'auth'), function() {
// TO-DO : Seperate Controller access
});
Run Code Online (Sandbox Code Playgroud)
登录看起来像这样:
public function performLogin()
{
$logindata = array(
'username' => Input::get('user_name'),
'password' => Input::get('user_pass')
);
if( Auth::attempt( $logindata ) ){
// return \Redirect::to( check group and access this controller based …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个吗啡“按钮”,它可以在另一个菜单上滑动。
这个想法基于 Codrops变形按钮概念
现在已经差不多设置好了,只有两件小事让我烦恼:
我有点没主意了..
一些库提供Thenable接口类型 fe AJV。
我对他们有些不明白。鉴于这个最少的代码
const foo: Ajv.Thenable<boolean> = new Promise<boolean>((resolve, reject) => {
if ("condition")
resolve(true)
reject("Nope")
})
Run Code Online (Sandbox Code Playgroud)
TypeScript 编译器抛出一个我无法理解的错误。
error TS2322: Type 'Promise<boolean>' is not assignable to type 'Thenable<boolean>'.
Types of property 'then' are incompatible.
Type '<TResult1 = boolean, TResult2 = never>(onfulfilled?: ((value: boolean) => TResult1 | PromiseLike<...' is not assignable to type '<U>(onFulfilled?: ((value: boolean) => U | Thenable<U>) | undefined, onRejected?: ((error: any) =...'.
Types of parameters 'onfulfilled' and 'onFulfilled' are incompatible.
Type '((value: …Run Code Online (Sandbox Code Playgroud)