How to skip has_secure_password validations

后端 未结 3 524
忘掉有多难
忘掉有多难 2020-12-09 03:22

In my app, only admins can create new User records. The user is emailed an activation link where they set their password.

I\'d like to use the has_secure_passord met

3条回答
  •  情深已故
    2020-12-09 04:24

    There's no way to skip the validation, but it would be easy enough to write your own version of the method that allows you to pass an argument to determine whether or not to validate presence of the password_digest field.

    Just extend ActiveModel the same way they do in the SecurePassword module (via ActiveSupport::Concern) and add your own secure password method.

    i.e.

    module ActiveModel
      module MySecurePassword
        extend ActiveSupport::Concern
    
        module ClassMethods
          def my_has_secure_password(validate_password_digest=true)
            # you custom logic
          end
        end
      end
    end
    

提交回复
热议问题