# frozen-string-literal: truemoduleRodauthFeature.define(:remember,:Remember)donotice_flash"Your remember setting has been updated"error_flash"There was an error updating your remember setting"loaded_templates%w'remember'view'remember','Change Remember Setting'additional_form_tagsbutton'Change Remember Setting'beforebefore'load_memory'afterafter'load_memory'redirectauth_value_method:raw_remember_token_deadline,nilauth_value_method:remember_cookie_options,{}.freezeauth_value_method:extend_remember_deadline?,falseauth_value_method:remember_period,{:days=>14}.freezeauth_value_method:remember_deadline_interval,{:days=>14}.freezeauth_value_method:remember_id_column,:idauth_value_method:remember_key_column,:keyauth_value_method:remember_deadline_column,:deadlineauth_value_method:remember_table,:account_remember_keysauth_value_method:remember_cookie_key,'_remember'auth_value_method:remember_param,'remember'auth_value_method:remember_remember_param_value,'remember'auth_value_method:remember_forget_param_value,'forget'auth_value_method:remember_disable_param_value,'disable'translatable_method:remember_remember_label,'Remember Me'translatable_method:remember_forget_label,'Forget Me'translatable_method:remember_disable_label,'Disable Remember Me'auth_methods(:add_remember_key,:disable_remember_login,:forget_login,:generate_remember_key_value,:get_remember_key,:load_memory,:remembered_session_id,:logged_in_via_remember_key?,:remember_key_value,:remember_login,:remove_remember_key)internal_request_method:remember_setupinternal_request_method:remember_disableinternal_request_method:account_id_for_remember_keyroutedo|r|require_accountbefore_remember_router.getdoremember_viewendr.postdoremember=param(remember_param)if[remember_remember_param_value,remember_forget_param_value,remember_disable_param_value].include?(remember)transactiondobefore_remember# :nocov:caseremember# :nocov:whenremember_remember_param_valueremember_loginwhenremember_forget_param_valueforget_loginwhenremember_disable_param_valuedisable_remember_loginendafter_rememberendset_notice_flashremember_notice_flashredirectremember_redirectelseset_response_error_reason_status(:invalid_remember_param,invalid_field_error_status)set_error_flashremember_error_flashremember_viewendendenddefremembered_session_idreturnunlesscookie=_get_remember_cookieid,key=cookie.split('_',2)returnunlessid&&keyactual,deadline=active_remember_key_ds(id).get([remember_key_column,remember_deadline_column])returnunlessactualifhmac_secretunlessvalid=timing_safe_eql?(key,compute_hmac(actual))unlessraw_remember_token_deadline&&raw_remember_token_deadline>convert_timestamp(deadline)returnendendendunlessvalid||timing_safe_eql?(key,actual)returnendidenddefload_memoryreturnifsession[session_key]unlessid=remembered_session_id# Only set expired cookie if there is already a cookie set.forget_loginif_get_remember_cookiereturnendset_session_value(session_key,id)account=account_from_sessionremove_session_value(session_key)unlessaccountremove_remember_key(id)forget_loginreturnendbefore_load_memorylogin_session('remember')ifextend_remember_deadline?active_remember_key_ds(id).update(remember_deadline_column=>Sequel.date_add(Sequel::CURRENT_TIMESTAMP,remember_period))remember_loginendafter_load_memoryenddefremember_loginget_remember_keyopts=Hash[remember_cookie_options]opts[:value]="#{account_id}_#{convert_token_key(remember_key_value)}"opts[:expires]=convert_timestamp(active_remember_key_ds.get(remember_deadline_column))opts[:path]="/"unlessopts.key?(:path)opts[:httponly]=trueunlessopts.key?(:httponly)opts[:secure]=trueunlessopts.key?(:secure)||!request.ssl?::Rack::Utils.set_cookie_header!(response.headers,remember_cookie_key,opts)enddefforget_loginopts=Hash[remember_cookie_options]opts[:path]="/"unlessopts.key?(:path)::Rack::Utils.delete_cookie_header!(response.headers,remember_cookie_key,opts)enddefget_remember_keyunless@remember_key_value=active_remember_key_ds.get(remember_key_column)generate_remember_key_valuetransactiondoremove_remember_keyadd_remember_keyendendnilenddefdisable_remember_loginremove_remember_keyenddefadd_remember_keyhash={remember_id_column=>account_id,remember_key_column=>remember_key_value}set_deadline_value(hash,remember_deadline_column,remember_deadline_interval)ife=raised_uniqueness_violation{remember_key_ds.insert(hash)}# If inserting into the remember key table causes a violation, we can pull the # existing row from the table. If there is no invalid row, we can then reraise.raiseeunless@remember_key_value=active_remember_key_ds.get(remember_key_column)endenddefremove_remember_key(id=account_id)remember_key_ds(id).deleteenddeflogged_in_via_remember_key?authenticated_by.include?('remember')endprivatedef_get_remember_cookierequest.cookies[remember_cookie_key]enddefafter_logoutforget_loginsuperifdefined?(super)enddefafter_close_accountremove_remember_keysuperifdefined?(super)endattr_reader:remember_key_valuedefgenerate_remember_key_value@remember_key_value=random_keyenddefuse_date_arithmetic?super||extend_remember_deadline?||db.database_type==:mysqlenddefremember_key_ds(id=account_id)db[remember_table].where(remember_id_column=>id)enddefactive_remember_key_ds(id=account_id)remember_key_ds(id).where(Sequel.expr(remember_deadline_column)>Sequel::CURRENT_TIMESTAMP)endendend