Emberアプリケーションの一部とサーバーアプリケーションの一部のログイン認証を処理する必要があります。しかし、私はこのライブラリを私のアプリケーションでは時々使用していることをお勧めしたいと思います。それは、その後
一度
ember install ember-simple-auth
を
git clone https://github.com/simplabs/ember-simple-auth.git
cd ember-simple-auth
npm install && bower install && ember serve
をインストールするには非常に簡単ですそれはほとんどすべてあなたが望むものについてカバーし、あなたは、認証に必要なものと認証
はEmber Simple Authorization
を見てみましょうライブラリがインストールされている場合は、アプリケーション内で必要に応じてセッションサービスを挿入できます。あなたが例えば
{{!-- app/templates/login.hbs --}}
<form {{action 'authenticate' on='submit'}}>
<label for="identification">Login</label>
{{input id='identification' placeholder='Enter Login' value=identification}}
<label for="password">Password</label>
{{input id='password' placeholder='Enter Password' type='password' value=password}}
<button type="submit">Login</button>
{{#if errorMessage}}
<p>{{errorMessage}}</p>
{{/if}}
</form>
// app/controllers/login.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
authenticate() {
let { identification, password } = this.getProperties('identification', 'password');
this.get('session').authenticate('authenticator:oauth2', identification, password).catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});
ログイン
// app/controllers/application.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session')
…
});
{{!-- app/templates/application.hbs --}}
<div class="menu">
…
{{#if session.isAuthenticated}}
<a {{action 'invalidateSession'}}>Logout</a>
{{else}}
{{#link-to 'login'}}Login{{/link-to}}
{{/if}}
</div>
<div class="main">
{{outlet}}
</div>
はもっとここで読む:http://ember-simple-auth.com/api/classes/Configuration.html
をこれらのタスクの大半は、サーバー側の集中しています。あなたのためにEmber JSプラグインが表示されないのはそのためです。これらは、主にAPIによって処理される必要があります。 –
しかし、少なくとも5つのビューが実装される必要があり、途中でさらに異なる決定が行われます。 – Ante