|
@@ -0,0 +1,38 @@
|
|
1
|
+class Token < ApplicationRecord
|
|
2
|
+ # A Token contains some information that can be used as an alternative way to
|
|
3
|
+ # authenticate a user, typically instead of a username/password combination.
|
|
4
|
+ #
|
|
5
|
+ # At least the following types of tokens will exist:
|
|
6
|
+ # - Account confirmation tokens, sent to the user when their account is
|
|
7
|
+ # created (to verify their email address)
|
|
8
|
+ # - Password reset tokens
|
|
9
|
+ # - API authentication tokens
|
|
10
|
+ #
|
|
11
|
+ # @!attribute token
|
|
12
|
+ # @return [String]
|
|
13
|
+ # a unique token, that allows the holder to perform some action.
|
|
14
|
+ #
|
|
15
|
+ # @!attribute expires
|
|
16
|
+ # @return [DateTime]
|
|
17
|
+ # when the token will expire (and will no longer be usable).
|
|
18
|
+ #
|
|
19
|
+ # @!attribute tokentype
|
|
20
|
+ # @return [String]
|
|
21
|
+ # what action the token allows the holder to perform. Use the hash
|
|
22
|
+ # Token::TYPES instead of comparing directly!
|
|
23
|
+ #
|
|
24
|
+ # @!attribute user
|
|
25
|
+ # @return [User]
|
|
26
|
+ # what user the token allows the holder to authenticate as.
|
|
27
|
+
|
|
28
|
+ TYPES = {
|
|
29
|
+ password_reset: 'pw_reset',
|
|
30
|
+ account_confirmation: 'confirm',
|
|
31
|
+ api_authentication: 'api'
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ validates :token, uniqueness: true, presence: true
|
|
35
|
+ validates :user, presence: true
|
|
36
|
+
|
|
37
|
+ belongs_to :user
|
|
38
|
+end
|