ctws 0.1.5.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +295 -0
  4. data/Rakefile +21 -0
  5. data/app/auth/ctws/authenticate_user.rb +36 -0
  6. data/app/auth/ctws/authorize_api_request.rb +44 -0
  7. data/app/controllers/concerns/ctws/exception_handler.rb +58 -0
  8. data/app/controllers/concerns/ctws/response.rb +25 -0
  9. data/app/controllers/concerns/ctws/v1/exception_handler.rb +6 -0
  10. data/app/controllers/concerns/ctws/v1/response.rb +6 -0
  11. data/app/controllers/ctws/application_controller.rb +5 -0
  12. data/app/controllers/ctws/authentication_controller.rb +28 -0
  13. data/app/controllers/ctws/ctws_controller.rb +24 -0
  14. data/app/controllers/ctws/min_app_versions_controller.rb +55 -0
  15. data/app/controllers/ctws/users_controller.rb +39 -0
  16. data/app/controllers/ctws/v1/authentication_controller.rb +6 -0
  17. data/app/controllers/ctws/v1/ctws_controller.rb +9 -0
  18. data/app/controllers/ctws/v1/min_app_versions_controller.rb +6 -0
  19. data/app/controllers/ctws/v1/users_controller.rb +6 -0
  20. data/app/controllers/ctws/v2/ctws_controller.rb +9 -0
  21. data/app/controllers/ctws/v2/min_app_versions_controller.rb +6 -0
  22. data/app/jobs/ctws/application_job.rb +4 -0
  23. data/app/lib/ctws/json_web_token.rb +25 -0
  24. data/app/lib/ctws/message.rb +43 -0
  25. data/app/mailers/ctws/application_mailer.rb +6 -0
  26. data/app/models/ctws/application_record.rb +5 -0
  27. data/app/models/ctws/min_app_version.rb +22 -0
  28. data/config/initializers/ctws.rb +5 -0
  29. data/config/initializers/mime_types.rb +1 -0
  30. data/config/routes.rb +18 -0
  31. data/db/migrate/20170425110839_create_ctws_min_app_versions.rb +13 -0
  32. data/db/migrate/20170425110933_add_values_to_ctws_min_app_versions.rb +26 -0
  33. data/lib/ctws/engine.rb +13 -0
  34. data/lib/ctws/version.rb +3 -0
  35. data/lib/ctws.rb +18 -0
  36. data/lib/tasks/ctws_tasks.rake +4 -0
  37. data/spec/auth/ctws/authenticate_user_spec.rb +34 -0
  38. data/spec/auth/ctws/authorize_api_request_spec.rb +62 -0
  39. data/spec/controllers/ctws/ctws_controller_spec.rb +41 -0
  40. data/spec/controllers/ctws/users_controller_spec.rb +7 -0
  41. data/spec/dummy/Rakefile +6 -0
  42. data/spec/dummy/app/assets/config/manifest.js +5 -0
  43. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  44. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  45. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  46. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  47. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  49. data/spec/dummy/app/controllers/user_controller.rb +18 -0
  50. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  51. data/spec/dummy/app/helpers/user_helper.rb +2 -0
  52. data/spec/dummy/app/jobs/application_job.rb +2 -0
  53. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  54. data/spec/dummy/app/models/application_record.rb +3 -0
  55. data/spec/dummy/app/models/user.rb +4 -0
  56. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  57. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  58. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  59. data/spec/dummy/bin/bundle +3 -0
  60. data/spec/dummy/bin/rails +4 -0
  61. data/spec/dummy/bin/rake +4 -0
  62. data/spec/dummy/bin/setup +34 -0
  63. data/spec/dummy/bin/update +29 -0
  64. data/spec/dummy/config/application.rb +15 -0
  65. data/spec/dummy/config/boot.rb +5 -0
  66. data/spec/dummy/config/cable.yml +9 -0
  67. data/spec/dummy/config/database.yml +25 -0
  68. data/spec/dummy/config/environment.rb +5 -0
  69. data/spec/dummy/config/environments/development.rb +54 -0
  70. data/spec/dummy/config/environments/production.rb +86 -0
  71. data/spec/dummy/config/environments/test.rb +42 -0
  72. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  73. data/spec/dummy/config/initializers/assets.rb +11 -0
  74. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  76. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  77. data/spec/dummy/config/initializers/inflections.rb +16 -0
  78. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  79. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  80. data/spec/dummy/config/initializers/session_store.rb +3 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  82. data/spec/dummy/config/locales/en.yml +23 -0
  83. data/spec/dummy/config/puma.rb +47 -0
  84. data/spec/dummy/config/routes.rb +5 -0
  85. data/spec/dummy/config/secrets.yml +22 -0
  86. data/spec/dummy/config/spring.rb +6 -0
  87. data/spec/dummy/config.ru +5 -0
  88. data/spec/dummy/db/development.sqlite3 +0 -0
  89. data/spec/dummy/db/migrate/20170622072636_create_users.rb +10 -0
  90. data/spec/dummy/db/schema.rb +39 -0
  91. data/spec/dummy/db/test.sqlite3 +0 -0
  92. data/spec/dummy/log/development.log +29 -0
  93. data/spec/dummy/log/test.log +31496 -0
  94. data/spec/dummy/public/404.html +67 -0
  95. data/spec/dummy/public/422.html +67 -0
  96. data/spec/dummy/public/500.html +66 -0
  97. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  98. data/spec/dummy/public/apple-touch-icon.png +0 -0
  99. data/spec/dummy/public/favicon.ico +0 -0
  100. data/spec/factories/ctws/ctws_user.rb +7 -0
  101. data/spec/factories/ctws_min_app_version.rb +9 -0
  102. data/spec/models/ctws/min_app_version_spec.rb +11 -0
  103. data/spec/models/ctws/user_spec.rb +8 -0
  104. data/spec/rails_helper.rb +88 -0
  105. data/spec/requests/ctws/authentication_spec.rb +47 -0
  106. data/spec/requests/ctws/min_app_version_spec.rb +169 -0
  107. data/spec/requests/ctws/users_spec.rb +46 -0
  108. data/spec/spec_helper.rb +27 -0
  109. data/spec/support/ctws/controller_spec_helper.rb +29 -0
  110. data/spec/support/ctws/request_spec_helper.rb +10 -0
  111. metadata +367 -0
@@ -0,0 +1,9 @@
1
+ require_dependency "ctws/application_controller"
2
+
3
+ module Ctws
4
+ module V1
5
+ class CtwsController < Ctws::CtwsController
6
+ # Generic API stuff here
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Ctws
2
+ module V1
3
+ class MinAppVersionsController < Ctws::MinAppVersionsController
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Ctws
2
+ module V1
3
+ class UsersController < Ctws::UsersController
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require_dependency "ctws/application_controller"
2
+
3
+ module Ctws
4
+ module V2
5
+ class CtwsController < ApplicationController
6
+ # Generic API stuff here
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Ctws
2
+ module V2
3
+ class MinAppVersionsController < Ctws::MinAppVersionsController
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Ctws
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ module Ctws
2
+ class JsonWebToken
3
+ require 'jwt'
4
+
5
+ # secret to encode and decode token
6
+ HMAC_SECRET = Rails.application.secrets.secret_key_base
7
+
8
+ def self.encode(payload, exp = Ctws.jwt_expiration_time)
9
+ # set expiry to 24 hours from creation time
10
+ payload[:exp] = exp.to_i
11
+ # sign token with application secret
12
+ JWT.encode(payload, HMAC_SECRET)
13
+ end
14
+
15
+ def self.decode(token)
16
+ # get payload; first index in decoded Array
17
+ body = JWT.decode(token, HMAC_SECRET)[0]
18
+ HashWithIndifferentAccess.new body
19
+ # rescue from expiry exception
20
+ rescue JWT::ExpiredSignature, JWT::VerificationError => e
21
+ # raise custom error to be handled by custom handler
22
+ raise Ctws::ExceptionHandler::ExpiredSignature, e.message
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ module Ctws
2
+ class Message
3
+ def self.not_found(record = 'record')
4
+ "Sorry, #{record} not found."
5
+ end
6
+
7
+ def self.unmatched_route(route = 'route')
8
+ "No route matches #{route}"
9
+ end
10
+
11
+ def self.invalid_credentials
12
+ 'Invalid credentials'
13
+ end
14
+
15
+ def self.invalid_token
16
+ 'Invalid token'
17
+ end
18
+
19
+ def self.missing_token
20
+ 'Missing token'
21
+ end
22
+
23
+ def self.unauthorized
24
+ 'Unauthorized request'
25
+ end
26
+
27
+ def self.account_created
28
+ 'Account created successfully'
29
+ end
30
+
31
+ def self.account_not_created
32
+ 'Account could not be created'
33
+ end
34
+
35
+ def self.authenticated_user_success
36
+ 'Authenticated user successfully'
37
+ end
38
+
39
+ def self.expired_token
40
+ 'Sorry, your token has expired. Please login to continue.'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,6 @@
1
+ module Ctws
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Ctws
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ module Ctws
2
+ class MinAppVersion < ApplicationRecord
3
+ validates_presence_of :codename, :description, :platform, :min_version, :store_uri
4
+
5
+ def as_jsonapi(options={})
6
+ {
7
+ type: ActiveModel::Naming.param_key(self),
8
+ id: self.id,
9
+ attributes: {
10
+ codename: self.codename,
11
+ description: self.description,
12
+ min_version: self.min_version,
13
+ platform: self.platform,
14
+ store_uri: self.store_uri,
15
+ updated_at: self.updated_at
16
+ }
17
+ }
18
+ end
19
+ end
20
+
21
+
22
+ end
@@ -0,0 +1,5 @@
1
+ Ctws.user_class = "User"
2
+ Ctws.user_class_strong_params = %i(email password password_confirmation)
3
+ Ctws.user_validate_with_password = true
4
+ Ctws.jwt_expiration_time = 24.hours.from_now
5
+ Ctws.jwt_auth_token_attrs = %i(id email) # TODO: implement
@@ -0,0 +1 @@
1
+ Mime::Type.register "application/vnd.api+json", :json
data/config/routes.rb ADDED
@@ -0,0 +1,18 @@
1
+ Ctws::Engine.routes.draw do
2
+ namespace :v1 do
3
+ resources :min_app_versions
4
+ get 'min_app_version', to: 'min_app_versions#min_app_version'
5
+ post 'signup', to: 'users#create'
6
+ post 'login', to: 'authentication#authenticate'
7
+ end
8
+ namespace :v2 do
9
+ # resources :min_app_versions
10
+ get 'min_app_version', to: 'min_app_versions#min_app_version'
11
+ end
12
+
13
+ get '*unmatched_route', to: 'ctws#raise_not_found!'
14
+
15
+ # match '/', :to => 'base#raise_not_found!', via: :all
16
+ # match '*other', :to => 'base#raise_not_found!', via: :all
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCtwsMinAppVersions < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :ctws_min_app_versions do |t|
4
+ t.string :codename
5
+ t.text :description
6
+ t.string :platform
7
+ t.string :min_version
8
+ t.string :store_uri
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ class AddValuesToCtwsMinAppVersions < ActiveRecord::Migration[5.0]
2
+ def up
3
+ min_app_version_ios = Ctws::MinAppVersion.create!({
4
+ codename: "First Release",
5
+ description: "You need to update your app. You will be redirected to the corresponding store",
6
+ platform: "ios",
7
+ min_version: "0.0.1",
8
+ store_uri: "https://itunes.apple.com/"
9
+ })
10
+
11
+ min_app_version_android = Ctws::MinAppVersion.create!({
12
+ codename: "First Release",
13
+ description: "You need to update your app. You will be redirected to the corresponding store",
14
+ platform: "android",
15
+ min_version: "0.0.1",
16
+ store_uri: "https://play.google.com"
17
+ })
18
+ end
19
+
20
+ def down
21
+ min_app_version_ios = Ctws::MinAppVersion.find_by_min_version( "0.0.1" )
22
+ min_app_version_ios.destroy
23
+ min_app_version_android = Ctws::MinAppVersion.find_by_min_version( "0.0.1" )
24
+ min_app_version_android.destroy
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Ctws
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Ctws
4
+ config.generators.api_only = true
5
+
6
+ config.generators do |g|
7
+ g.test_framework :rspec, :fixture => false
8
+ g.fixture_replacement :factory_girl_rails, :dir => 'spec/factories'
9
+ g.assets false
10
+ g.helper false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Ctws
2
+ VERSION = '0.1.5.alpha'
3
+ end
data/lib/ctws.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "ctws/engine"
2
+
3
+ module Ctws
4
+ mattr_accessor :user_class
5
+ mattr_accessor :user_class_strong_params
6
+ mattr_accessor :user_validate_with_password
7
+ mattr_accessor :jwt_expiration_time
8
+ mattr_accessor :jwt_auth_token_attrs
9
+
10
+ def self.user_class
11
+ @@user_class.constantize
12
+ end
13
+
14
+ def self.jwt_auth_token_attrs
15
+ # TODO: implement
16
+ @@jwt_auth_token_attrs
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ctws do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,34 @@
1
+ require 'rails_helper'
2
+
3
+ module Ctws
4
+ RSpec.describe AuthenticateUser, class: 'Ctws::AuthenticateUser' do
5
+ # create test user
6
+ let(:ctws_user) { create(:ctws_user) }
7
+ # valid request subject
8
+ subject(:valid_auth_obj) { described_class.new(ctws_user.email, ctws_user.password) }
9
+ # invalid request subject
10
+ subject(:invalid_auth_obj) { described_class.new('foo', 'bar') }
11
+
12
+ # Test suite for AuthenticateUser#call
13
+ describe '#call' do
14
+ # return token when valid request
15
+ context 'when valid credentials' do
16
+ it 'returns an auth token' do
17
+ token = valid_auth_obj.call
18
+ expect(token).not_to be_nil
19
+ end
20
+ end
21
+
22
+ # raise Authentication Error when invalid request
23
+ context 'when invalid credentials' do
24
+ it 'raises an authentication error' do
25
+ expect { invalid_auth_obj.call }
26
+ .to raise_error(
27
+ Ctws::ExceptionHandler::AuthenticationError,
28
+ /Invalid credentials/
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ require 'rails_helper'
2
+
3
+ module Ctws
4
+ RSpec.describe AuthorizeApiRequest, class: 'Ctws::AuthorizeApiRequest' do
5
+ # Create test user
6
+ let(:ctws_user) { create(:ctws_user) }
7
+
8
+ # Mock `Authorization` header
9
+ let(:header) { { 'Authorization' => token_generator(ctws_user.id) } }
10
+ # Invalid request subject
11
+ subject(:invalid_request_obj) { described_class.new({}) }
12
+ # Valid request subject
13
+ subject(:request_obj) { described_class.new(header) }
14
+
15
+ # Test Suite for AuthorizeApiRequest#call
16
+ # This is our entry point into the service class
17
+ describe '#call' do
18
+ # returns user object when request is valid
19
+ context 'when valid request' do
20
+ it 'returns user object' do
21
+ result = request_obj.call
22
+ expect(result[:user]).to eq(ctws_user)
23
+ end
24
+ end
25
+
26
+ # returns error message when invalid request
27
+ context 'when invalid request' do
28
+ context 'when missing token' do
29
+ it 'raises a MissingToken error' do
30
+ expect { invalid_request_obj.call }
31
+ .to raise_error(Ctws::ExceptionHandler::MissingToken, 'Missing token')
32
+ end
33
+ end
34
+
35
+ context 'when invalid token' do
36
+ subject(:invalid_request_obj) do
37
+ # custom helper method `token_generator`
38
+ described_class.new('Authorization' => token_generator(5))
39
+ end
40
+
41
+ it 'raises an InvalidToken error' do
42
+ expect { invalid_request_obj.call }
43
+ .to raise_error(Ctws::ExceptionHandler::InvalidToken, /Invalid token/)
44
+ end
45
+ end
46
+
47
+ context 'when token is expired' do
48
+ let(:header) { { 'Authorization' => expired_token_generator(ctws_user.id) } }
49
+ subject(:request_obj) { described_class.new(header) }
50
+
51
+ it 'raises ExceptionHandler::ExpiredSignature error' do
52
+ expect { request_obj.call }
53
+ .to raise_error(
54
+ Ctws::ExceptionHandler::ExpiredSignature,
55
+ /Signature has expired/
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails_helper'
2
+
3
+ module Ctws
4
+ RSpec.describe CtwsController, type: :controller do
5
+ # create test ctws_user
6
+ let!(:ctws_user) { create(:ctws_user) }
7
+ # set headers for authorization
8
+ let(:headers) { { 'Authorization' => token_generator(ctws_user.id) } }
9
+ let(:invalid_headers) { { 'Authorization' => nil } }
10
+
11
+ describe "authorize_request" do
12
+ context "when auth token is passed" do
13
+ before { allow(request).to receive(:headers).and_return(headers) }
14
+
15
+ # private method authorize_request returns current ctws_user
16
+ it "sets the current ctws_user" do
17
+ expect(subject.instance_eval { authorize_request }).to eq(ctws_user)
18
+ end
19
+ end
20
+
21
+ context "when auth token is not passed" do
22
+ before do
23
+ allow(request).to receive(:headers).and_return(invalid_headers)
24
+ end
25
+
26
+ it "raises MissingToken error" do
27
+ expect { subject.instance_eval { authorize_request } }.
28
+ to raise_error(Ctws::ExceptionHandler::MissingToken, /Missing token/)
29
+ end
30
+ end
31
+ end
32
+ describe "routes" do
33
+ context "when route is not found" do
34
+ xit "returns 404" do
35
+ to raise_error(Ctws::ExceptionHandler::RoutingError, /No route matches/)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ module Ctws
4
+ RSpec.describe UsersController, type: :controller do
5
+
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
5
+ //= link ctws_manifest.js
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,18 @@
1
+ class UserController < ApplicationController
2
+ =begin
3
+ def create
4
+ # We use Active Record's create! method so that in the event there's an error,
5
+ # an exception will be raised and handled in the exception handler.
6
+ ctws_user = Ctws.user_class.create!(ctws_user_params)
7
+ auth_token = Ctws::AuthenticateUser.new(ctws_user.email, ctws_user.password).call
8
+ response = { message: Ctws::Message.account_created, auth_token: auth_token }
9
+ json_response(response, :created)
10
+ end
11
+
12
+ private
13
+
14
+ def ctws_user_params
15
+ params.permit(:email, :password, :password_confirmation)
16
+ end
17
+ =end
18
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UserHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,4 @@
1
+ class User < ApplicationRecord
2
+ has_secure_password
3
+ validates_presence_of :email, :password_digest
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # puts "\n== Copying sample files =="
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
24
+ # end
25
+
26
+ puts "\n== Preparing database =="
27
+ system! 'bin/rails db:setup'
28
+
29
+ puts "\n== Removing old logs and tempfiles =="
30
+ system! 'bin/rails log:clear tmp:clear'
31
+
32
+ puts "\n== Restarting application server =="
33
+ system! 'bin/rails restart'
34
+ end