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
|
||||
if message == ''
|
||||
|
||||
# remember last login
|
||||
userdata.update_last_login
|
||||
|
||||
# set basic auth user to current user
|
||||
current_user_set(userdata)
|
||||
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"
|
||||
def create
|
||||
|
||||
# authenticate user
|
||||
user = User.authenticate( params[:username], params[:password] )
|
||||
|
||||
# auth failed
|
||||
|
@ -13,9 +14,12 @@ class SessionsController < ApplicationController
|
|||
render :json => { :error => 'login failed' }, :status => :unprocessable_entity
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
# remember last login date
|
||||
user.update_last_login()
|
||||
|
||||
user = User.find_fulldata(user.id)
|
||||
|
||||
|
||||
# auto population of default collections
|
||||
default_collection = default_collections()
|
||||
|
||||
|
@ -118,21 +122,21 @@ class SessionsController < ApplicationController
|
|||
authorization = Authorization.create_from_hash(auth, current_user)
|
||||
end
|
||||
|
||||
# remember last login date
|
||||
authorization.user.update_last_login()
|
||||
|
||||
# Log the authorizing user in.
|
||||
session[:user_id] = authorization.user.id
|
||||
|
||||
# redirect to app
|
||||
redirect_to '/app#'
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def default_collections
|
||||
|
||||
# auto population of default collections
|
||||
# auto population collections, store all here
|
||||
default_collection = {}
|
||||
default_collection['Role'] = Role.all
|
||||
default_collection['Group'] = Group.all
|
||||
default_collection['Organization'] = Organization.all
|
||||
|
||||
# load collections to deliver from external files
|
||||
dir = File.expand_path('../', __FILE__)
|
||||
|
@ -142,6 +146,6 @@ class SessionsController < ApplicationController
|
|||
ExtraCollection.add(default_collection)
|
||||
end
|
||||
|
||||
return default_collection
|
||||
return default_collection
|
||||
end
|
||||
end
|
|
@ -88,7 +88,7 @@ class User < ApplicationModel
|
|||
|
||||
# try to find user based on login
|
||||
user = User.where( :login => username, :active => true ).first
|
||||
|
||||
|
||||
# try second lookup with email
|
||||
if !user
|
||||
user = User.where( :email => username, :active => true ).first
|
||||
|
@ -292,6 +292,11 @@ Your #{config.product_name} Team
|
|||
end
|
||||
end
|
||||
|
||||
def update_last_login
|
||||
self.last_login = Time.now
|
||||
self.save
|
||||
end
|
||||
|
||||
private
|
||||
def check_geo
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class CreateBase < ActiveRecord::Migration
|
|||
t.column :verified, :boolean, :null => false, :default => false
|
||||
t.column :active, :boolean, :null => false, :default => 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 :preferences, :string, :limit => 4000,:null => true
|
||||
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