Sha256: a51339057b09e65285f0b83f647b7e6b75e45aeb02c108598c04b9097d3be0fe

Contents?: true

Size: 1016 Bytes

Versions: 9

Compression:

Stored size: 1016 Bytes

Contents

require 'highline/import'

def default_email
  'comable@example.com'
end

def default_password
  'password'
end

def ask_admin_email
  if ENV['ADMIN_EMAIL']
    ENV['ADMIN_EMAIL']
  else
    ask("Email [#{default_email}]: ") do |q|
      q.echo = true
      q.whitespace = :strip
    end
  end.presence || default_email
end

def ask_admin_password
  if ENV['ADMIN_PASSWORD']
    ENV['ADMIN_PASSWORD']
  else
    ask("Password [#{default_password}]: ") do |q|
      q.echo = false
      q.whitespace = :strip
    end
  end.presence || default_password
end

def create_admin_user
  email = ask_admin_email
  password = ask_admin_password

  if Comable::User.where(email: email).exists?
    puts "WARNING: The email address has already existed: #{email}"
  else
    Comable::User.with_role(:admin).new do |obj|
      obj.email = email
      obj.password = password
    end.save!
  end
end

if Comable::User.with_role(:admin).exists?
  puts 'Admin user has already been previously created.'
else
  create_admin_user
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
comable-core-0.7.1 db/seeds/comable/users.rb
comable-core-0.7.0 db/seeds/comable/users.rb
comable-core-0.7.0.beta2 db/seeds/comable/users.rb
comable-core-0.7.0.beta1 db/seeds/comable/users.rb
comable-core-0.6.0 db/seeds/comable/users.rb
comable_core-0.5.0 db/seeds/comable/users.rb
comable_core-0.4.2 db/seeds/comable/users.rb
comable_core-0.4.1 db/seeds/comable/users.rb
comable_core-0.4.0 db/seeds/comable/users.rb