revise_auth-jets 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/config/routes.rb +7 -0
- data/app/controllers/api/base_controller.rb +42 -0
- data/app/controllers/api/v1/mes_controller.rb +11 -0
- data/app/controllers/revise_auth/registrations_controller.rb +1 -0
- data/app/controllers/revise_auth/sessions_controller.rb +1 -0
- data/app/stylesheet/theme.scss +1563 -0
- data/app/views/revise_auth/registrations/edit.html.erb +43 -52
- data/app/views/revise_auth/registrations/new.html.erb +29 -25
- data/app/views/revise_auth/sessions/new.html.erb +28 -13
- data/app/views/revise_auth/shared/_form_block.html.erb +7 -0
- data/app/views/shared/_error_messages.html.erb +18 -0
- data/lib/generators/revise_auth/model_generator.rb +13 -4
- data/lib/generators/revise_auth/templates/README +1 -2
- data/lib/generators/revise_auth/views_generator.rb +6 -0
- data/lib/revise_auth/api_model.rb +46 -0
- data/lib/revise_auth/version.rb +1 -1
- data/lib/revise_auth-jets.rb +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 825c70cb5515ef92564d9ba805da0c6629b8822c3b88b3760f4cee3b44e18c6c
|
4
|
+
data.tar.gz: f3befb88b7f16a042ed269bcc3e2bf12a50c58a512a0215f992587bbb95d010c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3edc1eff821369e7225b82e883d43e24373ae528d29682d01fdd9a14ad3c9549cbed623ec535d3448ab499986ff581a86a15811aeaf11965f9629ce7fbd55750
|
7
|
+
data.tar.gz: 70fedcacdf4b1d572810bf1120c8f915f10014ff0c89423a237e23299d542f42610a6d3db4ac20bfb1daac2d17fbd2fab37d33c3dfe4ae3ac69336811d2d17b1
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ bundle add "revise_auth-jets"
|
|
12
12
|
|
13
13
|
And then execute the following to generate a `User` model (optionally adding other fields such as `first_name` and `last_name`):
|
14
14
|
```bash
|
15
|
-
$ jets g revise_auth:model User
|
15
|
+
$ jets g revise_auth:model User
|
16
16
|
$ jets db:migrate
|
17
17
|
$ jets g revise_auth:views
|
18
18
|
```
|
data/app/config/routes.rb
CHANGED
@@ -23,6 +23,13 @@ Jets.application.routes.draw do
|
|
23
23
|
delete "logout", to: "sessions#delete"
|
24
24
|
end
|
25
25
|
|
26
|
+
# API routes
|
27
|
+
namespace :api do
|
28
|
+
namespace :v1 do
|
29
|
+
resource :me, only: :show
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
26
33
|
# The jets/public#show controller can serve static utf8 content out of the public folder.
|
27
34
|
# Note, as part of the deploy process Jets uploads files in the public folder to s3
|
28
35
|
# and serves them out of s3 directly. S3 is well suited to serve static assets.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Api::BaseController < ApplicationController
|
2
|
+
include ReviseAuth::Authentication
|
3
|
+
skip_before_action :verify_authenticity_token
|
4
|
+
prepend_before_action :authenticate_api_token!
|
5
|
+
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
6
|
+
rescue_from ActionController::ParameterMissing, with: :handle_parameter_missing
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def record_not_found
|
11
|
+
render json: {error: "Record Not Found"}, status: :not_found
|
12
|
+
end
|
13
|
+
|
14
|
+
def handle_parameter_missing(exception)
|
15
|
+
render json: {error: exception.message}, status: :bad_request
|
16
|
+
end
|
17
|
+
|
18
|
+
def authenticate_api_token!
|
19
|
+
if user_from_token
|
20
|
+
login(user_from_token)
|
21
|
+
else
|
22
|
+
head :unauthorized
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def token_from_header
|
27
|
+
request.headers.fetch("authorization", "").split(" ").last
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_token
|
31
|
+
@_api_token ||= ApiToken.find_by(token: token_from_header)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Only for use within authenticate_api_token! above
|
35
|
+
# Use current_user/Current.user or current_account/Current.account within app controllers
|
36
|
+
def user_from_token
|
37
|
+
if api_token.present?
|
38
|
+
api_token.touch(:last_used_at)
|
39
|
+
api_token.user
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -9,6 +9,7 @@ class ReviseAuth::RegistrationsController < ReviseAuthController
|
|
9
9
|
@user = User.new(sign_up_params)
|
10
10
|
if @user.save
|
11
11
|
login(@user)
|
12
|
+
current_user.api_tokens.first_or_create(name: ApiToken::APP_NAME)
|
12
13
|
redirect_to root_path
|
13
14
|
else
|
14
15
|
render :new, status: :unprocessable_entity
|
@@ -5,6 +5,7 @@ class ReviseAuth::SessionsController < ReviseAuthController
|
|
5
5
|
def create
|
6
6
|
if (user = User.authenticate_by(email: params[:email], password: params[:password]))
|
7
7
|
login(user)
|
8
|
+
current_user.api_tokens.first_or_create(name: ApiToken::APP_NAME)
|
8
9
|
redirect_to root_path
|
9
10
|
else
|
10
11
|
#flash[:alert] = I18n.t("revise_auth.invalid_email_or_password")
|