Ruby on rails 使用ember cli simple auth Desive时,Rails始终返回401

Ruby on rails 使用ember cli simple auth Desive时,Rails始终返回401,ruby-on-rails,devise,ember-cli,Ruby On Rails,Devise,Ember Cli,一般来说,编程非常新,对Rails的经验很少,对ember的经验很少甚至没有。目前,我可能过于雄心勃勃地使用余烬“构建雄心勃勃的网络应用程序”。我无法正确使用Desive设置进行身份验证。当尝试通过ember进行身份验证时,它总是返回401。出于某种原因,当我通过github页面对ember simple auth进行一些必要的更改以使其工作时,我的rails“flash messages”开始出错。就像我通过html浏览器访问/users/sign_时一样。在我展示了我认为相关的代码之后,会有

一般来说,编程非常新,对Rails的经验很少,对ember的经验很少甚至没有。目前,我可能过于雄心勃勃地使用余烬“构建雄心勃勃的网络应用程序”。我无法正确使用Desive设置进行身份验证。当尝试通过ember进行身份验证时,它总是返回401。出于某种原因,当我通过github页面对ember simple auth进行一些必要的更改以使其工作时,我的rails“flash messages”开始出错。就像我通过html浏览器访问/users/sign_时一样。在我展示了我认为相关的代码之后,会有更多的细节。如果我遗漏了什么,请告诉我还需要发布什么

我正在使用以下设置:

  • 余烬cli:0.1.15

  • ember cli简单身份验证:0.7.3

  • ember cli简单身份验证装置:0.7.3

我是否同时需要简单身份验证和简单身份验证装置,或者ember cli简单身份验证装置是否包含/包含ember cli简单身份验证?

  • rails:4.2.0

  • 设计:3.4.1

余烬代码

config/environment.js



    ENV['simple-auth'] = {
      authorizer: 'simple-auth-authorizer:devise',
    };

    ENV['simple-auth-devise'] = {
      crossOriginWhitelist: ['*'],
      //serverTokenEndpoint: 'http://localhost:3000/users/sign_in'
      //I have tried it both with and with out serverTokenEndpoint
    };

app/controllers/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'
        });

app/routes/protected.js



    import Ember from 'ember';
    import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';

    export default Ember.Route.extend(AuthenticatedRouteMixin);


app/templates/login.hbs



    
        Login
        {{input value=identification placeholder='Enter Login'}}
        Password
        {{input value=password placeholder='Enter Password' type='password'}}
        Login
    

Rails代码

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  #commented the following out to rule it out.
  #protect_from_forgery with: :null_session

  before_filter :authenticate_user_from_token!

  before_filter :authenticate_user!

  def authenticate_user_from_token!
    authenticate_with_http_token do |token, options|
      user_email = options[:user_email].presence
      user = user_email && User.find_by_email(user_email)

      if user && Devise.secure_compare(user.authentication_token, token)
        sign_in user, store: false
      end
    end
  end

end
class SessionsController < Devise::SessionsController
  respond_to :html, :json

  def create
    super do |user|
      if request.format.json?
        data = {
          token:      user.authentication_token,
          user_email: user.email
        }
        render json: data, status: 201 and return
      end
    end
  end
end
当我提交余烬登录表单时,无论我提交什么,我都会收到回复:

Started POST "/users/sign_in" for 127.0.0.1 at 2015-03-04 19:50:57 -0500
Processing by SessionsController#create as JSON
  Parameters: {"user"=>{"password"=>"[FILTERED]", "user_email"=>"foo@bar.com"}}
Completed 401 Unauthorized in 7ms
如果我访问,我会收到以下信息:

/app/views/layouts/application.html.erb where line #11 raised:

undefined method `flash' for #<ActionDispatch::Request:0x007fec37dfe708>
/app/views/layouts/application.html.erb,其中第11行出现:

#

的未定义方法“flash”此问题已由解决。只需根据修订版更新您的
app/controllers/application\u controller.rb
app/controllers/sessions\u controller.rb
。 还加


config/environment.js
中的
ENV['simple-auth-designe']
。一旦释放拉动请求的更改,可以再次删除最后添加的内容。

谢谢!成功了。不知道我怎么会错过。我是github的新手,所以对于发布版本中的内容和master中的内容有点困惑。再次感谢!和这件事斗争了很长时间。非常感谢。
  resources :specials

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

  root to: 'specials#index'
Started POST "/users/sign_in" for 127.0.0.1 at 2015-03-04 19:50:57 -0500
Processing by SessionsController#create as JSON
  Parameters: {"user"=>{"password"=>"[FILTERED]", "user_email"=>"foo@bar.com"}}
Completed 401 Unauthorized in 7ms
/app/views/layouts/application.html.erb where line #11 raised:

undefined method `flash' for #<ActionDispatch::Request:0x007fec37dfe708>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
identificationAttributeName: 'email'