simple_jwt_auth 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a3f123a56e05128ca367cc8fad36ea58bf60c8d81864a9634851b15ad709a49
4
- data.tar.gz: 18e011a83fa16813a670385aec58315e4aaa289e7c50be958aa91e1901cedee7
3
+ metadata.gz: 78d74d4d58750fc699e438212a1eb4d9f600c8aacebd23947e10b1ea5a8ab674
4
+ data.tar.gz: 4aa27eaeb5b1ead68fc77dd914ce12aee0ea75c180d7d9acd782f26b3e4839e7
5
5
  SHA512:
6
- metadata.gz: 9bb9d5ced0925f20982c702c5746cbd55cf7aa0160c822870833ce7915c938a8c93dd0db877a5f325f86635b24dbec5f43b09db147b5ecdf9336e975551eacb9
7
- data.tar.gz: 5625d08c5b78368655c644947027aee6a07728779d2bf49319fa76ff2d1dbf4488e3f23cd2108dd4fa4ed979decaa6653f550e4cb6d9ec1ba6d2f6c1a1a6d54e
6
+ metadata.gz: 9610ecf297ae4156e6945b42aa659ecd5bc3d4cdc2ef453bec925054404f1ed48a91db1ebe1683ce06cb236766b4f14e6311d1fc7dd28219ccfc74f8fb6a6e38
7
+ data.tar.gz: 1beffab4245f75424b2c77f37e3468ed8d34c406ec62555f6efc7ecd6a35076be90dcb33f7ab52ca40f73188b601dd189b8b424bdb8b706cc7bf3c3dfe45f339
data/README.md CHANGED
@@ -22,20 +22,15 @@ $ gem install simple_jwt_auth
22
22
  ### Models
23
23
  After installation run
24
24
  ```bash
25
- $ rails simple_jwt_auth:install:migrations
25
+ $ rails simple_jwt_auth:setup
26
26
  ```
27
- this will create a user model in your rails application.
27
+ this will create a user model in your rails application. As well as creating a file for adding associations and user model methods at app/models/user.rb
28
28
 
29
29
  then run
30
30
  ```bash
31
31
  $ rails db:migrate
32
32
  ```
33
- ### Routes
34
- in order to access gems provided routes add
35
- ```bash
36
- mount SimpleJwtAuth::Engine, at: "/auth"
37
- ```
38
- to the top of your routes in your rails project
33
+
39
34
  ### Creating Users
40
35
  Users can be created by making a POST request to
41
36
  https://localhost:3000/auth/users
@@ -1 +0,0 @@
1
- //= link_directory ../stylesheets/simple_jwt_auth .css
@@ -0,0 +1,26 @@
1
+ require_dependency "jwt"
2
+
3
+ class SessionsController < ApplicationController
4
+ def create
5
+ user = User.find_by(email: session_params[:email])
6
+ if user && user.authenticate(session_params[:password])
7
+ jwt = JWT.encode(
8
+ {
9
+ user_id: user.id, # the data to encode
10
+ exp: 24.hours.from_now.to_i # the expiration time
11
+ },
12
+ Rails.application.credentials.fetch(:secret_key_base), # the secret key
13
+ "HS256" # the encryption algorithm
14
+ )
15
+ render json: { jwt: jwt, email: user.email, user_id: user.id }, status: :created
16
+ else
17
+ render json: {}, status: :unauthorized
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def session_params
24
+ params.permit(:email, :password)
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ class UsersController < ApplicationController
2
+ def create
3
+ user = User.new(user_params)
4
+
5
+ if user.save
6
+ render json: {message: "User created successfully"}, status: :created
7
+ else
8
+ render json: {errors: user.errors.full_messages}, status: :bad_request
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def user_params
15
+ params.permit(:name, :email, :password, :password_confirmation)
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ module SessionsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class User < ApplicationRecord
2
+ has_secure_password
3
+ validates :email, presence: true, uniqueness: true
4
+ end
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
- SimpleJwtAuth::Engine.routes.draw do
2
- resources :users, only: [:create]
3
- resources :sessions, only: [:create]
1
+ Rails.application.routes.draw do
2
+ scope :auth do
3
+ resources :users, only: [:create]
4
+ resources :sessions, only: [:create]
5
+ end
4
6
  end
@@ -1,6 +1,6 @@
1
- class CreateSimpleJwtAuthUsers < ActiveRecord::Migration[6.0]
1
+ class CreateUsers < ActiveRecord::Migration[6.0]
2
2
  def change
3
- create_table :simple_jwt_auth_users do |t|
3
+ create_table :users do |t|
4
4
  t.string :name
5
5
  t.string :email
6
6
  t.string :password_digest
@@ -1,7 +1,6 @@
1
1
  module SimpleJwtAuth
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace SimpleJwtAuth
4
- initializer "actualize_auth.load_helpers" do |app|
3
+ initializer "simple_jwt_auth.load_helpers" do |app|
5
4
  ActionController::Base.send :include, SimpleJwtAuth::Engine.helpers
6
5
  end
7
6
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleJwtAuth
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -3,18 +3,15 @@ require_dependency "tty-file"
3
3
  desc "Copy migrations from simple_jwt_auth to application and create model/user.rb file in application"
4
4
  namespace :simple_jwt_auth do
5
5
  task :setup do
6
- Rake::Task["simple_jwt_auth:install:migrations"].invoke
7
- TTY::File.create_dir('app/models/simple_jwt_auth/')
8
- TTY::File.create_file "app/models/simple_jwt_auth/user.rb" do
6
+ Rake::Task["simple_jwt_auth_engine:install:migrations"].invoke
7
+ TTY::File.create_file "app/models/user.rb" do
9
8
  <<~CONFIG_MODELS
10
- require File.expand_path('../../app/models/simple_jwt_auth/user', SimpleJwtAuth::Engine.called_from)
9
+ require File.expand_path('../../app/models/user', SimpleJwtAuth::Engine.called_from)
11
10
 
12
- module SimpleJwtAuth
13
11
  class User
14
- #associations and user model methods here.
15
12
  end
16
- end
17
13
  CONFIG_MODELS
18
14
  end
19
15
  end
20
16
  end
17
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - brye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-24 00:00:00.000000000 Z
11
+ date: 2019-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -91,22 +91,16 @@ files:
91
91
  - README.md
92
92
  - Rakefile
93
93
  - app/assets/config/simple_jwt_auth_manifest.js
94
- - app/assets/stylesheets/simple_jwt_auth/application.css
95
- - app/assets/stylesheets/simple_jwt_auth/sessions.css
96
- - app/assets/stylesheets/simple_jwt_auth/users.css
97
- - app/controllers/simple_jwt_auth/application_controller.rb
98
- - app/controllers/simple_jwt_auth/sessions_controller.rb
99
- - app/controllers/simple_jwt_auth/users_controller.rb
94
+ - app/assets/stylesheets/sessions.css
95
+ - app/assets/stylesheets/users.css
96
+ - app/controllers/sessions_controller.rb
97
+ - app/controllers/users_controller.rb
98
+ - app/helpers/sessions_helper.rb
100
99
  - app/helpers/simple_jwt_auth/application_helper.rb
101
- - app/helpers/simple_jwt_auth/sessions_helper.rb
102
- - app/helpers/simple_jwt_auth/users_helper.rb
103
- - app/jobs/simple_jwt_auth/application_job.rb
104
- - app/mailers/simple_jwt_auth/application_mailer.rb
105
- - app/models/simple_jwt_auth/application_record.rb
106
- - app/models/simple_jwt_auth/user.rb
107
- - app/views/layouts/simple_jwt_auth/application.html.erb
100
+ - app/helpers/users_helper.rb
101
+ - app/models/user.rb
108
102
  - config/routes.rb
109
- - db/migrate/20191222061616_create_simple_jwt_auth_users.rb
103
+ - db/migrate/20191225083243_create_users.rb
110
104
  - lib/simple_jwt_auth.rb
111
105
  - lib/simple_jwt_auth/engine.rb
112
106
  - lib/simple_jwt_auth/version.rb
@@ -1,15 +0,0 @@
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
- */
@@ -1,5 +0,0 @@
1
- module SimpleJwtAuth
2
- class ApplicationController < ActionController::Base
3
- protect_from_forgery with: :null_session
4
- end
5
- end
@@ -1,29 +0,0 @@
1
- require_dependency "simple_jwt_auth/application_controller"
2
- require_dependency "jwt"
3
-
4
- module SimpleJwtAuth
5
- class SessionsController < ApplicationController
6
- def create
7
- user = User.find_by(email: session_params[:email])
8
- if user && user.authenticate(session_params[:password])
9
- jwt = JWT.encode(
10
- {
11
- user_id: user.id, # the data to encode
12
- exp: 24.hours.from_now.to_i # the expiration time
13
- },
14
- Rails.application.credentials.fetch(:secret_key_base), # the secret key
15
- "HS256" # the encryption algorithm
16
- )
17
- render json: { jwt: jwt, email: user.email, user_id: user.id }, status: :created
18
- else
19
- render json: {}, status: :unauthorized
20
- end
21
- end
22
-
23
- private
24
-
25
- def session_params
26
- params.permit(:email, :password)
27
- end
28
- end
29
- end
@@ -1,22 +0,0 @@
1
- require_dependency "simple_jwt_auth/application_controller"
2
-
3
- module SimpleJwtAuth
4
- class UsersController < ApplicationController
5
-
6
- def create
7
- user = User.new(user_params)
8
-
9
- if user.save
10
- render json: {message: "User created successfully"}, status: :created
11
- else
12
- render json: {errors: user.errors.full_messages}, status: :bad_request
13
- end
14
- end
15
-
16
- private
17
-
18
- def user_params
19
- params.permit(:name, :email, :password, :password_confirmation)
20
- end
21
- end
22
- end
@@ -1,4 +0,0 @@
1
- module SimpleJwtAuth
2
- module SessionsHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module SimpleJwtAuth
2
- module UsersHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module SimpleJwtAuth
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module SimpleJwtAuth
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- module SimpleJwtAuth
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- module SimpleJwtAuth
2
- class User < ApplicationRecord
3
- has_secure_password
4
- validates :email, presence: true, uniqueness: true
5
- end
6
- end
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Simple jwt auth</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "simple_jwt_auth/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
15
- </html>