开发者

Updating existing users with an Authlogic single_access_token

开发者 https://www.devze.com 2023-01-16 19:53 出处:网络
I currently use Authlogic in a web-app to handle user authentication, but have now decided to create a limited API which would seem to require the use of a single_access_token.

I currently use Authlogic in a web-app to handle user authentication, but have now decided to create a limited API which would seem to require the use of a single_access_token. My question is, how can I apply the migration to existing users?

I thought using something like

 add_column :users, :single_access_token, :string
 User.reset_column_information
 User.find(:all) do |c|
   c.update_attribute :single_access_token, *****
 end

I don't know if this is the best way, or what to put in 开发者_StackOverflow社区place of the ***** to generate a token for all already-registered users.

Thanks


I think

User.all.each{ |x| x.reset_single_access_token! }

is what you're looking for


Might be quicker if you have a lot of users:

User.find_each do |user|

  tok = Authlogic::Random.friendly_token

  str = "UPDATE users SET single_access_token = '#{tok}' WHERE id = #{user.id}"

  ActiveRecord::Base.connection.update_sql(str)

end
0

精彩评论

暂无评论...
验证码 换一张
取 消