forked from postalserver/postal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to create an initial admin user
- Loading branch information
Showing
5 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'highline' | ||
|
||
module Postal | ||
module UserCreator | ||
|
||
def self.start(&block) | ||
cli = HighLine.new | ||
puts "\e[32mPostal User Creator\e[0m" | ||
puts "Enter the information required to create a new Postal user." | ||
puts "This tool is usually only used to create your initial admin user." | ||
puts | ||
user = User.new | ||
user.email_address = cli.ask("E-Mail Address".ljust(20, ' ') + ": ") | ||
user.first_name = cli.ask("First Name".ljust(20, ' ') + ": ") | ||
user.last_name = cli.ask("Last Name".ljust(20, ' ') + ": ") | ||
user.password = cli.ask("Initial Password:".ljust(20, ' ') + ": ") { |value| value.echo = '*' } | ||
|
||
block.call(user) if block_given? | ||
if user.save | ||
puts | ||
puts "User has been created with e-mail address \e[32m#{user.email_address}\e[0m" | ||
puts | ||
else | ||
puts | ||
puts "\e[31mFailed to create user\e[0m" | ||
for error in user.errors.full_messages | ||
puts " * #{error}" | ||
end | ||
puts | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
trap("INT") { puts ; exit } | ||
|
||
require_relative '../config/environment' | ||
require 'postal/user_creator' | ||
|
||
Postal::UserCreator.start do |u| | ||
u.admin = true | ||
end |