Class: Monban::Repository::Auth::Sequel
- Inherits:
-
Getto::Repository::Sequel
- Object
- Getto::Repository::Sequel
- Monban::Repository::Auth::Sequel
- Defined in:
- lib/monban/repository/auth.rb
Instance Method Summary collapse
- #account_id_by_email(email:) ⇒ Object
- #account_id_by_login_id(login_id:) ⇒ Object
- #account_id_by_public_id(public_id:, now:) ⇒ Object
- #authy_id(account_id:) ⇒ Object
- #delete_reset_password_token(account_id:) ⇒ Object
- #insert_public_id(account_id:, public_id:, created_at:, expired_at:) ⇒ Object
- #insert_reset_password_token(account_id:, reset_token:, created_at:, expired_at:) ⇒ Object
- #login_id(account_id:) ⇒ Object
- #password_hash_match?(account_id:, password_hash:) ⇒ Boolean
- #password_salt(account_id:) ⇒ Object
- #preserve_public_id_original_created_at(public_id:, original_created_at:) ⇒ Object
- #public_id_exists?(public_id:) ⇒ Boolean
- #public_id_original_created_at(public_id:) ⇒ Object
- #public_id_renew_enabled?(public_id:, original_created_at:) ⇒ Boolean
- #reset_password_token_exists?(reset_token:) ⇒ Boolean
- #roles(account_id:) ⇒ Object
- #update_authy_id(account_id:, authy_id:, now:) ⇒ Object
- #update_password_hash(account_id:, password_hash:, now:) ⇒ Object
- #valid_reset_password_token?(account_id:, reset_token:, now:) ⇒ Boolean
- #wipe_old_reset_password_token(now:) ⇒ Object
Instance Method Details
#account_id_by_email(email:) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/monban/repository/auth.rb', line 18 def account_id_by_email(email:) db[:account_reset_password_emails] .where(email: email) .select(:account_id) .map{|hash| hash[:account_id] }.first end |
#account_id_by_login_id(login_id:) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/monban/repository/auth.rb', line 25 def account_id_by_login_id(login_id:) db[:account_login_ids] .where(login_id: login_id) .select(:account_id) .map{|hash| hash[:account_id] }.first end |
#account_id_by_public_id(public_id:, now:) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/monban/repository/auth.rb', line 10 def account_id_by_public_id(public_id:, now:) db[:account_public_ids] .where(public_id: public_id) .where(::Sequel[:account_public_ids][:expired_at] > now) .select(:account_id) .map{|hash| hash[:account_id] }.first end |
#authy_id(account_id:) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/monban/repository/auth.rb', line 86 def authy_id(account_id:) db[:account_authy_ids] .where(account_id: account_id) .select(:authy_id) .map{|hash| hash[:authy_id]}.first end |
#delete_reset_password_token(account_id:) ⇒ Object
109 110 111 112 113 |
# File 'lib/monban/repository/auth.rb', line 109 def delete_reset_password_token(account_id:) db[:account_reset_password_tokens] .where(account_id: account_id) .delete end |
#insert_public_id(account_id:, public_id:, created_at:, expired_at:) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/monban/repository/auth.rb', line 75 def insert_public_id(account_id:, public_id:, created_at:, expired_at:) db[:account_public_ids].insert( account_id: account_id, public_id: public_id, created_at: created_at, expired_at: expired_at, original_created_at: created_at, ) end |
#insert_reset_password_token(account_id:, reset_token:, created_at:, expired_at:) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/monban/repository/auth.rb', line 121 def insert_reset_password_token(account_id:, reset_token:, created_at:, expired_at:) db[:account_reset_password_tokens].insert( account_id: account_id, reset_token: reset_token, created_at: created_at, expired_at: expired_at, ) end |
#login_id(account_id:) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/monban/repository/auth.rb', line 32 def login_id(account_id:) db[:account_login_ids] .where(account_id: account_id) .select(:login_id) .map{|hash| hash[:login_id]}.first end |
#password_hash_match?(account_id:, password_hash:) ⇒ Boolean
154 155 156 157 158 |
# File 'lib/monban/repository/auth.rb', line 154 def password_hash_match?(account_id:, password_hash:) not db[:account_password_hashes] .where(account_id: account_id, password_hash: password_hash) .empty? end |
#password_salt(account_id:) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/monban/repository/auth.rb', line 147 def password_salt(account_id:) db[:account_password_hashes] .select(::Sequel.function(:substring, ::Sequel[:password_hash], 1, 30).as(:salt)) .where(account_id: account_id) .map{|hash| hash[:salt]}.first end |
#preserve_public_id_original_created_at(public_id:, original_created_at:) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/monban/repository/auth.rb', line 61 def preserve_public_id_original_created_at(public_id:, original_created_at:) db[:account_public_ids] .where(public_id: public_id) .update( original_created_at: original_created_at, ) end |
#public_id_exists?(public_id:) ⇒ Boolean
69 70 71 72 73 |
# File 'lib/monban/repository/auth.rb', line 69 def public_id_exists?(public_id:) not db[:account_public_ids] .where(public_id: public_id) .empty? end |
#public_id_original_created_at(public_id:) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/monban/repository/auth.rb', line 54 def public_id_original_created_at(public_id:) db[:account_public_ids] .where(public_id: public_id) .select(:original_created_at) .map{|hash| hash[:original_created_at]}.first end |
#public_id_renew_enabled?(public_id:, original_created_at:) ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/monban/repository/auth.rb', line 47 def public_id_renew_enabled?(public_id:, original_created_at:) not db[:account_public_ids] .where(public_id: public_id) .where(::Sequel[:account_public_ids][:original_created_at] > original_created_at) .empty? end |
#reset_password_token_exists?(reset_token:) ⇒ Boolean
115 116 117 118 119 |
# File 'lib/monban/repository/auth.rb', line 115 def reset_password_token_exists?(reset_token:) not db[:account_reset_password_tokens] .where(reset_token: reset_token) .empty? end |
#roles(account_id:) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/monban/repository/auth.rb', line 39 def roles(account_id:) db[:account_roles] .where(account_id: account_id) .select(:role) .map{|r| r[:role]} end |
#update_authy_id(account_id:, authy_id:, now:) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/monban/repository/auth.rb', line 93 def update_authy_id(account_id:, authy_id:, now:) if db[:account_authy_ids].where(account_id: account_id).empty? db[:account_authy_ids].insert( account_id: account_id, authy_id: authy_id, created_at: now, ) else db[:account_authy_ids].where(account_id: account_id).update( authy_id: authy_id, created_at: now, ) end end |
#update_password_hash(account_id:, password_hash:, now:) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/monban/repository/auth.rb', line 160 def update_password_hash(account_id:, password_hash:, now:) if db[:account_password_hashes].where(account_id: account_id).empty? db[:account_password_hashes].insert( account_id: account_id, password_hash: password_hash, created_at: now, updated_at: now, ) else db[:account_password_hashes].where(account_id: account_id).update( password_hash: password_hash, updated_at: now, ) end end |
#valid_reset_password_token?(account_id:, reset_token:, now:) ⇒ Boolean
136 137 138 139 140 141 142 143 144 |
# File 'lib/monban/repository/auth.rb', line 136 def valid_reset_password_token?(account_id:, reset_token:, now:) not db[:account_reset_password_tokens] .where( account_id: account_id, reset_token: reset_token, ) .where(::Sequel[:account_reset_password_tokens][:expired_at] > now) .empty? end |
#wipe_old_reset_password_token(now:) ⇒ Object
130 131 132 133 134 |
# File 'lib/monban/repository/auth.rb', line 130 def wipe_old_reset_password_token(now:) db[:account_reset_password_tokens] .where(::Sequel[:account_reset_password_tokens][:expired_at] <= now) .delete end |