-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
55 lines (52 loc) · 1.42 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Bundler.setup
require 'date'
Dir.glob('./{models}/*.rb').each {|file| require file }
begin
# bundle exec rake "admin:create"
namespace :admin do
task :create do
create_admin
end
end
end
class String
def is_number?
true if Float(self) rescue false
end
end
def create_admin
puts "You will be prompted to enter an username, email and password for the new admin"
puts "Username: "
username = STDIN.gets.chomp
puts "Email: "
email = STDIN.gets.chomp
puts "Password: "
password = STDIN.gets.chomp
puts "Repeat password: "
repeat = STDIN.gets.chomp
if username.is_number?
puts "Sorry, the username need more letters."
return
end
unless password == repeat
puts "Sorry, password not matches."
return
end
unless email.to_s.empty? || username.to_s.empty? || password.to_s.empty?
if @user = User.create(:username => username,
:email => email,
:password => password,
:role => :admin)
@user.user_media = UserMedia.create
@user.user_information = UserInformation.create
@user.save
@user.user_media.save
@user.user_information.save
DataMapper.finalize.auto_upgrade!
puts "The admin was created successfully...
Admin: #{username} Date: #{DateTime.now}"
else
puts "Sorry, the admin was not created!"
end
end
end