Module: Volt
- Includes:
- Configurations, Modes
- Defined in:
- lib/volt/volt/repos.rb,
lib/volt.rb,
lib/volt/cli.rb,
lib/volt/boot.rb,
lib/volt/config.rb,
lib/volt/config.rb,
lib/volt/server.rb,
lib/volt/version.rb,
lib/volt/volt/app.rb,
lib/volt/cli/bundle.rb,
lib/volt/cli/runner.rb,
lib/volt/models/url.rb,
lib/volt/page/tasks.rb,
lib/volt/spec/setup.rb,
lib/volt/tasks/task.rb,
lib/volt/volt/users.rb,
app/volt/models/user.rb,
lib/volt/cli/console.rb,
lib/volt/utils/ejson.rb,
lib/volt/utils/modes.rb,
lib/volt/models/model.rb,
lib/volt/page/channel.rb,
lib/volt/utils/timers.rb,
lib/volt/models/buffer.rb,
lib/volt/models/cursor.rb,
lib/volt/models/errors.rb,
lib/volt/page/document.rb,
lib/volt/router/routes.rb,
lib/volt/spec/capybara.rb,
lib/volt/utils/parsing.rb,
lib/volt/volt/templates.rb,
lib/volt/spec/sauce_labs.rb,
lib/volt/page/sub_context.rb,
lib/volt/page/url_tracker.rb,
lib/volt/tasks/dispatcher.rb,
lib/volt/volt/environment.rb,
lib/volt/cli/asset_compile.rb,
lib/volt/extra_core/logger.rb,
lib/volt/page/channel_stub.rb,
lib/volt/models/array_model.rb,
lib/volt/models/permissions.rb,
lib/volt/reactive/eventable.rb,
lib/volt/utils/generic_pool.rb,
lib/volt/models/associations.rb,
lib/volt/models/helpers/base.rb,
lib/volt/reactive/dependency.rb,
lib/volt/utils/event_counter.rb,
lib/volt/utils/local_storage.rb,
lib/volt/utils/local_storage.rb,
lib/volt/models/helpers/dirty.rb,
lib/volt/models/helpers/model.rb,
lib/volt/models/model_wrapper.rb,
lib/volt/models/state_manager.rb,
lib/volt/page/document_events.rb,
lib/volt/reactive/computation.rb,
lib/volt/server/forking_server.rb,
lib/volt/volt/server_setup/app.rb,
lib/volt/data_stores/data_store.rb,
lib/volt/models/persistors/base.rb,
lib/volt/models/persistors/page.rb,
lib/volt/page/template_renderer.rb,
lib/volt/reactive/reactive_hash.rb,
lib/volt/server/rack/opal_files.rb,
lib/volt/utils/recursive_exists.rb,
lib/volt/cli/base_index_renderer.rb,
lib/volt/models/persistors/flash.rb,
lib/volt/models/persistors/store.rb,
lib/volt/page/targets/dom_target.rb,
lib/volt/reactive/reactive_array.rb,
lib/volt/server/rack/asset_files.rb,
lib/volt/server/rack/index_files.rb,
lib/volt/models/persistors/params.rb,
lib/volt/page/bindings/if_binding.rb,
lib/volt/page/targets/dom_section.rb,
lib/volt/reactive/class_eventable.rb,
lib/volt/reactive/hash_dependency.rb,
lib/volt/server/rack/http_request.rb,
lib/volt/models/persistors/cookies.rb,
lib/volt/page/path_string_renderer.rb,
lib/volt/page/targets/base_section.rb,
lib/volt/page/targets/dom_template.rb,
lib/volt/server/rack/http_resource.rb,
lib/volt/utils/lifecycle_callbacks.rb,
lib/volt/utils/logging/task_logger.rb,
lib/volt/volt/client_setup/browser.rb,
lib/volt/models/helpers/array_model.rb,
lib/volt/page/bindings/base_binding.rb,
lib/volt/page/bindings/each_binding.rb,
lib/volt/page/bindings/view_binding.rb,
lib/volt/server/component_templates.rb,
lib/volt/server/rack/component_code.rb,
lib/volt/controllers/http_controller.rb,
lib/volt/controllers/login_as_helper.rb,
lib/volt/models/model_hash_behaviour.rb,
lib/volt/page/bindings/event_binding.rb,
lib/volt/page/bindings/yield_binding.rb,
lib/volt/reactive/reactive_accessors.rb,
lib/volt/server/rack/component_paths.rb,
lib/volt/utils/generic_counting_pool.rb,
lib/volt/controllers/model_controller.rb,
lib/volt/controllers/template_helpers.rb,
lib/volt/extra_core/inflector/methods.rb,
lib/volt/models/helpers/change_helpers.rb,
lib/volt/models/persistors/array_store.rb,
lib/volt/models/persistors/local_store.rb,
lib/volt/models/persistors/model_store.rb,
lib/volt/models/persistors/store_state.rb,
lib/volt/models/root_models/store_root.rb,
lib/volt/page/bindings/content_binding.rb,
lib/volt/page/string_template_renderer.rb,
lib/volt/page/targets/attribute_target.rb,
lib/volt/server/html_parser/each_scope.rb,
lib/volt/server/html_parser/view_scope.rb,
lib/volt/server/rack/source_map_server.rb,
app/volt/controllers/notices_controller.rb,
lib/volt/controllers/collection_helpers.rb,
lib/volt/models/root_models/root_models.rb,
lib/volt/models/validations/validations.rb,
lib/volt/page/targets/attribute_section.rb,
lib/volt/server/html_parser/view_parser.rb,
lib/volt/data_stores/base_adaptor_client.rb,
lib/volt/data_stores/base_adaptor_server.rb,
lib/volt/models/helpers/listener_tracker.rb,
lib/volt/models/persistors/store_factory.rb,
lib/volt/page/bindings/attribute_binding.rb,
lib/volt/page/bindings/component_binding.rb,
lib/volt/server/html_parser/view_handler.rb,
lib/volt/server/message_bus/peer_to_peer.rb,
lib/volt/extra_core/inflector/inflections.rb,
lib/volt/models/validators/type_validator.rb,
lib/volt/server/html_parser/if_view_scope.rb,
lib/volt/server/rack/http_response_header.rb,
lib/volt/server/socket_connection_handler.rb,
lib/volt/models/validators/email_validator.rb,
lib/volt/models/validators/user_validation.rb,
lib/volt/server/html_parser/textarea_scope.rb,
lib/volt/models/persistors/query/normalizer.rb,
lib/volt/models/validators/format_validator.rb,
lib/volt/models/validators/length_validator.rb,
lib/volt/models/validators/unique_validator.rb,
lib/volt/server/html_parser/attribute_scope.rb,
lib/volt/server/message_bus/message_encoder.rb,
lib/volt/server/middleware/middleware_stack.rb,
lib/volt/server/rack/http_response_renderer.rb,
lib/volt/server/websocket/websocket_handler.rb,
lib/volt/server/message_bus/base_message_bus.rb,
lib/volt/server/rack/sprockets_helpers_setup.rb,
lib/volt/models/persistors/model_identity_map.rb,
lib/volt/models/validators/presence_validator.rb,
lib/volt/server/html_parser/sandlebars_parser.rb,
lib/volt/server/websocket/rack_server_adaptor.rb,
lib/volt/models/validators/inclusion_validator.rb,
lib/volt/server/socket_connection_handler_stub.rb,
lib/volt/models/persistors/query/query_listener.rb,
lib/volt/page/targets/helpers/comment_searchers.rb,
lib/volt/server/template_handlers/preprocessors.rb,
lib/volt/page/targets/binding_document/base_node.rb,
lib/volt/page/targets/binding_document/html_node.rb,
lib/volt/server/html_parser/component_view_scope.rb,
lib/volt/server/template_handlers/view_processor.rb,
lib/volt/models/validators/numericality_validator.rb,
lib/volt/models/validators/phone_number_validator.rb,
lib/volt/server/middleware/default_middleware_stack.rb,
lib/volt/models/persistors/query/query_listener_pool.rb,
lib/volt/server/message_bus/peer_to_peer/peer_server.rb,
lib/volt/page/targets/binding_document/component_node.rb,
lib/volt/page/bindings/view_binding/controller_handler.rb,
lib/volt/page/bindings/view_binding/grouped_controllers.rb,
lib/volt/server/message_bus/peer_to_peer/server_tracker.rb,
lib/volt/page/bindings/view_binding/view_lookup_for_path.rb,
lib/volt/server/message_bus/peer_to_peer/peer_connection.rb,
lib/volt/controllers/http_controller/http_cookie_persistor.rb,
lib/volt/server/message_bus/peer_to_peer/socket_with_timeout.rb,
lib/volt/server/template_handlers/sprockets_component_handler.rb
Overview
This file Monkeypatches sprockets to provide custom file loading (from volt instead disk) for component root files. These files then require in all parts or include generated ruby for templates, routes, and tasks.
Defined Under Namespace
Modules: Associations, AttributeScope, Buffer, Bundle, ClassEventable, CollectionHelpers, CommentSearchers, Eventable, Inflector, LifecycleCallbacks, LocalStorage, LoginAsHelper, MessageBus, ModelHashBehaviour, ModelWrapper, Models, Modes, Parsing, Persistors, Query, ReactiveAccessors, RecursiveExists, Repos, ServerSetup, StateManager, StoreRootHelpers, TemplateHelpders, UserValidatorHelpers, Validations, Version Classes: App, ArrayModel, AssetFiles, AttributeBinding, AttributeSection, AttributeTarget, BaseBinding, BaseIndexRenderer, BaseNode, BaseSection, BasicHandler, Boolean, Browser, CLI, Channel, ChannelStub, ComponentBinding, ComponentCode, ComponentNode, ComponentPaths, ComponentTemplates, ComponentViewScope, Computation, Console, ContentBinding, ControllerHandler, Cursor, DataStore, DefaultMiddlewareStack, Dependency, Dispatcher, Document, DocumentEvents, DomSection, DomTarget, DomTemplate, EJSON, EachBinding, EachScope, EmailValidator, Environment, Errors, EventBinding, EventCounter, ForkingServer, FormatValidator, GenericCountingPool, GenericPool, GenericPoolDeleteException, GroupedControllers, HTMLParseError, HashDependency, HtmlNode, HttpController, HttpRequest, HttpResource, HttpResponseHeader, HttpResponseRenderer, IfBinding, IfViewScope, InclusionValidator, IndexFiles, InvalidFieldName, InvalidObjectForEachBinding, JSEvent, LengthValidator, Listener, MiddlewareStack, Model, ModelController, ModelIdentityMap, NilMethodCall, NoticesController, NumericalityValidator, OpalFiles, PathStringRenderer, PhoneNumberValidator, PresenceValidator, QueryListener, QueryListenerPool, RackServerAdaptor, ReactiveArray, ReactiveHash, RecordNotFoundException, RootModels, Routes, SandlebarsParser, Server, SocketConnectionHandler, SocketConnectionHandlerStub, SocketWithTimeout, SourceMapServer, SprocketsHelpersSetup, StatStub, StringTemplateRenderer, SubContext, Task, TaskLogger, Tasks, TemplateRenderer, Templates, TextareaScope, Timers, TypeValidator, URL, UniqueValidator, UrlTracker, User, ViewBinding, ViewHandler, ViewLookupException, ViewLookupForPath, ViewParser, ViewProcessor, ViewScope, VoltLogger, VoltLoggerFormatter, WebsocketHandler, YieldBinding
Class Attribute Summary collapse
Class Method Summary collapse
-
.as_user(user_or_id) ⇒ Object
as_user lets you run a block as another user.
- .boot(app_path) ⇒ Object
- .client? ⇒ Boolean
-
.current_app ⇒ Object
When we use something like a Task, we don’t specify an app, so we use a thread local or global to lookup the current app.
-
.current_user ⇒ Object
Return the current user.
-
.current_user? ⇒ Boolean
True if the user is logged in and the user is loaded.
-
.current_user_id ⇒ Object
Get the user_id from the cookie.
- .defaults ⇒ Object
- .env ⇒ Object
- .fetch_current_user ⇒ Object
-
.in_app ⇒ Object
Runs code in the context of this app.
- .in_browser? ⇒ Boolean
-
.login(username, password) ⇒ Object
Login the user, return a promise for success.
- .logout ⇒ Object
-
.reset_config! ⇒ Object
Resets the configuration to the default (empty hash).
- .server? ⇒ Boolean
- .setup_capybara(app_path, volt_app = nil) ⇒ Object
- .setup_capybara_app(app_path, volt_app) ⇒ Object
-
.setup_client_config(config_hash) ⇒ Object
Called on page load to pass the backend config to the client.
- .setup_sauce_labs ⇒ Object
- .skip_permissions ⇒ Object
- .source_maps? ⇒ Boolean
- .spec_setup(app_path = '.') ⇒ Object
-
.user ⇒ Object
Put in a deprecation placeholder.
-
.user_id_signature ⇒ Object
Fetches the user_id+signature from the correct spot depending on client or server, does not verify it.
-
.wrap_config(hash) ⇒ Object
Wraps the config hash in an OpenStruct so it can be accessed in the same way as the server side config.
Instance Method Summary collapse
-
#user_login_signature(user) ⇒ Object
Takes a user and returns a signed string that can be used for the user_id cookie to login a user.
Methods included from Modes
Class Attribute Details
.logger ⇒ Object
55 56 57 |
# File 'lib/volt.rb', line 55 def logger @logger ||= Volt::VoltLogger.new end |
Class Method Details
.as_user(user_or_id) ⇒ Object
as_user lets you run a block as another user
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/volt/volt/users.rb', line 43 def as_user(user_or_id) # if we have a user, get the id user_id = user_or_id.is_a?(Volt::Model) ? user_or_id.id : user_or_id previous_id = Thread.current['with_user_id'] Thread.current['with_user_id'] = user_id yield Thread.current['with_user_id'] = previous_id end |
.boot(app_path) ⇒ Object
19 20 21 22 |
# File 'lib/volt/boot.rb', line 19 def self.boot(app_path) # Boot the app App.new(app_path) end |
.current_app ⇒ Object
When we use something like a Task, we don’t specify an app, so we use a thread local or global to lookup the current app. This lets us run more than one app at once, giving deference to a global app.
68 69 70 |
# File 'lib/volt.rb', line 68 def current_app Thread.current['volt_app'] || $volt_app end |
.current_user ⇒ Object
Return the current user.
85 86 87 88 89 90 91 92 |
# File 'lib/volt/volt/users.rb', line 85 def current_user user_id = current_user_id if user_id Volt.current_app.store._users.where(id: user_id).first else Promise.new.resolve(nil) end end |
.current_user? ⇒ Boolean
True if the user is logged in and the user is loaded
78 79 80 81 82 |
# File 'lib/volt/volt/users.rb', line 78 def current_user? current_user.then do |user| !!user end end |
.current_user_id ⇒ Object
Get the user_id from the cookie
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/volt/volt/users.rb', line 6 def current_user_id # Check for a user_id from with_user if (user_id = Thread.current['with_user_id']) return user_id end user_id_signature = self.user_id_signature if user_id_signature.nil? nil else index = user_id_signature.index(':') # If no index, the cookie is invalid return nil unless index user_id = user_id_signature[0...index] if RUBY_PLATFORM != 'opal' hash = user_id_signature[(index + 1)..-1] # Make sure the user hash matches # TODO: We could cache the digest generation for even faster comparisons if hash != Digest::SHA256.hexdigest("#{Volt.config.app_secret}::#{user_id}") # user id has been tampered with, reject fail VoltUserError, 'user id or hash is incorrectly signed. It may have been tampered with, the app secret changed, or generated in a different app.' end end user_id end end |
.defaults ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/volt/config.rb', line 49 def defaults app_name = File.basename(Dir.pwd) opts = { app_name: app_name, db_name: (ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s)).gsub('.', '_'), db_host: ENV['DB_HOST'] || 'localhost', db_port: (ENV['DB_PORT'] || 27_017).to_i, db_driver: ENV['DB_DRIVER'] || 'mongo', # a list of components which should be included in all components default_components: ['volt'], compress_javascript: Volt.env.production?, compress_css: Volt.env.production?, compress_images: Volt.env.production?, abort_on_exception: true, min_worker_threads: 1, max_worker_threads: 10, worker_timeout: 60 } opts[:db_uri] = ENV['DB_URI'] if ENV['DB_URI'] opts end |
.env ⇒ Object
51 52 53 |
# File 'lib/volt.rb', line 51 def env @env ||= Volt::Environment.new end |
.fetch_current_user ⇒ Object
100 101 102 103 |
# File 'lib/volt/volt/users.rb', line 100 def fetch_current_user Volt.logger.warn("Deprecation Warning: fetch current user have been depricated, Volt.current_user returns a promise now.") current_user end |
.in_app ⇒ Object
Runs code in the context of this app.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/volt.rb', line 73 def in_app previous_app = Thread.current['volt_app'] Thread.current['volt_app'] = self begin yield ensure Thread.current['volt_app'] = previous_app end end |
.login(username, password) ⇒ Object
Login the user, return a promise for success
106 107 108 109 110 111 112 113 114 |
# File 'lib/volt/volt/users.rb', line 106 def login(username, password) UserTasks.login(login: username, password: password).then do |result| # Assign the user_id cookie for the user Volt.current_app.._user_id = result # Pass nil back nil end end |
.logout ⇒ Object
116 117 118 |
# File 'lib/volt/volt/users.rb', line 116 def logout Volt.current_app..delete(:user_id) end |
.reset_config! ⇒ Object
Resets the configuration to the default (empty hash)
77 78 79 80 81 |
# File 'lib/volt/config.rb', line 77 def reset_config! configure do |c| c.from_h(defaults) end end |
.setup_capybara(app_path, volt_app = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/volt/spec/capybara.rb', line 5 def (app_path, volt_app = nil) browser = ENV['BROWSER'] if browser (app_path, volt_app) case browser when 'phantom' Capybara.default_driver = :poltergeist when 'chrome', 'safari' # Use the browser name, note that safari requires an extension to run browser = browser.to_sym Capybara.register_driver(browser) do |app| Capybara::Selenium::Driver.new(app, browser: browser) end Capybara.default_driver = browser when 'firefox' Capybara.default_driver = :selenium when 'sauce' setup_sauce_labs end end end |
.setup_capybara_app(app_path, volt_app) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/volt/spec/capybara.rb', line 30 def (app_path, volt_app) require 'capybara' require 'capybara/dsl' require 'capybara/rspec' require 'capybara/poltergeist' require 'selenium-webdriver' require 'volt/server' case RUNNING_SERVER when 'thin' Capybara.server do |app, port| require 'rack/handler/thin' Rack::Handler::Thin.run(app, Port: port) end when 'puma' Capybara.server do |app, port| Puma::Server.new(app).tap do |s| s.add_tcp_listener Capybara.server_host, port end.run.join end end # Setup server, use existing booted app Capybara.app = Server.new(app_path, volt_app).app end |
.setup_client_config(config_hash) ⇒ Object
Called on page load to pass the backend config to the client
21 22 23 24 |
# File 'lib/volt/config.rb', line 21 def setup_client_config(config_hash) # Only Volt.config.public is passed from the server (for security reasons) @config = wrap_config(public: config_hash) end |
.setup_sauce_labs ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/volt/spec/sauce_labs.rb', line 3 def setup_sauce_labs require 'sauce' require 'sauce/capybara' Sauce.config do |c| if ENV['OS'] # Use a specifc OS, BROWSER, VERSION combo (for travis) c[:browsers] = [ [ENV['OS'], ENV['USE_BROWSER'], ENV['VERSION']] ] else # Run all c[:browsers] = [ # ["Windows 7", "Chrome", "30"], # ["Windows 8", "Firefox", "28"], ['Windows 8.1', 'Internet Explorer', '11'], ['Windows 8.0', 'Internet Explorer', '10'], ['Windows 7.0', 'Internet Explorer', '9'], # ["OSX 10.9", "iPhone", "8.1"], # ["OSX 10.8", "Safari", "6"], # ["Linux", "Chrome", "26"] ] end c[:start_local_application] = false end Capybara.default_driver = :sauce Capybara.javascript_driver = :sauce end |
.skip_permissions ⇒ Object
71 72 73 74 75 |
# File 'lib/volt/volt/users.rb', line 71 def Volt.run_in_mode(:skip_permissions) do yield end end |
.source_maps? ⇒ Boolean
42 43 44 45 46 47 48 49 |
# File 'lib/volt.rb', line 42 def source_maps? if !ENV['MAPS'] # If no MAPS is specified, enable it in dev Volt.env.development? else ENV['MAPS'] != 'false' end end |
.spec_setup(app_path = '.') ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/volt/spec/setup.rb', line 5 def spec_setup(app_path = '.') require 'volt' ENV['SERVER'] = 'true' ENV['VOLT_ENV'] = 'test' require 'volt/boot' # Create a main volt app for tests volt_app = Volt.boot(app_path) unless RUBY_PLATFORM == 'opal' begin require 'volt/spec/capybara' (app_path, volt_app) rescue LoadError => e Volt.logger.warn("unable to load capybara, if you wish to use it for tests, be sure it is in the app's Gemfile") Volt.logger.error(e) end end unless ENV['BROWSER'] # Not running integration tests with ENV['BROWSER'] RSpec.configuration.filter_run_excluding type: :feature end cleanup_db = -> do volt_app.database.drop_database # Clear cached for a reset volt_app.instance_variable_set('@store', nil) volt_app.reset_query_pool! end if RUBY_PLATFORM != 'opal' # Call once during setup to clear if we killed the last run cleanup_db.call end # Run everything in the context of this app Thread.current['volt_app'] = volt_app # Setup the spec collection accessors # RSpec.shared_context "volt collections", {} do RSpec.shared_context 'volt collections', {} do # Page conflicts with capybara's page method, so we call it the_page for now. # TODO: we need a better solution for page let(:the_page) { Model.new } let(:store) do @__store_accessed = true volt_app.store end let(:volt_app) { volt_app } let(:params) { volt_app.params } after do # Clear params if used url = volt_app.url if url.instance_variable_get('@params') url.instance_variable_set('@params', nil) end end if RUBY_PLATFORM != 'opal' after do |example| if @__store_accessed || example.[:type] == :feature # Clear the database after each spec where we use store cleanup_db.call end end # Cleanup after integration tests also. before(:example, {type: :feature}) do @__store_accessed = true end end end end |
.user ⇒ Object
Put in a deprecation placeholder
95 96 97 98 |
# File 'lib/volt/volt/users.rb', line 95 def user Volt.logger.warn('Deprecation: Volt.user has been renamed to Volt.current_user (to be more clear about what it returns). Volt.user will be deprecated in the future.') current_user end |
.user_id_signature ⇒ Object
Fetches the user_id+signature from the correct spot depending on client or server, does not verify it.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/volt/volt/users.rb', line 122 def user_id_signature if Volt.client? user_id_signature = Volt.current_app.._user_id else # Check meta for the user id and validate it = Thread.current['meta'] if user_id_signature = ['user_id'] else user_id_signature = nil end end user_id_signature end |
.wrap_config(hash) ⇒ Object
Wraps the config hash in an OpenStruct so it can be accessed in the same way as the server side config.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/volt/config.rb', line 28 def wrap_config(hash) new_hash = {} hash.each_pair do |key, value| if value.is_a?(Hash) new_hash[key] = wrap_config(value) else new_hash[key] = value end end OpenStruct.new(new_hash) end |
Instance Method Details
#user_login_signature(user) ⇒ Object
Takes a user and returns a signed string that can be used for the user_id cookie to login a user.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/volt/volt/users.rb', line 58 def user_login_signature(user) fail 'app_secret is not configured' unless Volt.config.app_secret # TODO: returning here should be possible, but causes some issues # Salt the user id with the app_secret so the end user can't # tamper with the cookie signature = Digest::SHA256.hexdigest(salty_user_id(user.id)) # Return user_id:hash on user id "#{user.id}:#{signature}" end |