forked from fixin.me/fixin.me
		
	Add user statuses and seed admin user
This commit is contained in:
		
							parent
							
								
									d2fbacbf62
								
							
						
					
					
						commit
						e29c060a39
					
				@ -28,7 +28,7 @@ Copy config template and update database configuration:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Run database creation and migration tasks:
 | 
					Run database creation and migration tasks:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    RAILS_ENV="production" bundle exec rake db:create db:migrate
 | 
					    RAILS_ENV="production" bundle exec rake db:create db:migrate db:seed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Running
 | 
					## Running
 | 
				
			||||||
 | 
				
			|||||||
@ -3,4 +3,13 @@ class User < ApplicationRecord
 | 
				
			|||||||
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
 | 
					  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
 | 
				
			||||||
  devise :database_authenticatable, :registerable,
 | 
					  devise :database_authenticatable, :registerable,
 | 
				
			||||||
         :recoverable, :rememberable, :validatable
 | 
					         :recoverable, :rememberable, :validatable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # Statuses ordered by decreasing privileges
 | 
				
			||||||
 | 
					  enum :status, {
 | 
				
			||||||
 | 
					    admin: 1,       # admin level access
 | 
				
			||||||
 | 
					    active: 2,      # read-write user level access
 | 
				
			||||||
 | 
					    restricted: 3,  # read-only user level access
 | 
				
			||||||
 | 
					    locked: 4,      # disallowed to sign in due to failed logins
 | 
				
			||||||
 | 
					    disabled: 5     # administratively disallowed to sign in
 | 
				
			||||||
 | 
					  }, default: :active
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -35,8 +35,12 @@ module FixinMe
 | 
				
			|||||||
    #
 | 
					    #
 | 
				
			||||||
    # URL to use in sent e-mails.
 | 
					    # URL to use in sent e-mails.
 | 
				
			||||||
    config.action_mailer.default_url_options = {host: 'localhost'}
 | 
					    config.action_mailer.default_url_options = {host: 'localhost'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # List of hosts this app is available at.
 | 
					    # List of hosts this app is available at.
 | 
				
			||||||
    # https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization
 | 
					    # https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization
 | 
				
			||||||
    config.hosts << 'localhost'
 | 
					    config.hosts << 'localhost'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Email address of admin account
 | 
				
			||||||
 | 
					    config.admin = 'admin@localhost'
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -178,7 +178,7 @@ Devise.setup do |config|
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  # ==> Configuration for :validatable
 | 
					  # ==> Configuration for :validatable
 | 
				
			||||||
  # Range for password length.
 | 
					  # Range for password length.
 | 
				
			||||||
  config.password_length = 6..128
 | 
					  config.password_length = 5..128
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Email regex used to validate email formats. It simply asserts that
 | 
					  # Email regex used to validate email formats. It simply asserts that
 | 
				
			||||||
  # one (and only one) @ exists in the given string. This is mainly
 | 
					  # one (and only one) @ exists in the given string. This is mainly
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										20
									
								
								db/seeds.rb
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								db/seeds.rb
									
									
									
									
									
								
							@ -1,7 +1,13 @@
 | 
				
			|||||||
# This file should contain all the record creation needed to seed the database with its default values.
 | 
					# This file should contain all the record creation needed to seed the database
 | 
				
			||||||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
 | 
					# with its default values. The data can then be loaded with the
 | 
				
			||||||
#
 | 
					#   bin/rails db:seed
 | 
				
			||||||
# Examples:
 | 
					# command (or created alongside the database with db:setup).
 | 
				
			||||||
#
 | 
					# Seeding process should be idempotent.
 | 
				
			||||||
#   movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
 | 
					
 | 
				
			||||||
#   Character.create(name: "Luke", movie: movies.first)
 | 
					User.transaction do
 | 
				
			||||||
 | 
					  User.find_or_create_by!(status: :admin) do |user|
 | 
				
			||||||
 | 
					    user.email = Rails.configuration.admin
 | 
				
			||||||
 | 
					    user.password = 'admin'
 | 
				
			||||||
 | 
					    puts "Admin account '#{user.email}' created with default password '#{user.password}'"
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user