usman 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/usman/api/v1/base_controller.rb +15 -0
- data/app/controllers/usman/api/v1/docs_base_controller.rb +25 -0
- data/app/controllers/usman/api/v1/docs_controller.rb +165 -0
- data/app/controllers/usman/api/v1/profile_controller.rb +60 -0
- data/app/controllers/usman/api/v1/registrations_controller.rb +159 -0
- data/app/controllers/usman/registration_devices_controller.rb +141 -0
- data/app/controllers/usman/registrations_controller.rb +68 -0
- data/app/helpers/usman/api_helper.rb +21 -36
- data/app/helpers/usman/authentication_helper.rb +1 -1
- data/app/models/device.rb +30 -3
- data/app/models/registration.rb +12 -3
- data/app/models/user.rb +54 -4
- data/app/services/usman/mobile_registration_service.rb +3 -5
- data/app/views/kuppayam/api/docs/_navigation.html.erb +43 -0
- data/app/views/usman/api/v1/docs/register/_neg_case_1.html.erb +46 -0
- data/app/views/usman/api/v1/docs/register/_neg_case_2.html.erb +39 -0
- data/app/views/usman/api/v1/docs/register/_neg_case_3.html.erb +47 -0
- data/app/views/usman/api/v1/docs/register/_pos_case_1.html.erb +65 -0
- data/app/views/usman/api/v1/docs/resend_otp/_neg_case_1.html.erb +30 -0
- data/app/views/usman/api/v1/docs/resend_otp/_pos_case_1.html.erb +31 -0
- data/app/views/usman/api/v1/docs/verify_otp/_neg_case_1.html.erb +34 -0
- data/app/views/usman/api/v1/docs/verify_otp/_neg_case_2.html.erb +39 -0
- data/app/views/usman/api/v1/docs/verify_otp/_neg_case_3.html.erb +33 -0
- data/app/views/usman/api/v1/docs/verify_otp/_pos_case_1.html.erb +35 -0
- data/app/views/usman/registration_devices/_form.html.erb +24 -0
- data/app/views/usman/registration_devices/_index.html.erb +80 -0
- data/app/views/usman/registration_devices/_row.html.erb +34 -0
- data/app/views/usman/registrations/_form.html.erb +23 -0
- data/app/views/usman/registrations/_index.html.erb +60 -0
- data/app/views/usman/registrations/_row.html.erb +24 -0
- data/app/views/usman/registrations/_show.html.erb +112 -0
- data/app/views/usman/registrations/index.html.erb +47 -0
- data/config/locales/usman/api.ar.yml +43 -0
- data/config/locales/usman/api.en.yml +43 -0
- data/config/locales/usman/authentication.ar.yml +14 -14
- data/config/locales/usman/authentication.en.yml +15 -18
- data/config/routes.rb +28 -9
- data/db/migrate/20170904080436_add_tac_accepted_at_to_devices.rb +5 -0
- data/db/migrate/20170905041104_add_gender_to_users.rb +6 -0
- data/lib/usman/version.rb +1 -1
- metadata +36 -15
- data/app/controllers/api/v1/base_controller.rb +0 -13
- data/app/controllers/api/v1/registrations_controller.rb +0 -115
- data/app/controllers/usman/docs_controller.rb +0 -41
- data/app/views/usman/docs/index.html.erb +0 -502
- data/app/views/usman/docs/register.html.erb +0 -0
- data/config/locales/usman/general.ar.yml +0 -5
- data/config/locales/usman/general.en.yml +0 -5
- data/config/locales/usman/mobile_registration.ar.yml +0 -26
- data/config/locales/usman/mobile_registration.en.yml +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be37dd5242c311e6541ccfb190c9aa54597526cb
|
4
|
+
data.tar.gz: 0d2bef201228c383b53ea972b213d416cf0851c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31ccc69fc7604ce950a96d97615ac345b6197cf1c8a1c45d6433762410c80d47ca8a2fdec01ea7682dbc0d435815948b5b3a57e4e442518f71f011857ec44e66
|
7
|
+
data.tar.gz: 77dbcef014783e75b470eab8a572f5f88c8c5c98ea185a8bd0c6e23609e0e2400edb3636fcb94e9cb2f028fb281a503bbe0b4e48808447c7acb0181a66412b32
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Usman
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class BaseController < ActionController::API
|
5
|
+
|
6
|
+
include ActionController::HttpAuthentication::Token::ControllerMethods
|
7
|
+
include RenderApiHelper
|
8
|
+
include Usman::ApiHelper
|
9
|
+
|
10
|
+
before_action :require_api_token
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Usman
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class DocsBaseController < Kuppayam::BaseController
|
5
|
+
|
6
|
+
include Usman::AuthenticationHelper
|
7
|
+
|
8
|
+
layout 'kuppayam/docs'
|
9
|
+
|
10
|
+
before_action :current_user
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def breadcrumbs_configuration
|
15
|
+
{
|
16
|
+
heading: "Usman - API Documentation",
|
17
|
+
description: "A brief documentation of all APIs implemented in the gem Usman with input and output details and examples",
|
18
|
+
links: []
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module Usman
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class DocsController < DocsBaseController
|
5
|
+
|
6
|
+
def register
|
7
|
+
set_title("Register API")
|
8
|
+
@request_type = "POST"
|
9
|
+
@end_point = "/api/v1/register"
|
10
|
+
@description = "This API will register the user and the devise and will send an OTP for verification"
|
11
|
+
|
12
|
+
@input_headers = {
|
13
|
+
"Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
|
14
|
+
}
|
15
|
+
|
16
|
+
@input_params = {
|
17
|
+
country_id: { mandatory: true, description: "Country ID is an integer. You may get it from Countries API", example: "100", default: "" },
|
18
|
+
city_id: { mandatory: false, description: "City ID is an integer. You may get it from Cities API", example: "1030", default: "" },
|
19
|
+
dialing_prefix: { mandatory: true, description: "International Dialing Prefix for countries", example: "+971", default: "" },
|
20
|
+
mobile_number: { mandatory: true, description: "Mobile Number without Dialing Prefix", example: "If your mobile number is +971 54 312 9876, pass '543129876' without spaces.", default: "" },
|
21
|
+
uuid: { mandatory: true, description: "Universal Unique Identifier. iOS or Android will give you this programatically.", example: "", default: "" },
|
22
|
+
device_token: { mandatory: true, description: "Device Token is a unique token for your device", example: "", default: "" },
|
23
|
+
device_name: { mandatory: false, description: "The name of your Device", example: "Apple iPhone", default: "" },
|
24
|
+
device_type: { mandatory: false, description: "", example: "The kind of device you have", default: "iPhone 7 plus" },
|
25
|
+
operating_system: { mandatory: false, description: "Operating System Name", example: "", default: "" },
|
26
|
+
software_version: { mandatory: false, description: "Software / OS Version", example: "", default: "" }
|
27
|
+
}
|
28
|
+
|
29
|
+
@example_path = "usman/api/v1/docs/"
|
30
|
+
@examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
|
31
|
+
|
32
|
+
set_nav("docs/register")
|
33
|
+
|
34
|
+
render 'kuppayam/api/docs/show'
|
35
|
+
end
|
36
|
+
|
37
|
+
def resend_otp
|
38
|
+
set_title("Resend OTP API")
|
39
|
+
@request_type = "POST"
|
40
|
+
@end_point = "/api/v1/resend_otp"
|
41
|
+
@description = "This API will resend the OTP for verification"
|
42
|
+
|
43
|
+
@warning = "A maximum of 3 attempt is allowed for resending the OTP. 6th request will block the device."
|
44
|
+
|
45
|
+
@input_headers = {
|
46
|
+
"Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
|
47
|
+
}
|
48
|
+
|
49
|
+
@input_params = {
|
50
|
+
uuid: { mandatory: true, description: "Universal Unique Identifier. iOS or Android will give you this programatically.", example: "", default: "" },
|
51
|
+
dialing_prefix: { mandatory: true, description: "International Dialing Prefix for countries", example: "+971", default: "" },
|
52
|
+
mobile_number: { mandatory: true, description: "Mobile Number without Dialing Prefix", example: "If your mobile number is +971 54 312 9876, pass '543129876' without spaces.", default: "" }
|
53
|
+
}
|
54
|
+
|
55
|
+
@example_path = "usman/api/v1/docs/"
|
56
|
+
@examples = ["pos_case_1", "neg_case_1"]
|
57
|
+
|
58
|
+
set_nav("docs/resend_otp")
|
59
|
+
|
60
|
+
render 'kuppayam/api/docs/show'
|
61
|
+
end
|
62
|
+
|
63
|
+
def verify_otp
|
64
|
+
set_title("Verify OTP API")
|
65
|
+
@request_type = "POST"
|
66
|
+
@end_point = "/api/v1/verify_otp"
|
67
|
+
@description = "This API verify the OTP and returns the API token for further communication"
|
68
|
+
|
69
|
+
@input_headers = {
|
70
|
+
"Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
|
71
|
+
}
|
72
|
+
|
73
|
+
@input_params = {
|
74
|
+
otp: { mandatory: true, description: "One Time Password you have received via SMS. (Five Digit)", example: "", default: "" },
|
75
|
+
uuid: { mandatory: true, description: "Universal Unique Identifier. iOS or Android will give you this programatically.", example: "", default: "" },
|
76
|
+
dialing_prefix: { mandatory: true, description: "International Dialing Prefix for countries", example: "+971", default: "" },
|
77
|
+
mobile_number: { mandatory: true, description: "Mobile Number without Dialing Prefix", example: "If your mobile number is +971 54 312 9876, pass '543129876' without spaces.", default: "" }
|
78
|
+
}
|
79
|
+
|
80
|
+
@example_path = "usman/api/v1/docs/"
|
81
|
+
@examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
|
82
|
+
|
83
|
+
set_nav("docs/verify_otp")
|
84
|
+
|
85
|
+
render 'kuppayam/api/docs/show'
|
86
|
+
end
|
87
|
+
|
88
|
+
def accept_tac
|
89
|
+
set_title("Accept T&C API")
|
90
|
+
@request_type = "POST"
|
91
|
+
@end_point = "/api/v1/accept_tac"
|
92
|
+
@description = "This API record the acceptance of the terms and condition."
|
93
|
+
|
94
|
+
@info = "The user will have to accept terms and conditions everytime he registers a new device"
|
95
|
+
|
96
|
+
@input_headers = {
|
97
|
+
"Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
|
98
|
+
}
|
99
|
+
|
100
|
+
@input_params = {
|
101
|
+
uuid: { mandatory: true, description: "Universal Unique Identifier. iOS or Android will give you this programatically.", example: "", default: "" },
|
102
|
+
dialing_prefix: { mandatory: true, description: "International Dialing Prefix for countries", example: "+971", default: "" },
|
103
|
+
mobile_number: { mandatory: true, description: "Mobile Number without Dialing Prefix", example: "If your mobile number is +971 54 312 9876, pass '543129876' without spaces.", default: "" }
|
104
|
+
}
|
105
|
+
|
106
|
+
@example_path = "usman/api/v1/docs/"#
|
107
|
+
# @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
|
108
|
+
|
109
|
+
set_nav("docs/accept_tac")
|
110
|
+
|
111
|
+
render 'kuppayam/api/docs/show'
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_profile
|
115
|
+
set_title("Create Profile API")
|
116
|
+
@request_type = "POST"
|
117
|
+
@end_point = "/api/v1/accept_tac"
|
118
|
+
@description = "This API will return so and so and create blah blah blah"
|
119
|
+
|
120
|
+
@input_headers = {
|
121
|
+
"Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
|
122
|
+
}
|
123
|
+
|
124
|
+
@input_params = {
|
125
|
+
uuid: { mandatory: true, description: "Universal Unique Identifier. iOS or Android will give you this programatically.", example: "", default: "" },
|
126
|
+
dialing_prefix: { mandatory: true, description: "International Dialing Prefix for countries", example: "+971", default: "" },
|
127
|
+
mobile_number: { mandatory: true, description: "Mobile Number without Dialing Prefix", example: "If your mobile number is +971 54 312 9876, pass '543129876' without spaces.", default: "" }
|
128
|
+
}
|
129
|
+
|
130
|
+
@example_path = "usman/api/v1/docs/"#
|
131
|
+
# @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
|
132
|
+
|
133
|
+
set_nav("docs/create_profile")
|
134
|
+
|
135
|
+
render 'kuppayam/api/docs/show'
|
136
|
+
end
|
137
|
+
|
138
|
+
def update_profile
|
139
|
+
set_title("Update Profile API")
|
140
|
+
@request_type = "POST"
|
141
|
+
@end_point = "/api/v1/accept_tac"
|
142
|
+
@description = "This API will return so and so and create blah blah blah"
|
143
|
+
|
144
|
+
@input_headers = {
|
145
|
+
"Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " }
|
146
|
+
}
|
147
|
+
|
148
|
+
@input_params = {
|
149
|
+
uuid: { mandatory: true, description: "Universal Unique Identifier. iOS or Android will give you this programatically.", example: "", default: "" },
|
150
|
+
dialing_prefix: { mandatory: true, description: "International Dialing Prefix for countries", example: "+971", default: "" },
|
151
|
+
mobile_number: { mandatory: true, description: "Mobile Number without Dialing Prefix", example: "If your mobile number is +971 54 312 9876, pass '543129876' without spaces.", default: "" }
|
152
|
+
}
|
153
|
+
|
154
|
+
@example_path = "usman/api/v1/docs/"#
|
155
|
+
# @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
|
156
|
+
|
157
|
+
set_nav("docs/update_profile")
|
158
|
+
|
159
|
+
render 'kuppayam/api/docs/show'
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Usman
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ProfileController < Usman::Api::V1::BaseController
|
5
|
+
|
6
|
+
def create_profile
|
7
|
+
proc_code = Proc.new do
|
8
|
+
|
9
|
+
if @current_registration
|
10
|
+
if @current_user
|
11
|
+
@success = false
|
12
|
+
@errors = {
|
13
|
+
heading: I18n.translate("api.profile.user_already_exists.heading"),
|
14
|
+
message: I18n.translate("api.profile.user_already_exists.message")
|
15
|
+
}
|
16
|
+
else
|
17
|
+
@user = User.new
|
18
|
+
@user.name = permitted_params[:name]
|
19
|
+
@user.generate_username_and_password
|
20
|
+
@user.gender = permitted_params[:gender]
|
21
|
+
@user.date_of_birth = permitted_params[:date_of_birth]
|
22
|
+
@user.email = permitted_params[:email]
|
23
|
+
if @user.valid?
|
24
|
+
@current_registration.user = @user
|
25
|
+
@success = true
|
26
|
+
@alert = {
|
27
|
+
heading: I18n.translate("api.profile.profile_created.heading"),
|
28
|
+
message: I18n.translate("api.profile.profile_created.message")
|
29
|
+
}
|
30
|
+
@data = {
|
31
|
+
registration: @reg_data.registration,
|
32
|
+
device: @reg_data.device
|
33
|
+
}
|
34
|
+
else
|
35
|
+
@errors = @user.errors
|
36
|
+
@success = false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
@success = false
|
41
|
+
@errors = {
|
42
|
+
heading: I18n.translate("api.profile.registration_details_missing.heading"),
|
43
|
+
message: I18n.translate("api.profile.registration_details_missing.message")
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
render_json_response(proc_code)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def permitted_params
|
53
|
+
params.require(:profile).permit(:name, :gender, :date_of_birth, :email, :country_id, :city_id)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module Usman
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class RegistrationsController < Usman::Api::V1::BaseController
|
5
|
+
|
6
|
+
skip_before_action :require_api_token
|
7
|
+
|
8
|
+
def register
|
9
|
+
proc_code = Proc.new do
|
10
|
+
@reg_data = Usman::MobileRegistrationService.new(params)
|
11
|
+
@errors = @reg_data.errors
|
12
|
+
@success = false
|
13
|
+
if @errors[:heading].blank?
|
14
|
+
@success = true
|
15
|
+
@alert = {
|
16
|
+
heading: I18n.translate("api.mobile_registration.otp_sent.heading"),
|
17
|
+
message: I18n.translate("api.mobile_registration.otp_sent.message")
|
18
|
+
}
|
19
|
+
@data = {
|
20
|
+
registration: @reg_data.registration,
|
21
|
+
device: @reg_data.device
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
render_json_response(proc_code)
|
26
|
+
end
|
27
|
+
|
28
|
+
def resend_otp
|
29
|
+
proc_code = Proc.new do
|
30
|
+
@device = Device.where("uuid = ?", params[:uuid]).first
|
31
|
+
if @device
|
32
|
+
if @device.blocked?
|
33
|
+
@success = false
|
34
|
+
@errors = {
|
35
|
+
heading: I18n.translate("api.mobile_registration.device_blocked.heading"),
|
36
|
+
message: I18n.translate("api.mobile_registration.device_blocked.message"),
|
37
|
+
details: {}
|
38
|
+
}
|
39
|
+
else
|
40
|
+
valid, validation_errors = @device.resend_otp(params[:dialing_prefix], params[:mobile_number])
|
41
|
+
if valid
|
42
|
+
@success = true
|
43
|
+
@alert = {
|
44
|
+
heading: I18n.translate("api.mobile_registration.new_otp_sent.heading"),
|
45
|
+
message: I18n.translate("api.mobile_registration.new_otp_sent.message")
|
46
|
+
}
|
47
|
+
@data = {}
|
48
|
+
else
|
49
|
+
@success = false
|
50
|
+
@errors = {
|
51
|
+
heading: I18n.translate("api.mobile_registration.otp_not_matching.heading"),
|
52
|
+
message: I18n.translate("api.mobile_registration.otp_not_matching.message"),
|
53
|
+
details: validation_errors
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
@success = false
|
59
|
+
@errors = {
|
60
|
+
heading: I18n.translate("api.general.unexpected_failure.heading"),
|
61
|
+
message: I18n.translate("api.general.unexpected_failure.message"),
|
62
|
+
details: {
|
63
|
+
uuid: "is invalid"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
render_json_response(proc_code)
|
69
|
+
end
|
70
|
+
|
71
|
+
def verify
|
72
|
+
proc_code = Proc.new do
|
73
|
+
@device = Device.where("uuid = ?", params[:uuid]).first
|
74
|
+
if @device
|
75
|
+
if @device.blocked?
|
76
|
+
@success = false
|
77
|
+
@errors = {
|
78
|
+
heading: I18n.translate("api.mobile_registration.device_blocked.heading"),
|
79
|
+
message: I18n.translate("api.mobile_registration.device_blocked.message"),
|
80
|
+
details: {}
|
81
|
+
}
|
82
|
+
else
|
83
|
+
valid, validation_errors = @device.validate_otp(params[:otp], params[:dialing_prefix], params[:mobile_number])
|
84
|
+
if valid
|
85
|
+
@success = true
|
86
|
+
@alert = {
|
87
|
+
heading: I18n.translate("api.mobile_registration.verification_success.heading"),
|
88
|
+
message: I18n.translate("api.mobile_registration.verification_success.message")
|
89
|
+
}
|
90
|
+
else
|
91
|
+
@success = false
|
92
|
+
@errors = {
|
93
|
+
heading: I18n.translate("api.mobile_registration.otp_not_matching.heading"),
|
94
|
+
message: I18n.translate("api.mobile_registration.otp_not_matching.message"),
|
95
|
+
details: validation_errors
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
else
|
100
|
+
@success = false
|
101
|
+
@errors = {
|
102
|
+
heading: I18n.translate("api.general.unexpected_failure.heading"),
|
103
|
+
message: I18n.translate("api.general.unexpected_failure.message"),
|
104
|
+
details: {
|
105
|
+
uuid: "is invalid"
|
106
|
+
}
|
107
|
+
}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
render_json_response(proc_code)
|
111
|
+
end
|
112
|
+
|
113
|
+
def accept_tac
|
114
|
+
proc_code = Proc.new do
|
115
|
+
@device = Device.where("uuid = ?", params[:uuid]).first
|
116
|
+
if @device
|
117
|
+
if @device.blocked?
|
118
|
+
@success = false
|
119
|
+
@errors = {
|
120
|
+
heading: I18n.translate("api.mobile_registration.device_blocked.heading"),
|
121
|
+
message: I18n.translate("api.mobile_registration.device_blocked.message"),
|
122
|
+
details: {}
|
123
|
+
}
|
124
|
+
else
|
125
|
+
valid, validation_errors = @device.accept_tac(params[:terms_and_conditions], params[:dialing_prefix], params[:mobile_number])
|
126
|
+
if valid
|
127
|
+
@success = true
|
128
|
+
@alert = {
|
129
|
+
heading: I18n.translate("api.mobile_registration.tac_accepted.heading"),
|
130
|
+
message: I18n.translate("api.mobile_registration.tac_accepted.message")
|
131
|
+
}
|
132
|
+
@data = { api_token: @device.api_token }
|
133
|
+
else
|
134
|
+
@success = false
|
135
|
+
@errors = {
|
136
|
+
heading: I18n.translate("api.mobile_registration.tac_not_accepted.heading"),
|
137
|
+
message: I18n.translate("api.mobile_registration.tac_not_accepted.message"),
|
138
|
+
details: validation_errors
|
139
|
+
}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
else
|
143
|
+
@success = false
|
144
|
+
@errors = {
|
145
|
+
heading: I18n.translate("api.general.unexpected_failure.heading"),
|
146
|
+
message: I18n.translate("api.general.unexpected_failure.message"),
|
147
|
+
details: {
|
148
|
+
uuid: "is invalid"
|
149
|
+
}
|
150
|
+
}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
render_json_response(proc_code)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module Usman
|
2
|
+
class RegistrationDevicesController < ResourceController
|
3
|
+
|
4
|
+
before_action :require_site_admin
|
5
|
+
before_action :get_registration
|
6
|
+
|
7
|
+
def index
|
8
|
+
get_collections
|
9
|
+
respond_to do |format|
|
10
|
+
format.html {}
|
11
|
+
format.js {
|
12
|
+
js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/index" : :index
|
13
|
+
render js_view_path
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def show
|
19
|
+
@device = @r_object = @resource_options[:class].find_by_id(params[:id])
|
20
|
+
set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object
|
21
|
+
render_accordingly
|
22
|
+
end
|
23
|
+
|
24
|
+
def new
|
25
|
+
@device = Device.new
|
26
|
+
render_accordingly
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
@device = @r_object = Device.find_by_id(permitted_params[:id])
|
31
|
+
if @device.add_registration(@registration)
|
32
|
+
set_notification(true, I18n.t('status.success'), "Registration '#{@registration.name}' has been assigned to the device '#{@device.name}'")
|
33
|
+
else
|
34
|
+
set_notification(false, I18n.t('status.success'), "Failed to assign the Registration '#{@registration.name}'")
|
35
|
+
end
|
36
|
+
action_name = params[:action].to_s == "create" ? "new" : "edit"
|
37
|
+
render_or_redirect(false, resource_url(@r_object), action_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
@device = @r_object = Device.find_by_id(params[:id])
|
42
|
+
if @device
|
43
|
+
if @device.remove_registration(@registration)
|
44
|
+
get_collections
|
45
|
+
set_flash_message(I18n.t('success.deleted'), :success)
|
46
|
+
set_notification(true, I18n.t('status.success'), "Registration '#{@registration.name}' has been removed for the device '#{@device.name}'")
|
47
|
+
@destroyed = true
|
48
|
+
else
|
49
|
+
message = I18n.t('errors.failed_to_delete', item: default_item_name.titleize)
|
50
|
+
set_flash_message(message, :failure)
|
51
|
+
set_notification(false, I18n.t('status.success'), "Failed to remove the Registration '#{@registration.name}'")
|
52
|
+
@destroyed = false
|
53
|
+
end
|
54
|
+
else
|
55
|
+
set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize))
|
56
|
+
end
|
57
|
+
|
58
|
+
respond_to do |format|
|
59
|
+
format.html {}
|
60
|
+
format.js {
|
61
|
+
js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/destroy" : :destroy
|
62
|
+
render js_view_path
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def get_registration
|
71
|
+
@registration = Registration.find_by_id(params[:registration_id])
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_collections
|
75
|
+
@relation = @registration.devices.where("")
|
76
|
+
|
77
|
+
parse_filters
|
78
|
+
apply_filters
|
79
|
+
|
80
|
+
@devices = @r_objects = @relation.page(@current_page).per(@per_page)
|
81
|
+
|
82
|
+
return true
|
83
|
+
end
|
84
|
+
|
85
|
+
def apply_filters
|
86
|
+
@relation = @relation.search(@query) if @query
|
87
|
+
|
88
|
+
@order_by = "devices.created_at DESC" unless @order_by
|
89
|
+
@relation = @relation.order(@order_by)
|
90
|
+
end
|
91
|
+
|
92
|
+
def configure_filter_settings
|
93
|
+
@filter_settings = {
|
94
|
+
string_filters: [
|
95
|
+
{ filter_name: :query }
|
96
|
+
],
|
97
|
+
boolean_filters: [],
|
98
|
+
reference_filters: [],
|
99
|
+
variable_filters: [],
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def configure_filter_ui_settings
|
104
|
+
@filter_ui_settings = {}
|
105
|
+
end
|
106
|
+
|
107
|
+
def resource_url(obj)
|
108
|
+
url_for([@registration, obj])
|
109
|
+
end
|
110
|
+
|
111
|
+
def resource_controller_configuration
|
112
|
+
{
|
113
|
+
collection_name: :devices,
|
114
|
+
item_name: :device,
|
115
|
+
class: Device,
|
116
|
+
show_modal_after_create: false,
|
117
|
+
show_modal_after_update: false,
|
118
|
+
page_title: "Manage Device Registrations",
|
119
|
+
js_view_path: "/kuppayam/workflows/parrot",
|
120
|
+
view_path: "/usman/registration_devices"
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def breadcrumbs_configuration
|
125
|
+
{
|
126
|
+
heading: "Manage Device Registrations",
|
127
|
+
description: "Listing all Device Registrations",
|
128
|
+
links: [{name: "Home", link: dashboard_path, icon: 'fa-home'}]
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
def permitted_params
|
133
|
+
params.require(:device).permit(:id)
|
134
|
+
end
|
135
|
+
|
136
|
+
def set_navs
|
137
|
+
set_nav("admin/registrations")
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Usman
|
2
|
+
class RegistrationsController < ResourceController
|
3
|
+
|
4
|
+
before_action :require_site_admin
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def get_collections
|
9
|
+
@relation = Registration.where("")
|
10
|
+
|
11
|
+
parse_filters
|
12
|
+
apply_filters
|
13
|
+
|
14
|
+
@registrations = @r_objects = @relation.page(@current_page).per(@per_page)
|
15
|
+
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
|
19
|
+
def apply_filters
|
20
|
+
@relation = @relation.search(@query) if @query
|
21
|
+
|
22
|
+
@order_by = "created_at DESC" unless @order_by
|
23
|
+
@relation = @relation.order(@order_by)
|
24
|
+
end
|
25
|
+
|
26
|
+
def configure_filter_settings
|
27
|
+
@filter_settings = {
|
28
|
+
string_filters: [
|
29
|
+
{ filter_name: :query }
|
30
|
+
],
|
31
|
+
boolean_filters: [],
|
32
|
+
reference_filters: [],
|
33
|
+
variable_filters: [],
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def configure_filter_ui_settings
|
38
|
+
@filter_ui_settings = {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def resource_controller_configuration
|
42
|
+
{
|
43
|
+
page_title: "Registrations",
|
44
|
+
js_view_path: "/kuppayam/workflows/peacock",
|
45
|
+
view_path: "/usman/registrations"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def breadcrumbs_configuration
|
50
|
+
{
|
51
|
+
heading: "Manage Registrations",
|
52
|
+
icon: "fa-lock",
|
53
|
+
description: "Listing all Registrations",
|
54
|
+
links: [{name: "Home", link: dashboard_path, icon: 'fa-home'},
|
55
|
+
{name: "Manage Registrations", link: registrations_path, icon: 'fa-calendar', active: true}]
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def permitted_params
|
60
|
+
params.require(:registration).permit(:mobile_number, :dialing_prefix, :country_id, :city_id)
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_navs
|
64
|
+
set_nav("admin/registrations")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|