我的ember js app未正确验证会话。它将正确发布到数据库,但不会对会话进行身份验证。我正在使用rails 4,ember-simple-auth1.1.0和ember 2.5
Rails会话控制器
class SessionsController < Devise::SessionsController
respond_to :html, :json
def create
super do |user|
if request.format.json?
data = {
token: user.authentication_token,
email: user.email
}
render json: data, status: 201 and return
end
end
end
end
Ember登录控制器
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:devise', identification, password)
.then(() =>{
this.transitionToRoute('posts')
})
.catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});
Login.hbs
{{#modal-dialog close="goBackToList"}}
{{login-form }}
{{/modal-dialog}}
登录-form.hbs
<form {{action "authenticate" on="submit"}}>
<div class="form-group">
<label for="identification">Login</label>
{{input class="form-control" value=identification placeholder="Enter Login"}}
</div>
<div class="form-group">
<label for="password">Password</label>
{{input class="form-control" value=password type="password" placeholder="Enter Password"}}
</div>
<button class="btn btn-default" type="submit">Login</button>
</form>
{{#if errorMessage}}
{{errorMessage}}
{{/if}}
找到