小编obo*_*obo的帖子

Ember-simple-auth,Torii和Facebook Oauth2的工作流程

我之前关于ember-simple-auth和torii的问题之后,我使用他们的Facebook帐户成功验证了我的用户.

但目前,torii的提供商facebook-oauth2正在从Facebook返回授权码; 当承诺解决时,我将此授权代码发送到我的后端,在那里我执行针对Facebook的请求以获取用户的ID和电子邮件:然后我在我的后端验证用户,生成特定的访问令牌并发送回我的ember应用程序.

客户代码:

// app/controllers/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';

export
default Ember.Controller.extend(LoginControllerMixin, {
    // This authenticator for a simple login/password authentication.
    authenticator: 'simple-auth-authenticator:oauth2-password-grant',
    actions: {
        // This method for login with Facebook.
        authenticateWithFacebook: function() {
            var _this = this;
            this.get('session').authenticate(
                'simple-auth-authenticator:torii',
                "facebook-oauth2"
            ).then(
                function() {
                    var authCode = _this.get('session.authorizationCode');
                    Ember.$.ajax({
                            type: "POST",
                            url: window.ENV.host + "/facebook/auth.json",
                            data: JSON.stringify({
                                    auth_code: authCode
                            }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function(data) {
                                    // TODO : manage …
Run Code Online (Sandbox Code Playgroud)

authentication facebook ember.js ember-simple-auth

17
推荐指数
1
解决办法
4033
查看次数

如何使用coffeescript隐藏和显示div - Rails 3.1

我试图在Stack Overflow中的问题上做出与评论链接类似的行为.单击应隐藏包含"添加注释"链接的div,并显示包含新注释表单的另一个div.

怎么可能用coffeescript做到这一点?

我正在尝试以下不起作用:

jQuery ->

  hide_comment_link = () ->
    $('#add_comment_link').hide
  hide_comment = () ->
    $('#add_comment').hide
  show_comment = () ->
    $('#add_comment').show

  $('#add_comment_link').click ->
    hide_comment_link
    show_comment
    false
Run Code Online (Sandbox Code Playgroud)

查看是:

#add_comment_link
  #{link_to "Add a comment"}
#add_comment
  Add a comment in this div.
Run Code Online (Sandbox Code Playgroud)

jquery ruby-on-rails coffeescript ruby-on-rails-3.1

10
推荐指数
2
解决办法
1万
查看次数

Android LinearLayout填充宽度

我想知道为什么会这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:gravity="center_vertical"
    android:layout_height="wrap_content" android:layout_gravity="top"
    android:background="@drawable/gradient" android:focusable="true"
    android:paddingTop="5dip" android:paddingBottom="5dip"
    android:focusableInTouchMode="true">
        <EditText android:id="@+id/searchField"
            android:layout_width="wrap_content" android:layout_height="fill_parent"

            android:paddingTop="2dip" android:paddingBottom="2dip"
            android:paddingLeft="10dip" android:paddingRight="10dip"
            android:inputType="textVisiblePassword" android:radius="5dip"
            android:layout_marginLeft="10dip"
            android:background="@drawable/search_background" android:textColor="#000000" />

        <Button android:id="@+id/info" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:background="@drawable/info_btn" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如果我将"fill_parent"设置为我的EditText的layout_width,它将占用父级的整个宽度,按钮消失(我猜它隐藏在EditText下面).

有人可以解释一下吗?我想让Button获得自己的宽度,EditText获取剩余的宽度.

android android-linearlayout

8
推荐指数
1
解决办法
1万
查看次数

如何使用rspec测试Mongoid :: Observer

在一个简单的mongoid数据模型上,用户有很多评论,我想在用户写至少一条评论时给用户一个特定的徽章.所以我建立了一个像这样的观察者:

class CommentBadgeObserver < Mongoid::Observer
  observe :comment

  def after_create(comment)
    CommentBadge.check_conditions_for(comment.user)
  end
end

class CommentBadge < Badge
  def self.check_conditions_for(user)
    if user.comments.size > 1
      badge = CommentBadge.create(:title => "Comment badge")
      user.award(badge)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

user.award方法:

def award(badge)
  self.badges << badge
  self.save
end
Run Code Online (Sandbox Code Playgroud)

以下测试失败(但我想这是正常的,因为观察者在后台执行?)

it 'should award the user with comment badge' do
    @comment = Factory(:comment, :user => @user)
    @user.badges.count.should == 1
    @user.badges[0].title.should == "Comment badge"
end
Run Code Online (Sandbox Code Playgroud)

什么是验证此行为的最佳方法?

ruby rspec ruby-on-rails mongoid observer-pattern

8
推荐指数
1
解决办法
1164
查看次数

如何使用rspec在设计中测试json登录

我正在尝试使用设计构建rails登录过程,允许用户通过移动应用程序登录/注销.

我创建了一个像这样的SessionsController:

class SessionsController < Devise::SessionsController

  def create  
    resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    sign_in(resource_name, resource)

    respond_to do |format|  
      format.html { super }  
      format.json {  
        render :status => 200, :json => { :error => "Success", :user =>  resource}.to_json  
      }  
    end  
  end

  def destroy  
    super  
  end
end
Run Code Online (Sandbox Code Playgroud)

我的路线:

devise_for :users, :controllers => {:sessions => "sessions"}
resources :users
Run Code Online (Sandbox Code Playgroud)

然后我有以下规范来测试这个过程:

require 'spec_helper'

describe SessionsController do

  describe "POST 'signin'" do

    before (:each) do
      @user = Factory(:user)
    end

    it …
Run Code Online (Sandbox Code Playgroud)

authentication json ruby-on-rails devise rspec2

7
推荐指数
1
解决办法
2701
查看次数

Emberjs:如何在模型操作上显示加载微调器和通知消息

我正在使用ember.js 1.2并在尝试在模型上的crud操作期间显示加载微调器和通知消息时遇到问题.

这是代码:

var MyModelController = Ember.ObjectController.extend({
  needs: ['application'],
  application: Ember.computed.alias("controllers.application"),
  actions: {
    save: function() {
      var _this = this;

      // Display the spinner
      this.get('application').get('loading').trigger(true);

      this.get('model').save().then(function(response) {
        // Hide the spinner
        _this.get('application').get('loading').trigger(false);

        // Display the success message
        _this.get('application').get('flash').success('The model has been updated.');
      }, function(response) {
        // Hide the loading spinner
        _this.get('application').get('loading').trigger(false);

        // Display the error message
        _this.get('application').get('flash').danger('Error updating the model.');
      });
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

这里有两个主要问题:

  • 首先:显示微调器,其转换时间为0.5秒,但保存操作的持续时间较短,微调器显示并立即消失.这里我想在我的模型上调用保存操作之前设置一个1s计时器,以确保正确执行动画.怎么可能呢?

  • 第二:我的flash对象上的成功方法绑定到模板上的特定{{view.message}}.如果我在promise的'then'之外调用此方法,则会很好地显示消息,但在我的情况下,并不是绑定没有完成.我是否错过了使用承诺的方式?怎么可能显示这条消息?

javascript binding promise ember.js ember-data

6
推荐指数
2
解决办法
6681
查看次数

使用Devise和token_authenticatable登录rails应用程序:"401 unauthorized"

我正在尝试使用Devise和authenticatable_token构建一个API来登录我的rails应用程序.我在我的API模块中创建了一个SessionsController,并将以下代码写入sign_in:

module Api
  module V1
    class SessionsController < Devise::SessionsController

      def create  
        resource = warden.authenticate!(scope: resource_name, recall: "#{controller_path}#new")
        sign_in(resource_name, resource) 
        if current_user  
          if !current_user.authentication_token  
            current_user.reset_authentication_token! 
          end
          render json: {success: true, auth_token: resource.authentication_token, email: resource.email}
        else 
          invalid_login_attempt
        end 
      end

      protected

      def invalid_login_attempt
        warden.custom_failure!
        render json: {success: false, message: "Error with your login or password"}, status: 401
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

问题是当我使用没有任何令牌的登录时,应用程序会引发401.

RestClient.post "http://localhost:3000/api/v1/users/sign_in", {user: {email: "tester@test.biz", password: "FILTERED"}}.to_json, :content_type => :json, :accept => :json
Run Code Online (Sandbox Code Playgroud)

但是,如果我设置由注册方法提供的令牌,它可以工作:

response_json = RestClient.post "http://localhost:3000/api/v1/users/sign_in?auth_token=#{@token}", {user: {email: "tester@test.biz", …
Run Code Online (Sandbox Code Playgroud)

authentication api ruby-on-rails devise ruby-on-rails-3

5
推荐指数
1
解决办法
5482
查看次数

rvmsudo:找不到命令

我正在按照这篇伟大的帖子在ubuntu 10.10上配置我的rails生产服务器:rails production

当我想执行命令时:

rvmsudo passenger-install-nginx-module

我收到错误: rvmsudo : command not found

有谁能够帮我 ?提前致谢 !

sudo rvm ubuntu-10.10 ruby-on-rails-3

4
推荐指数
2
解决办法
8726
查看次数

Rails:如何从lib文件夹中获取文件以便在控制器中使用它们?

我的lib /中有一个特定的app文件夹,其中包含与rails无关的所有内容.这是结构:

lib/ |myapp/ |repositories/ |repo1.rb |repo2.rb |use_cases/ |use_case1.rb |use_case2.rb

我在我的autoload_path中添加了lib文件夹,如下所示:

config.autoload_paths += Dir["#{config.root}/lib/**/"]
Run Code Online (Sandbox Code Playgroud)

如果我想在我的一个控制器中使用UseCase1,我必须指定完整路径:

MyApp::UseCases::UseCase1.new

存储库也是如此.

有没有办法全局要求它,因为我只能在我的控制器中使用UseCase1.new?

ruby ruby-on-rails

1
推荐指数
1
解决办法
2004
查看次数