从CakePHP的Rails的设计传统用户 [英] Rails Devise Legacy Users from CakePHP

查看:400
本文介绍了从CakePHP的Rails的设计传统用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近买了制定工作。新用户登录,注册,注销等等等等就好了。然而,老用户有一个问题。我有它得到一个地步,我得到一个401未经授权,这在我看来,这只是错误地创建哈希登录时,当然不能正确匹配。

I recently got Devise working. New users sign in, sign up, logout etc etc just fine. Old users however have an issue. I have gotten it to a point where I get a 401 unauthorized, which seems to me that the hash is just incorrectly being created when signing in and of course not matching correctly.

我的用户模型:

class User < ActiveRecord::Base
  require "digest/sha1"
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :encryptable, :encryptor => :old_cakephp_auth

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
  has_many :events
end

CakePHP的使用SHA1,但我不知道它是如何做的事情的具体细节。这显然​​是不行的,这就是为什么我在这里:

Cakephp uses sha1, but I don't know the specifics of how it does things. This obviously doesn't work, which is why I am here:

require "digest/sha1"

module Devise
  module Encryptors
    class OldCakephpAuth < Base
      def self.digest(password, stretches, salt, pepper)
        Digest::SHA1.hexdigest("#{salt}#{password}")
      end
    end
  end
end

我从如何添加自定义加密的例子。他们有这样的:

I got that from the how to add a custom encryptor example. They had this:

Digest::SHA1.hexdigest("--#{salt}--#{password}--")

这也不能工作。任何人有什么想法?

That didn't work either. Anyone have any ideas?

推荐答案

我看到这对创建自己的自定义加密维基的变化。我不知道我怎么没有看到过它。也许有人最近更新它。

I saw a variation of this on the create your own custom encryptor wiki. I don't know how I didn't see it before. Perhaps someone updated it recently.

将在用户模式下。它应该覆盖有效的密码从色器件:

Place the following in your user model. It should overwrite valid password from devise:

  def valid_password?(password)
    return false if encrypted_password.blank?
    Devise.secure_compare(Digest::SHA1.hexdigest(self.password_salt+password), self.encrypted_password)
  end

您需要确保填写密码的食盐,在蛋糕中使用到所有的传统用户的行。您还需要更改密码加密口令根据制定的指示。

You need to make sure to fill in the password salt you used in cake into all legacy user's rows. You also need to change password to encrypted password according to devise's instructions.

我觉得我可能需要添加从用户模型的方式加密,以及为新用户。或许我创建的自定义加密处理这方面。

I feel like I may need to add a way encrypt from user model as well for new users. Or perhaps the custom encryptor I created handles that aspect.

这篇关于从CakePHP的Rails的设计传统用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆