Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration legacy database hack - stopped working? #1858

Closed
shanlalit opened this issue May 17, 2012 · 8 comments
Closed

Migration legacy database hack - stopped working? #1858

shanlalit opened this issue May 17, 2012 · 8 comments

Comments

@shanlalit
Copy link

I'm using Rails 3.1.4 on REE 1.8.7, updated from 2.0.4 to 2.1, now the legacy hack has stopped working.

In 2.0.4 it was working fine, in 2.1 it returning 401, do I need change anything?

@josevalim
Copy link
Contributor

What is the legacy database hack?

@josevalim
Copy link
Contributor

Btw, were you running on Devise 2.0.4 without deprecations warnings?

@shanlalit
Copy link
Author

I'm following this How To: Migration legacy database to migrate from clearance to Devise, the only change is sha1 instead of MD5. Yes it is working fine with 2.0.4 without deprecations warnings.

@josevalim
Copy link
Contributor

Looking at the wiki, i can't see any reason for that to stop working. Are
you getting an exception or it simply doesn't work anymore?

@shanlalit
Copy link
Author

It doesn't work. I'm using pry for debugging and tried to binding.pry inside

def valid_password_with_legacy?(password)
  binding.pry
.
.
end

But it's not called during authentication process.

@josevalim
Copy link
Contributor

I have updated the gist to use DatabaseAuthenticatable.class_eval, can you
confirm if it works now? Also, can you confirm if the file is being loaded
in the first place?

@shanlalit
Copy link
Author

Thanks Josevalim,

Issue is resolved. class_eval helped in debugging the issue.

My mistake I enabled config.pepper which triggered failed logins, and then enable encryptable which stooped executing this legacy support code.

Please accept my apologies for taking your valuable time, and thank you very much for helping me out.

@josevalim
Copy link
Contributor

@shanlalit now that you got it working, i would like to propose a better solution. Instead of using alias_method_chain, why don't you simply override it in your model and call super instead?

    class User
      def valid_password_with_legacy?(password)
        if self.legacy_password_hash.present?
          if ::Digest::MD5.hexdigest(password).upcase == self.legacy_password_hash
            self.password = password
            self.legacy_password_hash = nil
            self.save!
            true
          else
            false
          end
        else
          super
        end
      end

      def reset_password!(*args)
        self.legacy_password_hash = nil
        super
      end
    end

Can you try a solution along these lines and update the wiki if it works for you? Thanks! (closing this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants