Rails: configure module. Confirmation module?

I have a Rails application setup with Devise , but it is still under development. I also have a Thor task that creates the default admin user.

The problem is that Devise will not allow this administrator user to log in until the account is verified. Is it possible to disable the confirmation module to create specific users, such as Admin?

My Thor task:

class Setup < Thor
  desc "create_admin [EMAIL] [PASSWORD]", "Creates the administrative user."
  def create_admin(email = "admin@bogus.com", password = "testpassword123")
    require File.expand_path('config/environment.rb') # load Rails environment
    admin = User.create(:email => email, :password => password, :password_confirmation => password)
    admin.assign_role :admin
    puts "Admin user (#{ email }) created."
  end
end
+3
source share
3 answers

Once your user is created, you can call, provided that you have confirmation! method, not directly update the database. For instance:.

admin = User.create(:email => email, :password => password, :password_confirmation => password)
admin.assign_role :admin
admin.confirm!
+6

admin = User.create(:email => email, :password => password, :password_confirmation => password)

, confirm_at , , .

, , , , .

admin.update_attributes(:confirmed_at => Time.now)
+2

just coment :confirmablein user or admin model

devise :database_authenticatable, :recoverable, :rememberable, :trackable, #:confirmable...

In config / inicializers / devise.rb you can specify how long the user must confirm his account.

-1
source

Source: https://habr.com/ru/post/1780248/


All Articles