2015-10-13 27 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端。