首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aurelia js授权

Aurelia js授权
EN

Stack Overflow用户
提问于 2016-05-06 23:46:03
回答 3查看 744关注 0票数 1

我刚接触Aurelia,所以我的问题是在多用户环境中使用Aurelia的指导原则是什么。使用角色授权的Windows身份验证?有没有可能用asp mvc作为主机的示例代码?

EN

回答 3

Stack Overflow用户

发布于 2016-05-07 00:05:33

下面是一个简单的授权工作流程示例:

应用程序结构:

代码语言:javascript
复制
/src
 main.js
 -app
   -app.html -- app root component for logged users
   -app.js -- app root component for logged users
   -nav-bar.html
   -nav-bar.js
 -login
   -login.js -- app root component for unlogged users
   -login.html -- app root component for unlogged users
   -user-password.html -- route with user/password fields.
   -user-password.js -- route with user/password fields.
   -forgot-password.html
   -forgot-password.js

MAIN.JS:

代码语言:javascript
复制
export function(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging();

  //initialise
  aurelia.start().then(a => {
    let rootComponent = isLoggedIn() ? 'app/app' : 'login/login';
    a.setRoot(rootComponent, document.body);
  });
});

function isLoggedIn() {
  //do your magic here
  //check if the current user has a valid authorisation token
}

APP.HTML:

代码语言:javascript
复制
<template>
  <!-- THIS IS WHERE YOU APP WILL BE RENDERED (if the user is logged) -->
  <nav-bar></nav-bar>
  <router-view></router-view>
</template>

LOGIN.HTML:

代码语言:javascript
复制
<template>
  <!-- THIS IS WHERE YOU APP WILL BE RENDERED (if the user is not logged) -->
  <router-view></router-view>
</template>

LOGIN.JS:

代码语言:javascript
复制
export class Login {

configureRouter(config, router) {
  config.map([
    { route: '', name: 'user-password', moduleId: './user-password', title: 'Sign In' },
    { route: 'forgot-password', name: 'forgot-password', moduleId: './forgot-password', title: 'Forgot Password?' }
  ]);
  config.mapUnknownRoutes(instruction => {
    //check instruction.fragment
    return './user-password';
  });

  this.router = router;
}

}

USER-PASSWORD.HTML

代码语言:javascript
复制
<template>
  <input type="text">
  <input type="password">
  <button type="submit"></button>
</template>

USER-PASSWORD.JS

代码语言:javascript
复制
export class UserPassword {

  login() {
    //check if the user and password are valid
    //redirect to the app root component
    //import and inject { Aurelia } from 'aurelia-framework';
    this.aurelia.setRoot('app/app');
  }
}

如果有什么不够清楚,尽管问我!

希望这能有所帮助!

票数 4
EN

Stack Overflow用户

发布于 2017-07-28 00:46:48

有一个同构的授权库,称为CASL。您可以在medium https://medium.com/@sergiy.stotskiy/casl-based-authorization-in-aurelia-app-3e44c0fe1703上的Aurelia应用程序中了解到它的集成

票数 0
EN

Stack Overflow用户

发布于 2017-11-01 15:42:43

我编写了一个库CASL来处理JavaScript中的授权逻辑。你也可以在我的github和related article on Medium上找到a sample application of integration CASL and Aurelia

希望这能对你有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37076484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档