2015-10-13 32 views
0

我试图实现烬一个认证系统具有以下版本:认证使用的余烬,简单的auth-装置和后轨后端

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 /用户/ 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}} 

templates/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

请求是否到达Rails后端? – marcoow

+0

yes,它返回'ActionController :: RoutingError(没有路由匹配[POST]“/ users/sign_in”):'(在上面添加了我的设计路线) –

+0

这意味着'/ users/sign_in'路线没有配置在Rails应用程序中,这是500错误 – marcoow

回答

1

在你的routes.rb文件,你可能需要在加: '用户'为设备为sign_in提供的默认路由为http://ip_address_to_your_server/sign_in,并且要创建自定义网址,如http://localhost:3000/users/sign_in,则必须将其映射到'用户'上。生成的代码看起来像

devise_for :users, at 'users',controllers: { sessions: 'sessions' } 

这样你就可以调用SessionsController在/用户

希望这有助于。否则,请考虑发布在rails后端实现的代码,因为问题出在Rails端。