【发布时间】:2015-10-13 17:19:53
【问题描述】:
我正在尝试使用以下版本在 ember 中实现身份验证系统:
DEBUG: -------------------------------
ember.debug.js:5378 DEBUG: Ember : 1.13.7
ember.debug.js:5378 DEBUG: Ember Data : 1.13.8
ember.debug.js:5378 DEBUG: jQuery : 1.11.3
ember.debug.js:5378 DEBUG: Ember Simple Auth : 0.8.0
ember.debug.js:5378 DEBUG: Ember Simple Auth Devise : 0.8.0
ember.debug.js:5378 DEBUG: -------------------------------
我按照https://github.com/simplabs/ember-simple-auth/tree/master/packages/ember-simple-auth-devise github 上的说明进行操作
现在当我点击“注册”时,它返回 500 错误:
POST http://localhost:4200/users/sign_in 500 (Internal Server Error)
我觉得应该去 localhost:3000/users/sign_in,但不是。
我使用ember s --proxy http://localhost:3000 命令启动了服务器,但不明白发生了什么。
这是我的参考代码:
控制器/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:devise'
});
路由/login.js
import Ember from 'ember';
import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(UnauthenticatedRouteMixin);
模板/application.hbs
<h2 id="title">Welcome to Ember.js - With Authentication!</h2>
{{#if session.isAuthenticated}}
Hi, {{session.email}}
<br/>
You can't see this text unless you're logged in!
<br/>
Click this button to logout:
<button {{action 'invalidateSession'}}>Logout</button>
<br/>
If you try to go to the
{{#link-to "login"}}Login{{/link-to}}
page, you should get redirected!
{{else}}
{{#link-to "login"}}Login{{/link-to}}
{{/if}}
{{outlet}}
模板/login.hbs
<form {{action "authenticate" on="submit"}}>
<div>
<label for="identification">E-mail</label><br />
{{input value=identification placeholder="E-mail" type="text" name="email"}}
</div>
<div>
<label for="password">Password</label><br />
{{input value=password placeholder="Password" type="password" name="password"}}
</div>
<div>
<button type="submit">Log in</button>
</div>
</form>
config/environment.js
...
ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise'
}
ENV['simple-auth-devise'] = {
tokenAttributeName: 'token',
identificationAttributeName: 'email'
}
...
我的 Rails 路线如下所示:
devise_for :users, controllers: { sessions: 'sessions' }
【问题讨论】:
-
请求是否到达过 Rails 后端?
-
是的,它返回,
ActionController::RoutingError (No route matches [POST] "/users/sign_in"):(在上面添加了我的设计路线) -
这意味着
/users/sign_in路由没有在 Rails 应用程序中配置,这是 500 错误
标签: ember.js ember-simple-auth