Added last login feature.
This commit is contained in:
parent
62edaa6119
commit
5bf96897e2
6 changed files with 41 additions and 9 deletions
|
@ -84,6 +84,9 @@ class ApplicationController < ActionController::Base
|
||||||
# return auth ok
|
# return auth ok
|
||||||
if message == ''
|
if message == ''
|
||||||
|
|
||||||
|
# remember last login
|
||||||
|
userdata.update_last_login
|
||||||
|
|
||||||
# set basic auth user to current user
|
# set basic auth user to current user
|
||||||
current_user_set(userdata)
|
current_user_set(userdata)
|
||||||
return {
|
return {
|
||||||
|
|
11
app/controllers/sessions/collection_base.rb
Normal file
11
app/controllers/sessions/collection_base.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module ExtraCollection
|
||||||
|
def add(collections)
|
||||||
|
|
||||||
|
# all base stuff
|
||||||
|
collections['Role'] = Role.all
|
||||||
|
collections['Group'] = Group.all
|
||||||
|
collections['Organization'] = Organization.all
|
||||||
|
|
||||||
|
end
|
||||||
|
module_function :add
|
||||||
|
end
|
|
@ -6,6 +6,7 @@ class SessionsController < ApplicationController
|
||||||
# "Create" a login, aka "log the user in"
|
# "Create" a login, aka "log the user in"
|
||||||
def create
|
def create
|
||||||
|
|
||||||
|
# authenticate user
|
||||||
user = User.authenticate( params[:username], params[:password] )
|
user = User.authenticate( params[:username], params[:password] )
|
||||||
|
|
||||||
# auth failed
|
# auth failed
|
||||||
|
@ -14,6 +15,9 @@ class SessionsController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# remember last login date
|
||||||
|
user.update_last_login()
|
||||||
|
|
||||||
user = User.find_fulldata(user.id)
|
user = User.find_fulldata(user.id)
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population of default collections
|
||||||
|
@ -118,6 +122,9 @@ class SessionsController < ApplicationController
|
||||||
authorization = Authorization.create_from_hash(auth, current_user)
|
authorization = Authorization.create_from_hash(auth, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# remember last login date
|
||||||
|
authorization.user.update_last_login()
|
||||||
|
|
||||||
# Log the authorizing user in.
|
# Log the authorizing user in.
|
||||||
session[:user_id] = authorization.user.id
|
session[:user_id] = authorization.user.id
|
||||||
|
|
||||||
|
@ -128,11 +135,8 @@ class SessionsController < ApplicationController
|
||||||
private
|
private
|
||||||
def default_collections
|
def default_collections
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population collections, store all here
|
||||||
default_collection = {}
|
default_collection = {}
|
||||||
default_collection['Role'] = Role.all
|
|
||||||
default_collection['Group'] = Group.all
|
|
||||||
default_collection['Organization'] = Organization.all
|
|
||||||
|
|
||||||
# load collections to deliver from external files
|
# load collections to deliver from external files
|
||||||
dir = File.expand_path('../', __FILE__)
|
dir = File.expand_path('../', __FILE__)
|
||||||
|
|
|
@ -292,6 +292,11 @@ Your #{config.product_name} Team
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_last_login
|
||||||
|
self.last_login = Time.now
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_geo
|
def check_geo
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ class CreateBase < ActiveRecord::Migration
|
||||||
t.column :verified, :boolean, :null => false, :default => false
|
t.column :verified, :boolean, :null => false, :default => false
|
||||||
t.column :active, :boolean, :null => false, :default => true
|
t.column :active, :boolean, :null => false, :default => true
|
||||||
t.column :note, :string, :limit => 250, :null => true
|
t.column :note, :string, :limit => 250, :null => true
|
||||||
|
t.column :last_login, :timestamp, :null => true
|
||||||
t.column :source, :string, :limit => 200, :null => true
|
t.column :source, :string, :limit => 200, :null => true
|
||||||
t.column :preferences, :string, :limit => 4000,:null => true
|
t.column :preferences, :string, :limit => 4000,:null => true
|
||||||
t.column :updated_by_id, :integer, :null => false
|
t.column :updated_by_id, :integer, :null => false
|
||||||
|
|
8
db/migrate/20121018074741_users_update.rb
Normal file
8
db/migrate/20121018074741_users_update.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class UsersUpdate < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :users, :last_login, :timestamp, :null => true
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue