Class: Lato::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Lato::User
- Defined in:
- app/models/lato/user.rb
Instance Method Summary collapse
- #destroy_with_confirmation(params) ⇒ Object
-
#full_name ⇒ Object
Helpers.
- #request_recover_password(params) ⇒ Object
- #request_verify_email ⇒ Object
-
#signin(params) ⇒ Object
Operations.
- #update_password(params) ⇒ Object
-
#valid_accepted_privacy_policy_version? ⇒ Boolean
Questions.
- #valid_accepted_terms_and_conditions_version? ⇒ Boolean
- #verify_email(params) ⇒ Object
Instance Method Details
#destroy_with_confirmation(params) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'app/models/lato/user.rb', line 117 def destroy_with_confirmation(params) unless params[:email_confirmation] == email errors.add(:email, 'non corretto') return end destroy end |
#full_name ⇒ Object
Helpers
53 54 55 |
# File 'app/models/lato/user.rb', line 53 def full_name "#{last_name} #{first_name}" end |
#request_recover_password(params) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/models/lato/user.rb', line 126 def request_recover_password(params) user = Lato::User.find_by(email: params[:email]) unless user errors.add(:email, 'non registrato') return end code = SecureRandom.hex.upcase delivery = Lato::UserMailer.password_update_mail(user.id, code).deliver_now unless delivery errors.add(:base, 'Impossibile inviare mail') return end self.id = user.id reload password_update_code.value = code true end |
#request_verify_email ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/lato/user.rb', line 80 def request_verify_email if email_verification_semaphore.value errors.add(:base, 'Attendi almeno 2 minuti per provare un nuovo tentativo di verifica email') return end code = SecureRandom.hex.upcase delivery = Lato::UserMailer.email_verification_mail(id, code).deliver_now unless delivery errors.add(:base, 'Impossibile inviare mail') return end email_verification_code.value = code email_verification_semaphore.value = true true end |
#signin(params) ⇒ Object
Operations
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/lato/user.rb', line 60 def signin(params) self.email = params[:email] user = Lato::User.find_by(email: params[:email]) unless user errors.add(:email, 'non valido') return end unless user.authenticate(params[:password]) errors.add(:password, 'non valida') return end self.id = user.id reload true end |
#update_password(params) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/models/lato/user.rb', line 148 def update_password(params) unless password_update_code.value errors.add(:base, 'Il codice di verifica risulta scaduto') return end unless password_update_code.value == params[:code] errors.add(:base, 'Il codice di verifica non risulta valido') return end password_update_code.value = nil update(params.permit(:password, :password_confirmation)) end |
#valid_accepted_privacy_policy_version? ⇒ Boolean
Questions
42 43 44 |
# File 'app/models/lato/user.rb', line 42 def valid_accepted_privacy_policy_version? @valid_accepted_privacy_policy_version ||= accepted_privacy_policy_version >= Lato.config.legal_privacy_policy_version end |
#valid_accepted_terms_and_conditions_version? ⇒ Boolean
46 47 48 |
# File 'app/models/lato/user.rb', line 46 def valid_accepted_terms_and_conditions_version? @valid_accepted_terms_and_conditions_version ||= accepted_terms_and_conditions_version >= Lato.config.legal_privacy_policy_version end |
#verify_email(params) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/lato/user.rb', line 99 def verify_email(params) unless email_verification_code.value errors.add(:base, 'Il codice di verifica email risulta scaduto') return end unless email_verification_code.value == params[:code] errors.add(:base, 'Il codice di verifica email non risulta valido') return end email_verification_code.value = nil email_verification_semaphore.value = nil update_column(:email_verified_at, Time.now) true end |