Class: AnoubisSsoServer::User
- Inherits:
-
ApplicationRecord
- Object
- Anoubis::ApplicationRecord
- ApplicationRecord
- AnoubisSsoServer::User
- Defined in:
- app/models/anoubis_sso_server/user.rb
Overview
Default user class
Constant Summary collapse
- VALID_EMAIL_REGEX =
Regexp validation mask for email
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
Class Method Summary collapse
-
.load_cache(uuid) ⇒ Hash
Procedure returns User model data from the cache or database.
Instance Method Summary collapse
-
#after_destroy_sso_server_user ⇒ Object
Fires before delete User from database.
-
#before_save_sso_server_user ⇒ Object
Fires before save User data to database.
-
#before_validation_sso_server_user_on_create ⇒ Object
Fires before create any User on the server.
-
#clear_cache ⇒ Object
Procedure clear cached User model data.
-
#password_changed? ⇒ Boolean
Procedure checks if password was changed.
-
#save_cache ⇒ Object
Procedure saves cached User model data to Redis database for improve access speed.
-
#setup_private_user_id ⇒ String
Procedure setup private user identifier.
-
#setup_public_user_id ⇒ String
Procedure setup public user identifier.
Class Method Details
.load_cache(uuid) ⇒ Hash
Procedure returns User model data from the cache or database. If user data isn’t present in cache then call procedure that cache User model data.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/anoubis_sso_server/user.rb', line 94 def self.load_cache(uuid) begin data = JSON.parse self.redis.get("#{self.redis_prefix}user:#{uuid}"), { symbolize_names: true } rescue data = nil end unless data user = self.where(uuid: uuid).first return nil unless user user.save_cache data = JSON.parse(user.to_json(except: [:password_digest]), { symbolize_names: true }) end data end |
Instance Method Details
#after_destroy_sso_server_user ⇒ Object
Fires before delete User from database. Procedure call procedure for clear Redis cache data for the user.
67 68 69 |
# File 'app/models/anoubis_sso_server/user.rb', line 67 def after_destroy_sso_server_user clear_cache end |
#before_save_sso_server_user ⇒ Object
Fires before save User data to database. Procedure setup email, timezone and call procedure for clear Redis cache data for the user.
58 59 60 61 62 |
# File 'app/models/anoubis_sso_server/user.rb', line 58 def before_save_sso_server_user self.timezone = 'GMT' if !self.timezone self.email = self.email.downcase self.clear_cache end |
#before_validation_sso_server_user_on_create ⇒ Object
Fires before create any User on the server. Procedure generates internal UUID and setup timezone to GMT. Public user identifier is generated also if not defined.
34 35 36 37 38 39 |
# File 'app/models/anoubis_sso_server/user.rb', line 34 def before_validation_sso_server_user_on_create self.uuid = setup_private_user_id self.public = setup_public_user_id unless public self.timezone = 'GMT' if !self.timezone end |
#clear_cache ⇒ Object
Procedure clear cached User model data.
79 80 81 |
# File 'app/models/anoubis_sso_server/user.rb', line 79 def clear_cache redis.del("#{redis_prefix}user:#{uuid}") if redis end |
#password_changed? ⇒ Boolean
Procedure checks if password was changed.
86 87 88 |
# File 'app/models/anoubis_sso_server/user.rb', line 86 def password_changed? !password.blank? end |
#save_cache ⇒ Object
Procedure saves cached User model data to Redis database for improve access speed.
73 74 75 |
# File 'app/models/anoubis_sso_server/user.rb', line 73 def save_cache redis.set("#{redis_prefix}user:#{uuid}", self.to_json(except: [:password_digest])) if redis end |
#setup_private_user_id ⇒ String
Procedure setup private user identifier. Procedure can be redefined.
44 45 46 |
# File 'app/models/anoubis_sso_server/user.rb', line 44 def setup_private_user_id SecureRandom.uuid end |
#setup_public_user_id ⇒ String
Procedure setup public user identifier. Used for open API. Procedure can be redefined.
51 52 53 |
# File 'app/models/anoubis_sso_server/user.rb', line 51 def setup_public_user_id SecureRandom.uuid end |