Class: Notee::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Notee::User
- Defined in:
- app/models/notee/user.rb
Constant Summary collapse
- SECURE =
constants
'SOFHGPOIJERPGOKSPDO2SPTI4RJ6POIFDJVS7ETJ1EITJHSPEKMVOEIGU'
- CIPHER =
'aes-256-cbc'
Instance Attribute Summary collapse
-
#editor_id ⇒ Object
Returns the value of attribute editor_id.
-
#file ⇒ Object
accessors.
-
#now_password ⇒ Object
Returns the value of attribute now_password.
-
#password ⇒ Object
Returns the value of attribute password.
-
#password_confirm ⇒ Object
Returns the value of attribute password_confirm.
Class Method Summary collapse
- .decrypt(password) ⇒ Object
- .root_user_setting ⇒ Object
- .sign_in(name_or_email, password) ⇒ Object
- .user_setting(user) ⇒ Object
Instance Method Summary collapse
Methods inherited from ApplicationRecord
#create_authority, #destroy_authority, #is_destroy?, #skip_callback_block, #update_authority
Instance Attribute Details
#editor_id ⇒ Object
Returns the value of attribute editor_id.
15 16 17 |
# File 'app/models/notee/user.rb', line 15 def editor_id @editor_id end |
#file ⇒ Object
accessors
11 12 13 |
# File 'app/models/notee/user.rb', line 11 def file @file end |
#now_password ⇒ Object
Returns the value of attribute now_password.
12 13 14 |
# File 'app/models/notee/user.rb', line 12 def now_password @now_password end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'app/models/notee/user.rb', line 13 def password @password end |
#password_confirm ⇒ Object
Returns the value of attribute password_confirm.
14 15 16 |
# File 'app/models/notee/user.rb', line 14 def password_confirm @password_confirm end |
Class Method Details
.decrypt(password) ⇒ Object
41 42 43 44 |
# File 'app/models/notee/user.rb', line 41 def self.decrypt(password) crypt = ActiveSupport::MessageEncryptor.new(SECURE, CIPHER) crypt.decrypt_and_verify(password) end |
.root_user_setting ⇒ Object
69 70 71 72 73 |
# File 'app/models/notee/user.rb', line 69 def self.root_user_setting if token = Token.create!(user_id: 0) Thread.current[:request].session[:access_token] = token.access_token end end |
.sign_in(name_or_email, password) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/notee/user.rb', line 46 def self.sign_in(name_or_email, password) # root-user login if Notee.notee_id == name_or_email && Notee.notee_password == password return root_user_setting end # other-user login user = not_trash.find_by(name: name_or_email) user = not_trash.find_by(email: name_or_email) unless user return false unless user return false if user.id == 0 # root_user return false unless password == decrypt(user.encrypted_password) user_setting(user) end |
.user_setting(user) ⇒ Object
63 64 65 66 67 |
# File 'app/models/notee/user.rb', line 63 def self.user_setting(user) if token = Token.create!(user_id: user.id) Thread.current[:request].session[:access_token] = token.access_token end end |