Class: Ibrain::User
- Inherits:
-
Base
- Object
- Base
- Ibrain::User
- Includes:
- Devise::JWT::RevocationStrategies::JTIMatcher
- Defined in:
- app/models/ibrain/user.rb
Instance Attribute Summary collapse
-
#jwt_token ⇒ Object
Returns the value of attribute jwt_token.
Class Method Summary collapse
- .create_with_line!(params) ⇒ Object
- .ibrain_find(params, available_columns) ⇒ Object
- .random_password ⇒ Object
- .social_find_or_initialize(params) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#jwt_token ⇒ Object
Returns the value of attribute jwt_token.
5 6 7 |
# File 'app/models/ibrain/user.rb', line 5 def jwt_token @jwt_token end |
Class Method Details
.create_with_line!(params) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/ibrain/user.rb', line 65 def create_with_line!(params) user = created!({ uid: params['uid'], provider: 'line', remote_avatar_url: params['info']['image'] }) user.skip_confirmation! unless user&.confirmed? user end |
.ibrain_find(params, available_columns) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/ibrain/user.rb', line 44 def ibrain_find(params, available_columns) matched_value = params[:username] || params[:email] if matched_value.present? query = available_columns.map do |column_name| <<~RUBY #{column_name} = '#{matched_value}' RUBY end.join(' OR ') where(query).first end end |
.random_password ⇒ Object
76 77 78 |
# File 'app/models/ibrain/user.rb', line 76 def random_password (('A'..'Z').to_a.sample(4) + ["~", "!", "@", "#", "$", "%", "^", "&", "*", "_", "-"].sample(1) + ('0'..'9').to_a.sample(2) + ('a'..'z').to_a.sample(4)).join end |
.social_find_or_initialize(params) ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/ibrain/user.rb', line 58 def (params) user = find_by(provider: params[:provider], uid: params[:uid]) return user if user.present? create!(params) end |
Instance Method Details
#can_skip_confirmation? ⇒ Boolean
39 40 41 |
# File 'app/models/ibrain/user.rb', line 39 def can_skip_confirmation? try(:is_admin?) || email.blank? end |
#jwt_payload ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/ibrain/user.rb', line 22 def jwt_payload # for hasura hasura_keys = { 'https://hasura.io/jwt/claims': { 'x-hasura-allowed-roles': Ibrain.user_class.roles.keys, 'x-hasura-default-role': role, 'x-hasura-user-id': id.to_s } } super.merge( { 'role' => role, 'exp' => determine_expiration }, hasura_keys) end |