Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added user timezone setting (defaults to Brisbane). #121

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ApplicationController < ActionController::Base
layout :api_or_html

before_filter :authenticate_user!

# CanCan - always check authorization
check_authorization unless: :devise_controller?

Expand Down Expand Up @@ -36,6 +38,8 @@ class ApplicationController < ActionController::Base

after_filter :set_csrf_cookie_for_ng, :resource_representation_caching_fixes

before_filter :set_user_time_zone

# set and reset user stamper for each request
# based on https://github.com/theepan/userstamp/tree/bf05d832ee27a717ea9455d685c83ae2cfb80310
around_filter :set_then_reset_user_stamper
Expand Down Expand Up @@ -411,4 +415,8 @@ def set_then_reset_user_stamper
end
end

def set_user_time_zone
Time.zone = current_user.time_zone_name if user_signed_in?
end

end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class User < ActiveRecord::Base

attr_accessible :user_name, :email, :password, :password_confirmation, :remember_me,
:roles, :roles_mask, :preferences,
:image, :login
:image, :login, :time_zone_name

# Virtual attribute for authenticating by either :user_name or :email
# This is in addition to real persisted fields.
Expand Down
1 change: 1 addition & 0 deletions app/views/devise/registrations/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
= f.input :user_name, required: true, autofocus: true
= f.input :password, required: true
= f.input :password_confirmation, required: true
= f.time_zone_select :time_zone_name, /Australia/, default: 'Brisbane', required: true
= f.input :email, required: true
.form-actions
= f.button :submit, 'Sign up'
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Application < Rails::Application
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
#config.time_zone - 'UTC'
# used as default when user is not logged in
# for detecting user daylight savings time, see http://stackoverflow.com/a/11888430/31567
config.time_zone = 'Brisbane'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140906231545_add_time_zone_name_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTimeZoneNameToUser < ActiveRecord::Migration
def change
add_column :users, :time_zone_name, :string, null:false, default: 'Brisbane'
end
end