1

Authlogic は、新しいユーザーを作成するときにパスワード パラメータを無視しているようです。これが私のusers_controllerクラスです:

class Api::V1::UsersController < ApplicationController

  def create
    @user = User.new(user_params)

    respond_to do |format|
      if @user.save
        format.json  { render :json => @user, :status => :created}
      else
        format.json  { render :json => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

  private
  def user_params
    params.require(:user).permit(:username, :email, :password)
  end

end

そして私のユーザーモデル:

class User < ActiveRecord::Base
    acts_as_authentic do |c|
      c.require_password_confirmation = false
    end
end

/api/v1/users/ にユーザー名、電子メール、およびパスワードのパラメーターを指定して POST 要求を送信すると、authlogic はパスワードを空白にすることはできないと言いますが、そうではありません。Railsによって出力されたものは次のとおりです。

Started POST "/api/v1/users/" for 127.0.0.1 at 2013-06-22 00:03:30 -0400
Processing by Api::V1::UsersController#create as */*
  Parameters: {"email"=>"someemail@website.com", "password"=>"[FILTERED]", "username"=>"myUser", "user"=>{"username"=>"myUser", "email"=>"someemail@website.com"}}
   (0.2ms)  BEGIN
  User Exists (0.4ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('someemail@website.com') LIMIT 1
  User Exists (0.2ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."username") = LOWER('myUser') LIMIT 1
  User Exists (0.3ms)  SELECT 1 AS one FROM "users" WHERE "users"."persistence_token" = '7b72bab3627914d33e83e4efe1c5a9dab190750efb227698c8b5b6be7a7ccf118160d8e12623078543e0f4e5f31eb30828799cb0d97fb2af195daee894c79902' LIMIT 1
   (0.2ms)  ROLLBACK
Completed 422 Unprocessable Entity in 33ms (Views: 0.2ms | ActiveRecord: 3.2ms)

最新の authlogic と Ruby 2/Rails 4 を使用しています。

4

2 に答える 2

0

これを試してください:-

acts_as_authentic do |config|
  config.check_passwords_against_database = false
  config.validate_password_field = false
  config.crypted_password_field = false
end
于 2013-06-22T05:15:50.223 に答える