Skip to content

Commit

Permalink
Merge pull request #326 from scouttyg/kandan-270
Browse files Browse the repository at this point in the history
Fixed current user list not being updated when user logs in
  • Loading branch information
fusion94 committed Apr 10, 2014
2 parents 031f79f + 8558eb5 commit ef27c8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/models/user.rb
Expand Up @@ -9,6 +9,8 @@ class User < ActiveRecord::Base

has_many :activities
before_save :ensure_gravatar_hash
before_save :ensure_authentication_token

before_create :mark_registration_status_depending_on_app_settings

after_create :ensure_at_least_one_admin
Expand Down Expand Up @@ -41,6 +43,12 @@ def ensure_gravatar_hash
self.gravatar_hash = Digest::MD5.hexdigest self.email
end

def ensure_authentication_token
if self.authentication_token.blank?
self.authentication_token = generate_authentication_token
end
end

# We never want an app without an admin so let's ensure there is at least one user
def ensure_at_least_one_admin
if User.count == 1
Expand Down Expand Up @@ -120,4 +128,12 @@ def check_external_avatar
end
end

private
def generate_authentication_token
loop do
token = Devise.friendly_token
break token unless User.where(authentication_token: token).first
end
end

end
7 changes: 7 additions & 0 deletions db/migrate/20140409193213_fix_authentication_tokens.rb
@@ -0,0 +1,7 @@
class FixAuthenticationTokens < ActiveRecord::Migration
def change
User.all.each do |user|
user.save!
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130623202749) do
ActiveRecord::Schema.define(:version => 20140409193213) do

create_table "activities", :force => true do |t|
t.text "content"
Expand Down

0 comments on commit ef27c8f

Please sign in to comment.