Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- lib/chatgpt_assistant/models.rb
Overview
User model
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
- #chat_by_title(title) ⇒ Object
- #chat_history ⇒ Object
- #confirm_account(hash) ⇒ Object
- #current_chat ⇒ Object
- #encrypt_password ⇒ Object
- #encrypt_token ⇒ Object
- #last_chat ⇒ Object
- #valid_password?(password) ⇒ Boolean
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
23 24 25 |
# File 'lib/chatgpt_assistant/models.rb', line 23 def password @password end |
Instance Method Details
#chat_by_title(title) ⇒ Object
75 76 77 |
# File 'lib/chatgpt_assistant/models.rb', line 75 def chat_by_title(title) chats.find_by(title: title) end |
#chat_history ⇒ Object
79 80 81 |
# File 'lib/chatgpt_assistant/models.rb', line 79 def chat_history current_chat..last(10).map { |m| "#{m.role}: #{m.content}\nat: #{m.created_at}" } end |
#confirm_account(hash) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chatgpt_assistant/models.rb', line 56 def confirm_account(hash) confirmation = { email: email, password_hash: password_hash, time: created_at } secret = BCrypt::Engine.hash_secret(JSON.parse(confirmation.to_json), password_salt) return false unless secret == hash self.token = secret self.active = true save true end |
#current_chat ⇒ Object
67 68 69 |
# File 'lib/chatgpt_assistant/models.rb', line 67 def current_chat chats.find(current_chat_id) end |
#encrypt_password ⇒ Object
40 41 42 43 44 45 |
# File 'lib/chatgpt_assistant/models.rb', line 40 def encrypt_password return if password.nil? self.password_salt = BCrypt::Engine.generate_salt self.password_hash = BCrypt::Engine.hash_secret(password, password_salt) end |
#encrypt_token ⇒ Object
47 48 49 50 |
# File 'lib/chatgpt_assistant/models.rb', line 47 def encrypt_token confirmation = { email: email, password_hash: password_hash, time: created_at } BCrypt::Engine.hash_secret(JSON.parse(confirmation.to_json), password_salt) end |
#last_chat ⇒ Object
71 72 73 |
# File 'lib/chatgpt_assistant/models.rb', line 71 def last_chat chats.last end |
#valid_password?(password) ⇒ Boolean
52 53 54 |
# File 'lib/chatgpt_assistant/models.rb', line 52 def valid_password?(password) BCrypt::Engine.hash_secret(password, password_salt) == password_hash end |