我正在尝试使用以下版本在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: -------------------------------
我按照github上https://github.com/simplabs/ember-simple-auth/tree/master/packages/ember-simple-auth-devise
的说明进行操作现在,当我点击'注册'时,它返回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>
配置/ environment.js
...
ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise'
}
ENV['simple-auth-devise'] = {
tokenAttributeName: 'token',
identificationAttributeName: 'email'
}
...
我的铁路路线如下:
devise_for :users, controllers: { sessions: 'sessions' }
答案 0 :(得分:1)
在您的routes.rb文件中,您可能需要添加 at:&#39; users&#39; ,因为sign_in为http://ip_address_to_your_server/sign_in设置的默认路由并创建您的自定义像http://localhost:3000/users/sign_in这样的网址,您必须将其映射到用户&#39;。生成的代码看起来像
devise_for :users, at 'users',controllers: { sessions: 'sessions' }
这样您就可以在/ users
中调用SessionsController希望这会有所帮助。否则请考虑发布在rails后端实现的代码,因为问题出在Rails端。