jungle_path 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/jungle_path.gemspec +4 -1
- data/lib/jungle_path/api/helpers/auth.rb +6 -10
- data/lib/jungle_path/api/helpers/defaults.rb +7 -6
- data/lib/jungle_path/api/helpers/logging.rb +7 -1
- data/lib/jungle_path/api/helpers.rb +2 -2
- data/lib/jungle_path/api/template.erb +2 -2
- data/lib/jungle_path/app/api/{server_base.rb → base.rb} +24 -23
- data/lib/jungle_path/app/api/{server_custom.rb → custom.rb} +15 -16
- data/lib/jungle_path/app/api/{server_gen.rb → generated.rb} +2 -2
- data/lib/jungle_path/app/auth/authorization.rb +15 -14
- data/lib/jungle_path/app/config/config.rb +8 -9
- data/lib/jungle_path/app/config/override.rb +2 -1
- data/lib/jungle_path/app/config.ru +6 -5
- data/lib/jungle_path/app/controllers/controller.rb +197 -0
- data/lib/jungle_path/app/controllers/generated.rb +13 -0
- data/lib/jungle_path/app/db/db.rb +13 -0
- data/lib/jungle_path/app/schemas/schema.rb +81 -0
- data/lib/jungle_path/app/services/email.rb +138 -0
- data/lib/jungle_path/app/services/sms.rb +17 -0
- data/lib/jungle_path/app/web_apps/public/index.html +10 -0
- data/lib/jungle_path/app/ztools/db/migrations/000_root.rb +1 -0
- data/lib/jungle_path/app/ztools/zbootstrapdata.rb +57 -0
- data/lib/jungle_path/app/ztools/zcreatedb.rb +19 -0
- data/lib/jungle_path/app/ztools/zgen.rb +9 -0
- data/lib/jungle_path/app/ztools/zgen_node_tree.rb +14 -0
- data/lib/jungle_path/app/ztools/zmigrate.rb +7 -0
- data/lib/jungle_path/app/ztools/zport_data.rb +292 -0
- data/lib/jungle_path/authentication/auth_provider/default.rb +36 -29
- data/lib/jungle_path/authentication/data_provider/default.rb +55 -109
- data/lib/jungle_path/authentication/data_provider/test.rb +149 -0
- data/lib/jungle_path/authentication/data_provider.rb +1 -0
- data/lib/jungle_path/authentication/identity.rb +4 -4
- data/lib/jungle_path/authentication/password_hash.rb +8 -8
- data/lib/jungle_path/authorization/filter.rb +0 -3
- data/lib/jungle_path/config.rb +1 -1
- data/lib/jungle_path/controller/template.erb +2 -2
- data/lib/jungle_path/db_access.rb +6 -0
- data/lib/jungle_path/file/file.rb +21 -0
- data/lib/jungle_path/file.rb +3 -0
- data/lib/jungle_path/gen/api.rb +3 -3
- data/lib/jungle_path/gen/controllers.rb +20 -0
- data/lib/jungle_path/gen/db.rb +77 -0
- data/lib/jungle_path/gen/schema.rb +2 -2
- data/lib/jungle_path/gen.rb +1 -1
- data/lib/jungle_path/migration/migration.rb +31 -0
- data/lib/jungle_path/migration.rb +3 -0
- data/lib/jungle_path/rack/json_body_parser.rb +2 -2
- data/lib/jungle_path/schema/auth.rb +32 -40
- data/lib/jungle_path/sql/key.rb +0 -22
- data/lib/jungle_path/sql/query_filter.rb +2 -2
- data/lib/jungle_path/sql/role.rb +2 -2
- data/lib/jungle_path/sql/user.rb +21 -2
- data/lib/jungle_path/time/time.rb +9 -0
- data/lib/jungle_path/time.rb +3 -0
- data/lib/jungle_path/version.rb +3 -0
- data/lib/jungle_path.rb +4 -0
- metadata +28 -6
- data/lib/jungle_path/gen/controller.rb +0 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
# controller.rb
|
2
|
+
require 'base64'
|
3
|
+
require 'jungle_path/controller'
|
4
|
+
require 'jungle_path/api/helpers'
|
5
|
+
require 'jungle_path/authentication/helpers'
|
6
|
+
require 'jungle_path/exceptions'
|
7
|
+
|
8
|
+
require_relative '../config/config'
|
9
|
+
require_relative '../schemas/schema'
|
10
|
+
require_relative 'generated'
|
11
|
+
|
12
|
+
module Controller
|
13
|
+
class User < JunglePath::Controller::Base
|
14
|
+
def initialize(current_user, current_key, params, db)
|
15
|
+
super(current_user, current_key, params, db, Schema::User)
|
16
|
+
end
|
17
|
+
|
18
|
+
def insert(include_secure_columns: false)
|
19
|
+
params = self.class.add_audit_parameter_values_for_insert(@params, @current_user, @current_key, @table_class)
|
20
|
+
model = @table_class.new params
|
21
|
+
#puts "params: #{params}."
|
22
|
+
#puts "model: #{model.to_h}."
|
23
|
+
|
24
|
+
#model.user_name = params[:email] unless model.user_name
|
25
|
+
model.user_name = model.email unless model.user_name
|
26
|
+
model.user_name = model.user_name.downcase if model.user_name
|
27
|
+
|
28
|
+
if params[:first_name] and params[:last_name]
|
29
|
+
model.name = "#{model.first_name} #{model.last_name}"
|
30
|
+
elsif params[:first_name]
|
31
|
+
model.name = model.first_name
|
32
|
+
elsif params[:last_name]
|
33
|
+
model.name = model.last_name
|
34
|
+
elsif params[:name]
|
35
|
+
name = params[:name].split(' ')
|
36
|
+
model.first_name = name[0]
|
37
|
+
model.last_name = name[1..-1].join(' ') if name.length > 1
|
38
|
+
end
|
39
|
+
|
40
|
+
#puts "model: #{model}."
|
41
|
+
|
42
|
+
model.sms_verification_code = validate_or_set_sms_verification_code(model.sms_verification_code)
|
43
|
+
model.activation_key = validate_or_set_activation_key(model.activation_key)
|
44
|
+
|
45
|
+
password = params[:password]
|
46
|
+
password = model.sms_verification_code unless password
|
47
|
+
|
48
|
+
message = self.class.validate_password_message(password)
|
49
|
+
if message
|
50
|
+
self.class.validate_insert(model, message)
|
51
|
+
raise Exceptions::InvalidPassword, "#{message}", caller
|
52
|
+
end
|
53
|
+
## todo: validate password strength, etc. here!
|
54
|
+
#model.hash = PasswordHash.createHash(password)
|
55
|
+
#model.key = KeyHelpers.generate_api_key unless model.key #create a new key_string unless one was passed in.
|
56
|
+
#model.key = model.key.downcase if model.key
|
57
|
+
|
58
|
+
self.class.validate_insert(model)
|
59
|
+
# result = handle_profile_image params
|
60
|
+
# model.profile_image_id = result.id if result
|
61
|
+
begin
|
62
|
+
result = @db.insert._model(model)
|
63
|
+
#puts "result: #{result}."
|
64
|
+
result = self.class.handle_include_secure_columns_flag(result, include_secure_columns, @table_class)
|
65
|
+
#default to role admin:
|
66
|
+
#params[:role_id] = 2 unless params[:role_id] # default to 'user' role.
|
67
|
+
#if params[:role_id]
|
68
|
+
# user_role = {role_id: params[:role_id], user_id: result.id}
|
69
|
+
# Controller::UserRole.new(@current_user, @current_key, user_role, @db).insert
|
70
|
+
#end
|
71
|
+
rescue Sequel::UniqueConstraintViolation => e
|
72
|
+
# already there? update instead...
|
73
|
+
puts "not unique!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
74
|
+
user_query = Schema::User.new({user_name: params[:user_name]})
|
75
|
+
user = @db.select._model_by_any(user_query)
|
76
|
+
puts "user: #{user}."
|
77
|
+
params[:id] = user.id if user
|
78
|
+
if user
|
79
|
+
update
|
80
|
+
user = @db.select._model(user)
|
81
|
+
else
|
82
|
+
raise
|
83
|
+
end
|
84
|
+
end
|
85
|
+
result
|
86
|
+
end
|
87
|
+
|
88
|
+
def update
|
89
|
+
params = self.class.add_audit_parameter_values_for_update(@params, @current_user, @current_key, @table_class)
|
90
|
+
model = @table_class.new params
|
91
|
+
puts "params: #{params}."
|
92
|
+
puts "model: #{model.to_h}."
|
93
|
+
puts "aaa model.id: #{model.id}, #{model.id.class}."
|
94
|
+
model.user_name = params[:email] unless model.user_name
|
95
|
+
model.user_name = model.user_name.downcase if model.user_name
|
96
|
+
model.sms_verification_code = validate_or_set_sms_verification_code(model.sms_verification_code)
|
97
|
+
model.activation_key = validate_or_set_activation_key(model.activation_key)
|
98
|
+
|
99
|
+
password = params[:password]
|
100
|
+
if password
|
101
|
+
message = self.class.validate_password_message(password)
|
102
|
+
if message
|
103
|
+
self.class.validate_update(model, message)
|
104
|
+
raise Exceptions::InvalidPassword, "#{message}", caller
|
105
|
+
end
|
106
|
+
# todo: validate password strength, etc. here!
|
107
|
+
model.hash = PasswordHash.createHash(password)
|
108
|
+
end
|
109
|
+
#model.key = KeyHelpers.generate_api_key unless model.key #create a new key_string unless one was passed in.
|
110
|
+
#model.key = model.key.downcase if model.key
|
111
|
+
|
112
|
+
self.class.validate_update(model)
|
113
|
+
# result = handle_profile_image params
|
114
|
+
# model.profile_image_id = result.id if result
|
115
|
+
result = @db.update._model(model)
|
116
|
+
if params[:role_id]
|
117
|
+
puts "model.class #{model.class}."
|
118
|
+
puts "model.id: #{model.id}, #{model.id.class}."
|
119
|
+
if model.id > 0 #don't delete root's role!!!
|
120
|
+
delete_user_roles model.id
|
121
|
+
end
|
122
|
+
#user_role = {role_id: params[:role_id], user_id: params[:id]}
|
123
|
+
#temp = Controller::UserRole.new(@current_user, @current_key, user_role, @db).insert
|
124
|
+
end
|
125
|
+
result
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.validate_hash_with_password(hash, password)
|
129
|
+
PasswordHash.validatePassword(password, hash)
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.strip_phone_leave_domain_if_any user_phone
|
133
|
+
phone = nil
|
134
|
+
if user_phone
|
135
|
+
parts = user_phone.split('@')
|
136
|
+
phone = parts[0].gsub(/[^0-9]/,'')
|
137
|
+
phone = phone[1..-1] if phone[0] == '1'
|
138
|
+
phone = "#{phone}@#{parts[1]}" if parts.length > 1
|
139
|
+
end
|
140
|
+
phone
|
141
|
+
end
|
142
|
+
|
143
|
+
def delete
|
144
|
+
model = @table_class.new @params
|
145
|
+
self.class.validate_delete(model)
|
146
|
+
delete_user_roles model.id
|
147
|
+
result = @db.delete._model(model)
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def delete_user_roles user_id
|
153
|
+
ds = @db.base['delete from user_role where user_id = ?', user_id]
|
154
|
+
result = ds.all
|
155
|
+
puts "deleted all user_roles for user_id #{user_id}: #{result}."
|
156
|
+
end
|
157
|
+
|
158
|
+
def handle_profile_image params
|
159
|
+
result = nil
|
160
|
+
if params[:image_name] and params[:image]
|
161
|
+
encoding = (params[:image_encoding] or 'base64')
|
162
|
+
hash = {image_file: params[:image_name], image_file_data: params[:image], image_file_data_encoding: encoding}
|
163
|
+
result = ::Controller::Image.new(@current_user, @current_key, hash, @db).insert
|
164
|
+
end
|
165
|
+
result
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.validate_password_message(password)
|
169
|
+
message = ''
|
170
|
+
pw_set = configatron.application.password_settings
|
171
|
+
# returns message if password is not a minimum strength...
|
172
|
+
message = "#{pw_set[:length][:message]}\n" unless password and password.length > pw_set[:length][:must_be_greater_than]
|
173
|
+
pw_set[:regular_expression_matches].each do |match|
|
174
|
+
message += "#{match[:message]}\n" if (match[:expression] =~ password) == nil
|
175
|
+
end
|
176
|
+
# message += "Password must have at least one alphabetical character.\n" if (/[[:alpha:]]/ =~ password) == nil
|
177
|
+
# message += "Password must have at least one numeric character." if (/[[:digit:]]/ =~ password) == nil
|
178
|
+
# message = "Password may not contain a '@' character." if password and password.include? '@'
|
179
|
+
if message == ''
|
180
|
+
nil
|
181
|
+
else
|
182
|
+
message
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def validate_or_set_sms_verification_code(sms_verification_code)
|
187
|
+
sms_verification_code = "000000#{(rand() * 1000000).to_i}"[-6, 6] unless sms_verification_code
|
188
|
+
sms_verification_code = "000000#{sms_verification_code}"[-6, 6] unless sms_verification_code.length == 6
|
189
|
+
sms_verification_code
|
190
|
+
end
|
191
|
+
|
192
|
+
def validate_or_set_activation_key(activation_key)
|
193
|
+
activation_key = KeyHelpers.generate_api_key('ak_') unless activation_key
|
194
|
+
activation_key
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#This file was generated using the ../lib/controller_template.erb. Do not modify directly.
|
2
|
+
require 'jungle_path/controller'
|
3
|
+
require_relative '../schemas/schema'
|
4
|
+
|
5
|
+
module Controller
|
6
|
+
|
7
|
+
class Answer < JunglePath::Controller::Base
|
8
|
+
def initialize(current_user, current_key, params, db)
|
9
|
+
super(current_user, current_key, params, db, Schema::Answer)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# (data) db.rb - db access layer...
|
2
|
+
require 'singleton'
|
3
|
+
require 'jungle_path/db_access'
|
4
|
+
require_relative '../config/config' # contains all settings (except sensitive data set to nil -- set sensitive data in override.rb.
|
5
|
+
|
6
|
+
module Server
|
7
|
+
class DB < JunglePath::DBAccess::IO::DB
|
8
|
+
include Singleton
|
9
|
+
def initialize
|
10
|
+
super jungle.db
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -19,3 +19,84 @@ class Answer < Schema::Base
|
|
19
19
|
[:audit_user]
|
20
20
|
)
|
21
21
|
end
|
22
|
+
|
23
|
+
class Practice < Schema::Base
|
24
|
+
self.description = ""
|
25
|
+
define(
|
26
|
+
[:id, :primary_key],
|
27
|
+
[:user_id, :foreign_key, :user],
|
28
|
+
[:notes, :string],
|
29
|
+
[:random_question_order, :boolean],
|
30
|
+
[:random_answer_order, :boolean],
|
31
|
+
[:audit_user]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
class PracticeQuiz < Schema::Base
|
36
|
+
self.description = ""
|
37
|
+
define(
|
38
|
+
[:practice_id, :foreign_key, :practice, :primary_key],
|
39
|
+
[:quiz_id, :foreign_key, :quiz, :primary_key],
|
40
|
+
[:audit_user]
|
41
|
+
)
|
42
|
+
def self.plural_table_name
|
43
|
+
"practice_quizzes"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class PracticeQuestion < Schema::Base
|
48
|
+
self.description = ""
|
49
|
+
define(
|
50
|
+
[:practice_id, :foreign_key, :practice, :primary_key],
|
51
|
+
[:question_id, :foreign_key, :question, :primary_key],
|
52
|
+
[:note, :string],
|
53
|
+
[:audit_user]
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
class PracticeAnswer < Schema::Base
|
58
|
+
self.description = ""
|
59
|
+
define(
|
60
|
+
[:practice_id, :foreign_key, :practice, :primary_key],
|
61
|
+
[:answer_id, :foreign_key, :answer, :primary_key],
|
62
|
+
[:label, :string],
|
63
|
+
[:selected, :boolean],
|
64
|
+
[:audit_user]
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
class Question < Schema::Base
|
69
|
+
self.description = ""
|
70
|
+
define(
|
71
|
+
[:id, :primary_key],
|
72
|
+
[:quiz_id, :foreign_key, :quiz],
|
73
|
+
[:name, :string],
|
74
|
+
[:description, :string],
|
75
|
+
[:audit_user]
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
class Quiz < Schema::Base
|
80
|
+
self.description = ""
|
81
|
+
define(
|
82
|
+
[:id, :primary_key],
|
83
|
+
[:name, :string],
|
84
|
+
[:description, :string],
|
85
|
+
[:private, :boolean, :default, true],
|
86
|
+
[:audit_user]
|
87
|
+
)
|
88
|
+
def self.plural_table_name
|
89
|
+
"quizzes"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Log < Schema::Base
|
94
|
+
define(
|
95
|
+
[:id, :primary_key],
|
96
|
+
[:set_id, :integer],
|
97
|
+
[:name, :string],
|
98
|
+
[:type, :string],
|
99
|
+
[:item, :string, :secure],
|
100
|
+
[:timestamp, :timestamp]
|
101
|
+
)
|
102
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'pony'
|
2
|
+
require_relative '../config/config'
|
3
|
+
require_relative '../controllers/controller'
|
4
|
+
|
5
|
+
module Services
|
6
|
+
module Email
|
7
|
+
def self.send_user_verification user
|
8
|
+
message = []
|
9
|
+
message << "<p>Please click the link below to verify your GIS sign-up.</p>"
|
10
|
+
message << "<p><a href='#{configatron.application.url}/activate/#{user.id}/activation_key/#{user.activation_key}?html=1'>#{configatron.application.url}/activate/#{user.id}/activation_key/#{user.activation_key}</a></p>"
|
11
|
+
message = message.join("\n")
|
12
|
+
|
13
|
+
user_email = user.email || user.user_name
|
14
|
+
|
15
|
+
Pony.mail({
|
16
|
+
to: "#{user_email}",
|
17
|
+
subject: "Subject: GIS Sign-up Verification",
|
18
|
+
html_body: message,
|
19
|
+
via: :smtp,
|
20
|
+
via_options: {
|
21
|
+
address: configatron.smtp.host,
|
22
|
+
port: configatron.smtp.port,
|
23
|
+
enable_starttls_auto: configatron.smtp.enable_tls,
|
24
|
+
user_name: configatron.smtp.user_name,
|
25
|
+
password: configatron.smtp.password,
|
26
|
+
authentication: :plain,
|
27
|
+
domain: configatron.smtp.domain_of_sender
|
28
|
+
}
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.send_user_password_reset_code user
|
33
|
+
message = []
|
34
|
+
message << "<p>Your password reset code:</p>"
|
35
|
+
message << "<p>#{user.password_reset_code}</p>"
|
36
|
+
message = message.join("\n")
|
37
|
+
|
38
|
+
user_email = user.email || user.user_name
|
39
|
+
|
40
|
+
Pony.mail({
|
41
|
+
to: "#{user_email}",
|
42
|
+
from: configatron.smtp.from,
|
43
|
+
subject: "Subject: GIS Password Reset Code",
|
44
|
+
html_body: message,
|
45
|
+
via: :smtp,
|
46
|
+
via_options: {
|
47
|
+
address: configatron.smtp.host,
|
48
|
+
port: configatron.smtp.port,
|
49
|
+
enable_starttls_auto: configatron.smtp.enable_tls,
|
50
|
+
user_name: configatron.smtp.user_name,
|
51
|
+
password: configatron.smtp.password,
|
52
|
+
authentication: configatron.smtp.authentication,
|
53
|
+
domain: configatron.smtp.domain_of_sender,
|
54
|
+
}
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.send_user_text_message_verification user
|
59
|
+
subject = "GIS Verification Code"
|
60
|
+
phone = Controller::User.strip_phone_leave_domain_if_any user.phone
|
61
|
+
puts "phone: #{phone}."
|
62
|
+
gateways = [
|
63
|
+
'@txt.att.net',
|
64
|
+
'@tmomail.net',
|
65
|
+
'@vtext.com',
|
66
|
+
'@messaging.sprintpcs.com',
|
67
|
+
|
68
|
+
'@mms.aiowireless.net',
|
69
|
+
'@sms.alltel.com',
|
70
|
+
'@paging.acswireless.com',
|
71
|
+
|
72
|
+
'@message.bam.com',
|
73
|
+
'@blsdcs.net',
|
74
|
+
'@blueskyfrog.com',
|
75
|
+
'@myboostmobile.com',
|
76
|
+
'@csouth1.com',
|
77
|
+
'@comcastpcs.textmsg.com',
|
78
|
+
'@sms.mycricket.com',
|
79
|
+
'@mobile.kajeet.net',
|
80
|
+
'@mymetropcs.com',
|
81
|
+
'@messaging.nextel.com',
|
82
|
+
'@ptel.net',
|
83
|
+
'@sms.pscel.com',
|
84
|
+
'@qwestmp.com',
|
85
|
+
'@page.southernlinc.com',
|
86
|
+
|
87
|
+
'@tms.suncom.com',
|
88
|
+
|
89
|
+
'@mmst5.tracfone.com',
|
90
|
+
'@msg.telus.com',
|
91
|
+
'@vmobl.com',
|
92
|
+
|
93
|
+
'@chat.wirefree.ca',
|
94
|
+
'@sms.beeline.ua',
|
95
|
+
'@txt.bell.ca'
|
96
|
+
]
|
97
|
+
if user.phone.include? '@'
|
98
|
+
Pony.mail({
|
99
|
+
to: phone,
|
100
|
+
subject: subject,
|
101
|
+
html_body: user.sms_verification_code,
|
102
|
+
via: :smtp,
|
103
|
+
via_options: {
|
104
|
+
address: configatron.smtp.host,
|
105
|
+
port: configatron.smtp.port,
|
106
|
+
enable_starttls_auto: true,
|
107
|
+
user_name: configatron.smtp.user_name,
|
108
|
+
password: configatron.smtp.password,
|
109
|
+
authentication: :plain,
|
110
|
+
domain: configatron.smtp.domain_of_sender
|
111
|
+
}
|
112
|
+
})
|
113
|
+
else
|
114
|
+
gateways.each do |gw|
|
115
|
+
begin
|
116
|
+
Pony.mail({
|
117
|
+
to: "#{phone}#{gw}",
|
118
|
+
subject: subject,
|
119
|
+
html_body: user.sms_verification_code,
|
120
|
+
via: :smtp,
|
121
|
+
via_options: {
|
122
|
+
address: configatron.smtp.host,
|
123
|
+
port: configatron.smtp.port,
|
124
|
+
enable_starttls_auto: true,
|
125
|
+
user_name: configatron.smtp.user_name,
|
126
|
+
password: configatron.smtp.password,
|
127
|
+
authentication: :plain,
|
128
|
+
domain: configatron.smtp.domain_of_sender
|
129
|
+
}
|
130
|
+
})
|
131
|
+
rescue Exception => ex
|
132
|
+
puts "exception sending text to #{user.phone}#{gw}: #{ex}."
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'twilio-ruby'
|
2
|
+
require_relative '../config/config'
|
3
|
+
|
4
|
+
module Services
|
5
|
+
module SMS
|
6
|
+
def self.send account_sid, auth_token, from_phone, to_phone, message
|
7
|
+
client = Twilio::REST::Client.new account_sid, auth_token
|
8
|
+
client.account.messages.create(
|
9
|
+
to: to_phone,
|
10
|
+
from: from_phone,
|
11
|
+
body: message
|
12
|
+
)
|
13
|
+
#rescue => e
|
14
|
+
# puts "SMS.send: #{e}!"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# prevent sequel migration error -- needed at least one file, empty ok as long as 000_... name matches schema version 0 in table.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# (who) zbootstrapdata.rb
|
2
|
+
require 'time'
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
require 'jungle_path/api/helpers'
|
6
|
+
require 'jungle_path/authentication/helpers'
|
7
|
+
require 'jungle_path/json'
|
8
|
+
|
9
|
+
require_relative '../db/db'
|
10
|
+
require_relative '../controllers/controller'
|
11
|
+
require_relative '../schemas/schema'
|
12
|
+
require_relative '../config/config' # contains all settings except sensitive data set to nil.
|
13
|
+
|
14
|
+
module ZBootstrap
|
15
|
+
def self.root_data db_config=nil, schema_initial_version=nil
|
16
|
+
db = JunglePath::DBAccess::IO::DB.new(db_config) if db_config
|
17
|
+
db = Server::DB.instance unless db
|
18
|
+
|
19
|
+
# set starting version numnber
|
20
|
+
if schema_initial_version
|
21
|
+
schema_info = Schema::SchemaInfo.new({version: schema_initial_version})
|
22
|
+
db.insert._model(schema_info)
|
23
|
+
end
|
24
|
+
|
25
|
+
hash = 'sha1:1000:/CloeFSPBOT7Ac/Jf/qQLk59iQbflhxf:H4eHZ0w51f3UdQpM+tp2DdhofDPkTf2P\n'
|
26
|
+
users = [
|
27
|
+
Schema::User.new({id: 0, name: 'root', user_name: 'root', role: 'root', hash: hash, email: nil, active: true, created_by_user_id: 0, updated_by_user_id: 0}),
|
28
|
+
Schema::User.new({id: 1, name: 'admin', user_name: 'admin', role: 'admin', hash: hash, email: nil, active: true, created_by_user_id: 0, updated_by_user_id: 0}),
|
29
|
+
Schema::User.new({id: 2, name: 'user', user_name: 'user', role: 'user', hash: hash, email: nil, active: true, created_by_user_id: 0, updated_by_user_id: 0})
|
30
|
+
]
|
31
|
+
users.each {|user| db.insert._model(user)}
|
32
|
+
|
33
|
+
#roles = [
|
34
|
+
# Schema::Role.new({id: 0, name: 'root', description: 'do anything', created_by_user_id: 0, updated_by_user_id: 0}),
|
35
|
+
# Schema::Role.new({id: 1, name: 'admin', description: 'general admin -- filtered by organization', created_by_user_id: 0, updated_by_user_id: 0}),
|
36
|
+
# Schema::Role.new({id: 2, name: 'user', description: 'basic user of system', created_by_user_id: 0, updated_by_user_id: 0})
|
37
|
+
#]
|
38
|
+
#roles.each {|role| db.insert._model(role)}
|
39
|
+
|
40
|
+
#user_roles = [
|
41
|
+
# Schema::UserRole.new({user_id: 0, role_id: 0, created_by_user_id: 0, updated_by_user_id: 0}),
|
42
|
+
# Schema::UserRole.new({user_id: 1, role_id: 1, created_by_user_id: 0, updated_by_user_id: 0}),
|
43
|
+
# Schema::UserRole.new({user_id: 2, role_id: 2, created_by_user_id: 0, updated_by_user_id: 0})
|
44
|
+
#]
|
45
|
+
#user_roles.each {|user_role| db.insert._model(user_role)}
|
46
|
+
|
47
|
+
fix_serial db
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.fix_serial db=nil
|
51
|
+
db = Server::API::DB.instance unless db
|
52
|
+
db.reset_sequence_for_table("user")
|
53
|
+
#db.reset_sequence_for_table("role")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
ZBootstrap.root_data if ARGV[0] == 'run'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'jungle_path/gen/db'
|
2
|
+
require 'jungle_path/gen/schema'
|
3
|
+
require_relative '../schemas/schema'
|
4
|
+
require_relative '../config/config' # contains all settings except sensitive data set to nil.
|
5
|
+
|
6
|
+
module ZCreateDb
|
7
|
+
def self.run db_config=nil
|
8
|
+
db_config = jungle.db unless db_config
|
9
|
+
puts "db_config port/name/user_name/password: #{db_config.port}/#{db_config.name}/#{db_config.user_name}/#{db_config.password}."
|
10
|
+
JunglePath::Gen::DB.reset!(db_config)
|
11
|
+
JunglePath::Gen::Schema.create(Schema::Base.models_dependent_order, db_config)
|
12
|
+
|
13
|
+
this_path = File.expand_path(File.dirname(__FILE__))
|
14
|
+
migrations_path = File.join(this_path, 'db', 'migrations')
|
15
|
+
JunglePath::Gen::Schema.set_version_to_latest(Schema::SchemaInfo, db_config, migrations_path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ZCreateDb.run if ARGV[0] == 'run'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# zgen.rb -- this project's generators:
|
2
|
+
require 'jungle_path/gen/api'
|
3
|
+
require 'jungle_path/gen/controllers'
|
4
|
+
|
5
|
+
require '../config/config.rb'
|
6
|
+
require '../schemas/schema'
|
7
|
+
|
8
|
+
JunglePath::Gen.controllers(configatron.application.root_dir, Schema::Base.models.values)
|
9
|
+
JunglePath::Gen.api(configatron.application.root_dir, Schema::Base.models.values)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#require 'pp'
|
2
|
+
require_relative 'jungle_path/gen/schema_tree'
|
3
|
+
require_relative '../config/config'
|
4
|
+
require_relative '../schemas/schema'
|
5
|
+
|
6
|
+
root = JunglePath::Gen::SchemaTree.gen_node_tree(Schema::Base.models)
|
7
|
+
|
8
|
+
## write node tree to schema_tree.txt file for use by query api test page.
|
9
|
+
#template_file = File.join(configatron.application.public_dir, 'query/documents/schema_tree_template.txt')
|
10
|
+
#template = File.read(template_file)
|
11
|
+
#template_output = "#{template}\n\n#{root.to_str}"
|
12
|
+
#output_file = File.join(configatron.application.public_dir, 'query/documents/schema_tree.txt')
|
13
|
+
#File.write(output_file, template_output)
|
14
|
+
puts root.to_str
|