Saturday 15 August 2015

ruby on rails - Authlogic ignoring password parameter -


Authlogic is ignoring the password parameter while creating a new user. Here are my users_controller classes:

  class Api :: V1 :: UsersController & lt; ApplicationController def can create @username = user.net (user_update) answer_to do it. Format | If @ user.save format.json {render: json = & gt; @ User: Status = & gt; : Created} and format.json {rendere: json = & gt; @ User.errors,: Status = & gt; : Unprocessable_entity} End End End Personal Def user_params params.require (user) .permit (: username,: email, password) end end   

and my user model:

  Class User & lt; ActiveRecord :: Base works_sa_Attract | C | C.require_password_confirmation = false end end   

When I send a POST request to / api / v1 / users / with a username, email and password parameter, authlogic says that password It can not be empty even though it is not. Printed by the Rails:

  Started Post "/ api / v1 / users /" for 127.0.0.1 2013-06-22 00:03:30 -0400 Processing by API :: V1 :: UsersController # create as * / * parameter: {"email" = & gt; "Someemail@website.com", "password" = & gt; "[FILTERED]", "username" = & gt; "MyUser", "user" = & gt; {"User name" = & gt; "myUser", "email" = & gt; "someemail@website.com"}} (0.2ms) BEGIN user exists (0.4ms) SELECT 1 AS "user" where low ("User". "Email") = LOWER ('someemail@website.com ') LIMIT 1 user exists (0.2ms) SELECT 1 AS = 1 from "less people" ("user". "User name") ( 'MyUser') limit 1 user exists (0.3ms) "them" where selected as one of "those" "persistence_token" 1 = '7b72bab3627914d33e83e4efe1c5a9dab190750efb227698c8b5b6be7a7ccf118160d8e12623078543e0f4e5f31eb30828799cb0d97fb2af195daee894c79902' limit 1 (0.2ms) 33ms in ROLLBACK (view all 422 UnprocessableKai .: 0.2ms | ActiveRecord: 3.2ms)   

I am using the latest authlogic and Ruby 2 / rail 4.

Take a look at a fraction of the rail log:

  { "Email" = & gt; "Someemail @ website" "user name" = & gt; {"User name" = & gt; "myUser", "email" = & gt; "some mmail", "password" => gt; "[FILTERED]", "username" = & gt; "myUser" @ Website.com "}} It seems that you send a slightly wrong parameter to get recognition by Authlogic, the  password  parameter should be sent to  the user < The parameters under the / code> key should be in the hash i.e. This line should appear in this way from the line log (note at the end of the string):  
  {"email" => "Someemail@website.com", "password" = & Gt; "[FILTERED]", "username" = & gt; "myUser", "user" = & gt; {"username" = & gt; "myUser", "email" = & gt; "someemail @ Website.com "," password "=> 
" [FILTERED] "}}

To fix this, you can do a hack like this:

  Private def user_params params.require (: Users) Alternatively, you can adjust the parameters sent from the client side (for example,    

Code> user [password] parameter name when sending the request HTTP POST only password Urd instead of ).

No comments:

Post a Comment