sis_core 1.0.3 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/sis/core/application_controller.rb +10 -2
- data/app/controllers/sis/core/menus_controller.rb +22 -0
- data/app/controllers/sis/core/users_controller.rb +71 -0
- data/app/models/sis/core/academic_programme.rb +17 -0
- data/app/models/sis/core/academic_year.rb +1 -0
- data/app/models/sis/core/applicant.rb +18 -1
- data/app/models/sis/core/application.rb +50 -0
- data/app/models/sis/core/application_document.rb +12 -0
- data/app/models/sis/core/application_module.rb +8 -0
- data/app/models/sis/core/application_setup.rb +23 -0
- data/app/models/sis/core/document_requirement.rb +13 -0
- data/app/models/sis/core/{program_type.rb → document_type.rb} +1 -1
- data/app/models/sis/core/exam.rb +17 -0
- data/app/models/sis/core/exam_result.rb +25 -0
- data/app/models/sis/core/exam_setup.rb +15 -0
- data/app/models/sis/core/menu.rb +11 -0
- data/app/models/sis/core/programme.rb +7 -0
- data/app/models/sis/core/programme_level.rb +6 -0
- data/app/models/sis/core/programme_type.rb +6 -0
- data/app/models/sis/core/semester.rb +4 -0
- data/app/models/sis/core/user.rb +13 -0
- data/app/models/sis/core/user_role.rb +10 -0
- data/app/services/sis/core/user_service.rb +25 -0
- data/app/uploaders/sis/core/application_document_uploader.rb +51 -0
- data/app/uploaders/sis/core/photo_uploader.rb +51 -0
- data/config/routes.rb +6 -0
- data/db/migrate/{20200307072142_create_sis_core_academic_years.rb → 20200105072142_create_sis_core_academic_years.rb} +2 -1
- data/db/migrate/{20200307072246_create_sis_core_semesters.rb → 20200106072246_create_sis_core_semesters.rb} +0 -0
- data/db/migrate/20200106130428_create_sis_core_programmes.rb +10 -0
- data/db/migrate/20200106132035_create_sis_core_academic_programmes.rb +21 -0
- data/db/migrate/20200106132521_create_sis_core_application_setups.rb +19 -0
- data/db/migrate/20200106133034_create_sis_core_document_requirements.rb +19 -0
- data/db/migrate/20200106133937_create_sis_core_applicants.rb +14 -2
- data/db/migrate/20200107094449_create_sis_core_applications.rb +24 -0
- data/db/migrate/20200107101638_create_sis_core_application_documents.rb +16 -0
- data/db/migrate/20200107302251_create_sis_core_exam_setups.rb +15 -0
- data/db/migrate/20200107333411_create_sis_core_exams.rb +17 -0
- data/db/migrate/20200107434658_create_sis_core_exam_results.rb +18 -0
- data/db/migrate/20200307033100_create_sis_core_courses.rb +2 -2
- data/db/migrate/20200307072006_create_sis_core_students.rb +2 -2
- data/db/migrate/20200507114003_create_sis_core_users.rb +17 -0
- data/db/migrate/20200511165121_create_sis_core_application_modules.rb +15 -0
- data/db/migrate/20200511165241_create_sis_core_user_roles.rb +15 -0
- data/db/migrate/20200511165450_create_sis_core_menus.rb +18 -0
- data/lib/authorize_request.rb +18 -0
- data/lib/json_web_token.rb +12 -0
- data/lib/sis/core/engine.rb +2 -2
- data/lib/sis/core/version.rb +1 -1
- data/lib/sis_core.rb +5 -0
- data/spec/factories/sis/core/academic_programmes.rb +8 -0
- data/spec/factories/sis/core/academic_years.rb +3 -2
- data/spec/factories/sis/core/applicants.rb +9 -2
- data/spec/factories/sis/core/application_documents.rb +7 -0
- data/spec/factories/sis/core/application_modules.rb +6 -0
- data/spec/factories/sis/core/application_setups.rb +9 -0
- data/spec/factories/sis/core/applications.rb +11 -0
- data/spec/factories/sis/core/document_requirements.rb +9 -0
- data/spec/factories/sis/core/document_types.rb +5 -0
- data/spec/factories/sis/core/exam_results.rb +8 -0
- data/spec/factories/sis/core/exam_setups.rb +8 -0
- data/spec/factories/sis/core/exams.rb +10 -0
- data/spec/factories/sis/core/instructor_courses.rb +2 -2
- data/spec/factories/sis/core/instructors.rb +2 -2
- data/spec/factories/sis/core/menus.rb +9 -0
- data/spec/factories/sis/core/programme_levels.rb +5 -0
- data/spec/factories/sis/core/programme_types.rb +5 -0
- data/spec/factories/sis/core/programmes.rb +6 -0
- data/spec/factories/sis/core/semesters.rb +1 -1
- data/spec/factories/sis/core/students.rb +5 -5
- data/spec/factories/sis/core/user_roles.rb +6 -0
- data/spec/factories/sis/core/users.rb +9 -0
- metadata +150 -29
- data/app/models/sis/core/attached_document.rb +0 -8
- data/app/models/sis/core/enrollment_application.rb +0 -9
- data/app/models/sis/core/program.rb +0 -9
- data/app/models/sis/core/staff.rb +0 -21
- data/app/models/user.rb +0 -12
- data/config/initializers/devise_token_auth.rb +0 -55
- data/db/migrate/20200106001016_create_sis_core_field_of_studies.rb +0 -9
- data/db/migrate/20200106130428_create_sis_core_programs.rb +0 -10
- data/db/migrate/20200108092202_devise_token_auth_create_users.rb +0 -53
- data/db/migrate/20200108094449_create_sis_core_enrollment_applications.rb +0 -10
- data/db/migrate/20200108101638_create_sis_core_attached_documents.rb +0 -11
- data/db/migrate/20200316120805_create_sis_core_staffs.rb +0 -31
- data/db/migrate/20200319074334_modify_user.rb +0 -16
- data/spec/factories/sis/core/attached_documents.rb +0 -7
- data/spec/factories/sis/core/enrollment_applications.rb +0 -7
- data/spec/factories/sis/core/field_of_studies.rb +0 -6
- data/spec/factories/sis/core/program_types.rb +0 -5
- data/spec/factories/sis/core/programs.rb +0 -7
- data/spec/factories/sis/core/staffs.rb +0 -32
- data/spec/factories/users.rb +0 -11
@@ -0,0 +1,51 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class ApplicationDocumentUploader < CarrierWave::Uploader::Base
|
4
|
+
# Include RMagick or MiniMagick support:
|
5
|
+
# include CarrierWave::RMagick
|
6
|
+
# include CarrierWave::MiniMagick
|
7
|
+
|
8
|
+
# Choose what kind of storage to use for this uploader:
|
9
|
+
storage :file
|
10
|
+
# storage :fog
|
11
|
+
|
12
|
+
# Override the directory where uploaded files will be stored.
|
13
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
14
|
+
def store_dir
|
15
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
19
|
+
# def default_url(*args)
|
20
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
21
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
22
|
+
#
|
23
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Process files as they are uploaded:
|
27
|
+
# process scale: [200, 300]
|
28
|
+
#
|
29
|
+
# def scale(width, height)
|
30
|
+
# # do something
|
31
|
+
# end
|
32
|
+
|
33
|
+
# Create different versions of your uploaded files:
|
34
|
+
# version :thumb do
|
35
|
+
# process resize_to_fit: [50, 50]
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
39
|
+
# For images you might use something like this:
|
40
|
+
def extension_whitelist
|
41
|
+
%w[pdf]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Override the filename of the uploaded files:
|
45
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
46
|
+
# def filename
|
47
|
+
# "something.jpg" if original_filename
|
48
|
+
# end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class PhotoUploader < CarrierWave::Uploader::Base
|
4
|
+
# Include RMagick or MiniMagick support:
|
5
|
+
# include CarrierWave::RMagick
|
6
|
+
# include CarrierWave::MiniMagick
|
7
|
+
|
8
|
+
# Choose what kind of storage to use for this uploader:
|
9
|
+
storage :file
|
10
|
+
# storage :fog
|
11
|
+
|
12
|
+
# Override the directory where uploaded files will be stored.
|
13
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
14
|
+
def store_dir
|
15
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
19
|
+
# def default_url(*args)
|
20
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
21
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
22
|
+
#
|
23
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Process files as they are uploaded:
|
27
|
+
# process scale: [200, 300]
|
28
|
+
#
|
29
|
+
# def scale(width, height)
|
30
|
+
# # do something
|
31
|
+
# end
|
32
|
+
|
33
|
+
# Create different versions of your uploaded files:
|
34
|
+
# version :thumb do
|
35
|
+
# process resize_to_fit: [50, 50]
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
39
|
+
# For images you might use something like this:
|
40
|
+
def extension_whitelist
|
41
|
+
%w[jpg jpeg gif png]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Override the filename of the uploaded files:
|
45
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
46
|
+
# def filename
|
47
|
+
# "something.jpg" if original_filename
|
48
|
+
# end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,8 @@
|
|
1
1
|
Sis::Core::Engine.routes.draw do
|
2
|
+
resources :users, only: [:create]
|
3
|
+
post '/login', controller: :users, action: :login
|
4
|
+
get '/menus', controller: :menus, action: :menu
|
5
|
+
post '/sign_in', controller: :users, action: :sign_in
|
6
|
+
post '/generate_recovery_token', controller: :users, action: :generate_recovery_token
|
7
|
+
post '/reset_password', controller: :users, action: :reset_password
|
2
8
|
end
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreateSisCoreAcademicProgrammes < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_academic_programmes do |t|
|
4
|
+
t.integer :duration, null: false
|
5
|
+
t.references :programme,
|
6
|
+
null: false,
|
7
|
+
index: { name: 'ap_on_programme_indx' },
|
8
|
+
foreign_key: { to_table: :sis_core_programmes }
|
9
|
+
t.references :programme_type,
|
10
|
+
null: false,
|
11
|
+
index: { name: 'ap_on_pt_indx' },
|
12
|
+
foreign_key: { to_table: :sis_core_lookups }
|
13
|
+
t.references :programme_level,
|
14
|
+
null: false,
|
15
|
+
index: { name: 'ap_on_pl_indx' },
|
16
|
+
foreign_key: { to_table: :sis_core_lookups }
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateSisCoreApplicationSetups < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_application_setups do |t|
|
4
|
+
t.date :start_date, null: false
|
5
|
+
t.date :end_date, null: false
|
6
|
+
t.string :status, null: false, default: 'Open'
|
7
|
+
t.references :academic_programme,
|
8
|
+
null: false,
|
9
|
+
index: { name: 'as_on_ap_indx' },
|
10
|
+
foreign_key: { to_table: :sis_core_academic_programmes }
|
11
|
+
t.references :target_semester,
|
12
|
+
null: false,
|
13
|
+
index: { name: 'as_on_ts_indx' },
|
14
|
+
foreign_key: { to_table: :sis_core_semesters }
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateSisCoreDocumentRequirements < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_document_requirements do |t|
|
4
|
+
t.integer :original, null: false, default: 0
|
5
|
+
t.integer :copy, null: false, default: 0
|
6
|
+
t.string :remark
|
7
|
+
t.references :document_type,
|
8
|
+
null: false,
|
9
|
+
index: { name: 'adr_on_dc_indx' },
|
10
|
+
foreign_key: { to_table: :sis_core_lookups }
|
11
|
+
t.references :application_setup,
|
12
|
+
null: false,
|
13
|
+
index: { name: 'adr_on_as_indx' },
|
14
|
+
foreign_key: { to_table: :sis_core_application_setups }
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,8 +4,20 @@ class CreateSisCoreApplicants < ActiveRecord::Migration[6.0]
|
|
4
4
|
t.string :first_name, null: false
|
5
5
|
t.string :middle_name, null: false
|
6
6
|
t.string :last_name, null: false
|
7
|
-
t.string :
|
8
|
-
t.string :
|
7
|
+
t.string :password_digest, null: false
|
8
|
+
t.string :email, null: false
|
9
|
+
t.string :alternative_email_address
|
10
|
+
t.string :primary_phone_number
|
11
|
+
t.string :alternative_telephone_number
|
12
|
+
t.date :date_of_birth
|
13
|
+
t.string :gender
|
14
|
+
t.string :nationality
|
15
|
+
t.string :address
|
16
|
+
t.string :photo
|
17
|
+
t.string :reset_password_token
|
18
|
+
t.datetime :reset_password_sent_at
|
19
|
+
t.string :secret_question
|
20
|
+
t.string :secret_question_answer
|
9
21
|
|
10
22
|
t.timestamps
|
11
23
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateSisCoreApplications < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_applications do |t|
|
4
|
+
t.string :status, null: false, default: 'Draft'
|
5
|
+
t.boolean :payment_made, null: false, default: false
|
6
|
+
t.string :payment_information
|
7
|
+
t.date :application_date
|
8
|
+
t.references :applicant,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'applications_on_applicant_indx' },
|
11
|
+
foreign_key: { to_table: :sis_core_applicants }
|
12
|
+
t.references :academic_programme,
|
13
|
+
null: false,
|
14
|
+
index: { name: 'applications_on_ap_indx' },
|
15
|
+
foreign_key: { to_table: :sis_core_academic_programmes }
|
16
|
+
t.references :application_setup,
|
17
|
+
null: false,
|
18
|
+
index: { name: 'application_setup_on_ap_indx' },
|
19
|
+
foreign_key: { to_table: :sis_core_application_setups }
|
20
|
+
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateSisCoreApplicationDocuments < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_application_documents do |t|
|
4
|
+
t.string :document
|
5
|
+
t.references :document_requirement,
|
6
|
+
null: false,
|
7
|
+
index: { name: 'ad_on_adr_indx' },
|
8
|
+
foreign_key: { to_table: :sis_core_document_requirements }
|
9
|
+
t.references :application,
|
10
|
+
null: false,
|
11
|
+
index: { name: 'ad_on_application_indx' },
|
12
|
+
foreign_key: { to_table: :sis_core_applications }
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateSisCoreExamSetups < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_exam_setups do |t|
|
4
|
+
t.date :date, null: false
|
5
|
+
t.float :hours, null: false
|
6
|
+
t.string :venue, null: false
|
7
|
+
t.references :application_setup,
|
8
|
+
null: false,
|
9
|
+
index: { name: 'es_on_as_indx' },
|
10
|
+
foreign_key: { to_table: :sis_core_application_setups }
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSisCoreExams < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_exams do |t|
|
4
|
+
t.string :title, null: false
|
5
|
+
t.datetime :start, null: false
|
6
|
+
t.datetime :finish, null: false
|
7
|
+
t.float :points, null: false
|
8
|
+
t.float :pass_point, null: false
|
9
|
+
t.references :exam_setup,
|
10
|
+
null: false,
|
11
|
+
index: { name: 'exams_on_es_indx' },
|
12
|
+
foreign_key: { to_table: :sis_core_exam_setups }
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateSisCoreExamResults < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_exam_results do |t|
|
4
|
+
t.float :points, null: false
|
5
|
+
t.string :status, null: false
|
6
|
+
t.references :exam,
|
7
|
+
null: false,
|
8
|
+
index: { name: 'er_on_exam_indx' },
|
9
|
+
foreign_key: { to_table: :sis_core_exams }
|
10
|
+
t.references :application,
|
11
|
+
null: false,
|
12
|
+
index: { name: 'er_on_application_indx' },
|
13
|
+
foreign_key: { to_table: :sis_core_applications }
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -8,10 +8,10 @@ class CreateSisCoreCourses < ActiveRecord::Migration[6.0]
|
|
8
8
|
t.float :ects, null: false
|
9
9
|
t.float :lecture_hours, null: false
|
10
10
|
t.float :lab_hours, null: false
|
11
|
-
t.references :
|
11
|
+
t.references :academic_programme,
|
12
12
|
index: { name: 'program_on_courses_indx' },
|
13
13
|
null: false,
|
14
|
-
foreign_key: { to_table: :
|
14
|
+
foreign_key: { to_table: :sis_core_academic_programmes }
|
15
15
|
|
16
16
|
t.timestamps
|
17
17
|
end
|
@@ -5,10 +5,10 @@ class CreateSisCoreStudents < ActiveRecord::Migration[6.0]
|
|
5
5
|
t.string :full_name, null: false
|
6
6
|
t.date :date_of_birth, null: false
|
7
7
|
t.string :nationality, null: false
|
8
|
-
t.references :
|
8
|
+
t.references :academic_programme,
|
9
9
|
index: { name: 'program_on_student_indx' },
|
10
10
|
null: false,
|
11
|
-
foreign_key: { to_table: :
|
11
|
+
foreign_key: { to_table: :sis_core_academic_programmes }
|
12
12
|
|
13
13
|
t.timestamps
|
14
14
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSisCoreUsers < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_users do |t|
|
4
|
+
t.string :first_name, null: false
|
5
|
+
t.string :last_name, null: false
|
6
|
+
t.string :email, null: false
|
7
|
+
t.boolean :active, default: true
|
8
|
+
t.string :password_digest, null: false
|
9
|
+
t.string :reset_password_token
|
10
|
+
t.datetime :reset_password_sent_at
|
11
|
+
t.string :secret_question
|
12
|
+
t.string :secret_question_answer
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateSisCoreApplicationModules < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_application_modules do |t|
|
4
|
+
t.string :code, null: false
|
5
|
+
t.string :name, null: false
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table :sis_core_application_modules_users, id: false do |t|
|
11
|
+
t.belongs_to :application_module, index: { name: 'app_module_on_app_modules_usr_indx' }
|
12
|
+
t.belongs_to :user, index: { name: 'usr_on_app_modules_usr_indx' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateSisCoreUserRoles < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_user_roles do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.references :application_module, index: { name: 'app_module_on_usr_role_indx' }
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table :sis_core_user_roles_users, id: false do |t|
|
11
|
+
t.belongs_to :user, index: { name: 'usr_on_usr_role_usrs_indx' }
|
12
|
+
t.belongs_to :user_role, index: { name: 'usr_role_on_usr_role_usrs_indx' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateSisCoreMenus < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :sis_core_menus do |t|
|
4
|
+
t.string :text, null: false
|
5
|
+
t.string :icon_cls
|
6
|
+
t.string :location
|
7
|
+
t.integer :parent_id
|
8
|
+
t.references :application_module, index: { name: 'app_module_on_menus_indx' }
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :sis_core_menus_user_roles, id: false do |t|
|
14
|
+
t.belongs_to :menu, index: { name: 'menu_on_menus_usr_role_indx' }
|
15
|
+
t.belongs_to :user_role, index: { name: 'usr_role_on_menus_usr_role_indx' }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class AuthorizeRequest
|
2
|
+
class << self
|
3
|
+
def user(headers)
|
4
|
+
@user ||= User.find(decoded_auth_token(headers)[:id]) if decoded_auth_token(headers)
|
5
|
+
@user || nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def decoded_auth_token(headers)
|
9
|
+
@decoded_auth_token ||= JsonWebToken.decode(http_auth_header(headers)) if http_auth_header(headers)
|
10
|
+
end
|
11
|
+
|
12
|
+
def http_auth_header(headers)
|
13
|
+
return headers['Authorization'].split(' ').last if headers['Authorization'].present?
|
14
|
+
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class JsonWebToken
|
2
|
+
class << self
|
3
|
+
def encode(payload)
|
4
|
+
JWT.encode(payload, Rails.application.secrets.secret_key_base)
|
5
|
+
end
|
6
|
+
|
7
|
+
def decode(token)
|
8
|
+
body = JWT.decode(token, Rails.application.secrets.secret_key_base)[0]
|
9
|
+
HashWithIndifferentAccess.new body
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|