Commit fbf69899032ffd5e74e401aae7c94852a0722e92

Authored by Dmitriy Zaporozhets
1 parent 94be7320

Force admin to change password after first sign-in

app/controllers/application_controller.rb
... ... @@ -159,7 +159,7 @@ class ApplicationController < ActionController::Base
159 159 end
160 160  
161 161 def check_password_expiration
162   - if current_user.password_expires_at && current_user.password_expires_at < Time.now
  162 + if current_user && current_user.password_expires_at && current_user.password_expires_at < Time.now
163 163 redirect_to new_profile_password_path and return
164 164 end
165 165 end
... ...
app/models/user.rb
... ... @@ -42,8 +42,11 @@ class User &lt; ActiveRecord::Base
42 42  
43 43 attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username,
44 44 :skype, :linkedin, :twitter, :color_scheme_id, :theme_id, :force_random_password,
45   - :extern_uid, :provider, as: [:default, :admin]
46   - attr_accessible :projects_limit, :can_create_team, :can_create_group, as: :admin
  45 + :extern_uid, :provider, :password_expires_at,
  46 + as: [:default, :admin]
  47 +
  48 + attr_accessible :projects_limit, :can_create_team, :can_create_group,
  49 + as: :admin
47 50  
48 51 attr_accessor :force_random_password
49 52  
... ...
db/fixtures/production/001_admin.rb
... ... @@ -3,7 +3,8 @@ admin = User.create(
3 3 name: "Administrator",
4 4 username: 'root',
5 5 password: "5iveL!fe",
6   - password_confirmation: "5iveL!fe"
  6 + password_confirmation: "5iveL!fe",
  7 + password_expires_at: Time.now
7 8 )
8 9  
9 10 admin.projects_limit = 10000
... ...