arkaan 3.0.0 → 3.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99aa03dc8a6f14cf981a81b89ab54adf9450c7bf2646a8231883ec71673d5695
4
- data.tar.gz: 1e852dcc77ae4418286c94b7390888b3f8e71c57770852548cdf585ec300cea8
3
+ metadata.gz: 65f8289754a8004de723395b4b56b51c3a03298e12e2862bb93229a0b5a2628c
4
+ data.tar.gz: 784a148f4f3ceb643e5b2e644e0c79afd5207aaa8ed5c82c9dadd6b264a0ee6f
5
5
  SHA512:
6
- metadata.gz: 7fb7d81811559f1daff3971c65b80d323ad9c29705e96b5cc3d6ba2729234498b094955e76478148c3876b2aeb62f6dad5806d34f6fae6761d0fecb86d495917
7
- data.tar.gz: 4d2398bdc636a6b2307d4d4c101cf7f75e0e74b958f13e1d37d7e22addbbbfaec96022565737212c9f7b4beacd8f94e4f956f73a43203ca057612c8f50b33683
6
+ metadata.gz: 4553b140636382535cfaa9157d711c4e96d42e79c6f52dc4665eead60c9d73f9b9eaea1ab6c1f8f9849d8ae1f57d7ec880baacd67e42981ed663dca68c7a91bf
7
+ data.tar.gz: af868a3f99aea837395fb859bb0c5fe056d5b4f2c109c524a5eca7f077f0c03965d22d006f99e5121ec0bb40a1f09c30ffd6a9d5c63ef7c6ecf81acae0967801
@@ -99,5 +99,7 @@ module Arkaan
99
99
 
100
100
  validates :password_confirmation,
101
101
  presence: { message: 'required', if: :password_digest_changed? }
102
+
103
+ scope :search, ->(pattern) { any_of({ username: /#{pattern}/i }, { email: /#{pattern}/i }) }
102
104
  end
103
105
  end
@@ -4,6 +4,7 @@ module Arkaan
4
4
  # This module holds the logic for user authentication to our frontend.
5
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
6
6
  module Authentication
7
+ autoload :Device, 'arkaan/authentication/device'
7
8
  autoload :Session, 'arkaan/authentication/session'
8
9
  end
9
10
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arkaan
4
+ module Authentication
5
+ # A device is a computer or mobile phone from which a user logs in.
6
+ # @pauthor Vincent Courtois <courtois.vincent@outlook.com>
7
+ class Device
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ # @!attribute [rw] label
12
+ # @return [String] the label attached to the device, describing it in details.
13
+ field :label, type: String
14
+ # @!attribute [rw] user_agent
15
+ # @return [String] the string representation of the browser and OS of the user
16
+ field :user_agent, type: String
17
+ # @!attribute [rw] ip
18
+ # @return [String] the IP address of the user
19
+ field :ip, type: String
20
+ # @!attribute [rw] safe
21
+ # @return [Boolean] TRUE if the device is considered safe, FALSE otherwise
22
+ field :safe, type: Boolean, default: false
23
+
24
+ # @!attribute [rw] sessions
25
+ # @return [Array<Arkaan::Authentication::Session] the sessions this browser is linked to.
26
+ has_many :sessions, class_name: 'Arkaan::Authentication::Session', inverse_of: :device
27
+ end
28
+ end
29
+ end
@@ -12,20 +12,36 @@ module Arkaan
12
12
 
13
13
  # @!attribute [rw] token
14
14
  # @return [String] the unique token for this session, used to identify it and be sure the user is connected.
15
- field :token, type: String
15
+ field :session_id, type: String
16
16
  # @!attribute [rw] websocket_id
17
17
  # @return [String] the ID of the websocket the user is connected to.
18
18
  # It's not an association because instances are embedded.
19
19
  field :websocket_id, type: String, default: ''
20
+ # @!attribute [rw] duration
21
+ # @return [Integer] the duration of the session in seconds before it expires.
22
+ field :duration, type: Integer, default: 86_400
20
23
 
21
24
  # @!attribute [rw] account
22
25
  # @return [Arkaan::Account] the account connected to the application.
23
26
  belongs_to :account, class_name: 'Arkaan::Account', inverse_of: :sessions
27
+ # @!attribute [rw] device
28
+ # @return [Arkaan::Authentication::Device] the device (computer/mobile) linked to this session
29
+ belongs_to :device, class_name: 'Arkaan::Authentication::Device', inverse_of: :sessions, optional: true
24
30
 
25
- validates :token,
31
+ validates :session_id,
26
32
  presence: { message: 'required' },
27
- uniqueness: { message: 'uniq', if: :token? },
28
- length: { minimum: 10, message: 'minlength', if: :token? }
33
+ uniqueness: { message: 'uniq', if: :session_id? },
34
+ length: { minimum: 10, message: 'minlength', if: :session_id? }
35
+
36
+ validates :duration,
37
+ numericality: { greater_than_or_equal_to: 0, message: 'minimum' },
38
+ presence: { message: 'required' }
39
+
40
+ # Checks if the session is expired (it has a duration, and the duration has passed)
41
+ # @return [Boolean] TRUE if the session is expired, FALSE otherwise.
42
+ def expired?
43
+ duration != 0 && created_at + duration.to_f < DateTime.now
44
+ end
29
45
  end
30
46
  end
31
47
  end
@@ -14,7 +14,7 @@ module Arkaan
14
14
  field :name, type: String
15
15
  # @!attribute [rw] key
16
16
  # @return [String] the unique key for the application, identifying it when requesting a token for the API.
17
- field :application_key, type: String, default: -> { SecureRandom.hex }
17
+ field :app_key, type: String, default: -> { SecureRandom.hex }
18
18
  # @!attribute [rw] premium
19
19
  # @return [Boolean] a value indicating whether the application should automatically receive a token
20
20
  # when an account is created, or not.
@@ -36,7 +36,7 @@ module Arkaan
36
36
  length: { minimum: 6, message: 'minlength' },
37
37
  uniqueness: { message: 'uniq' }
38
38
 
39
- validates :application_key,
39
+ validates :app_key,
40
40
  presence: { message: 'required' },
41
41
  uniqueness: { message: 'uniq' }
42
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_cleaner
@@ -313,6 +313,7 @@ files:
313
313
  - lib/arkaan.rb
314
314
  - lib/arkaan/account.rb
315
315
  - lib/arkaan/authentication.rb
316
+ - lib/arkaan/authentication/device.rb
316
317
  - lib/arkaan/authentication/session.rb
317
318
  - lib/arkaan/campaign.rb
318
319
  - lib/arkaan/campaigns.rb