bscf-core 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -0
- data/app/controllers/bscf/core/application_controller.rb +33 -0
- data/app/services/token_service.rb +14 -0
- data/lib/bscf/core/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1210d0d4c690b34b822a20bd4e7a364e1731cb1df1e40b8352554805ee29e234
|
4
|
+
data.tar.gz: 86b2afc9d7fbfc5d2ebff1096269aebaa1f80c4b77b3e45615c70c4e2ee43ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7eb9cb98cda9c7f392934338a2d5a20bbc139adf7e068323da70bc7aa3f39b11983e4d99d92db284cdfabc63f66989892a121ef28ffa52a8f73d5fb26d5ca2
|
7
|
+
data.tar.gz: 48294c77f982ea1c2e9691bff4d29010aabcba9f8bdd98a3a449d80505e9c3458df93074f587c2d9cd9d79595f56e3e45148b332cbcaac3829bbf0034913de33
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# Bscf::Core
|
2
|
+
|
2
3
|
Short description and motivation.
|
3
4
|
|
4
5
|
## Usage
|
6
|
+
|
5
7
|
How to use my plugin.
|
6
8
|
|
7
9
|
## Installation
|
10
|
+
|
8
11
|
Add this line to your application's Gemfile:
|
9
12
|
|
10
13
|
```ruby
|
@@ -12,17 +15,57 @@ gem "bscf-core"
|
|
12
15
|
```
|
13
16
|
|
14
17
|
And then execute:
|
18
|
+
|
15
19
|
```bash
|
16
20
|
$ bundle
|
17
21
|
```
|
18
22
|
|
19
23
|
Or install it yourself as:
|
24
|
+
|
20
25
|
```bash
|
21
26
|
$ gem install bscf-core
|
22
27
|
```
|
23
28
|
|
29
|
+
#### Version Tasks
|
30
|
+
|
31
|
+
- **Bump Version**
|
32
|
+
|
33
|
+
rake version:bump[type]
|
34
|
+
|
35
|
+
- `patch`: Increases version by 0.0.1 (e.g., 1.0.0 -> 1.0.1)
|
36
|
+
|
37
|
+
```bash
|
38
|
+
rake version:bump[patch]
|
39
|
+
```
|
40
|
+
|
41
|
+
- `minor`: Increases version by 0.1.0 (e.g., 1.0.0 -> 1.1.0)
|
42
|
+
|
43
|
+
```bash
|
44
|
+
rake version:bump[minor]
|
45
|
+
```
|
46
|
+
|
47
|
+
- `major`: Increases version by 1.0.0 (e.g., 1.0.0 -> 2.0.0)
|
48
|
+
|
49
|
+
```bash
|
50
|
+
rake version:bump[major]
|
51
|
+
```
|
52
|
+
|
53
|
+
- `pre`: Adds or increments pre-release version (e.g., 1.0.0 -> 1.0.0-pre.1)
|
54
|
+
|
55
|
+
```bash
|
56
|
+
rake version:bump[pre]
|
57
|
+
```
|
58
|
+
|
59
|
+
- `release`: Removes pre-release version (e.g., 1.0.0-pre.1 -> 1.0.0)
|
60
|
+
|
61
|
+
```bash
|
62
|
+
rake version:bump[release]
|
63
|
+
```
|
64
|
+
|
24
65
|
## Contributing
|
66
|
+
|
25
67
|
Contribution directions go here.
|
26
68
|
|
27
69
|
## License
|
70
|
+
|
28
71
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,6 +1,39 @@
|
|
1
1
|
module Bscf
|
2
2
|
module Core
|
3
3
|
class ApplicationController < ActionController::API
|
4
|
+
private
|
5
|
+
|
6
|
+
def is_authenticated
|
7
|
+
render json: { error: "Not authenticated" }, status: :unauthorized unless current_user
|
8
|
+
end
|
9
|
+
|
10
|
+
def is_allowed
|
11
|
+
user_role = UserRole.find_by(user: current_user)
|
12
|
+
role = Role.find(user_role.role_id)
|
13
|
+
render json: { error: "Not authorized" }, status: :ok unless role.name == "User" || role.name == "Admin"
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
return @current_user if defined?(@current_user)
|
18
|
+
|
19
|
+
return unless auth_token
|
20
|
+
|
21
|
+
begin
|
22
|
+
payload = TokenService.new.decode(auth_token)
|
23
|
+
@current_user = User.find_by(id: payload["user"]["id"])
|
24
|
+
rescue JWT::DecodeError => e
|
25
|
+
Rails.logger.warn "Token decode error: #{e.message}"
|
26
|
+
nil
|
27
|
+
rescue ActiveRecord::RecordNotFound => e
|
28
|
+
Rails.logger.warn "User not found: #{e.message}"
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def auth_token
|
34
|
+
auth_header = request.headers["Authorization"]
|
35
|
+
auth_header&.split(" ")&.last
|
36
|
+
end
|
4
37
|
end
|
5
38
|
end
|
6
39
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "jwt"
|
2
|
+
|
3
|
+
class TokenService
|
4
|
+
def encode(payload)
|
5
|
+
JWT.encode(payload, ENV["SECRET_KEY_BASE"] || "secret_key_base")
|
6
|
+
end
|
7
|
+
|
8
|
+
def decode(token)
|
9
|
+
body = JWT.decode(token, ENV["SECRET_KEY_BASE"] || "secret_key_base")[0]
|
10
|
+
HashWithIndifferentAccess.new body
|
11
|
+
rescue JWT::DecodeError, JSON::ParserError => e
|
12
|
+
raise JWT::DecodeError.new("Invalid token")
|
13
|
+
end
|
14
|
+
end
|
data/lib/bscf/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bscf-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asrat
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-29 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: active_model_serializers
|
@@ -303,6 +303,7 @@ files:
|
|
303
303
|
- app/models/bscf/core/user_role.rb
|
304
304
|
- app/models/bscf/core/virtual_account.rb
|
305
305
|
- app/models/bscf/core/virtual_account_transaction.rb
|
306
|
+
- app/services/token_service.rb
|
306
307
|
- config/database.yml
|
307
308
|
- config/routes.rb
|
308
309
|
- db/migrate/20250326065606_create_bscf_core_users.rb
|