foreman/app/controllers/users_controller.rb @ b4b12197
1ba05a93 | Ohad Levy | class UsersController < ApplicationController
|
|
4a8190ef | Ohad Levy | include Foreman::Controller::AutoCompleteSearch
|
|
355bce36 | Ohad Levy | include Foreman::Controller::UsersMixin
|
|
1ba05a93 | Ohad Levy | ||
355bce36 | Ohad Levy | before_filter :find_resource, :only => [:edit, :update, :destroy]
|
|
306ed25a | rbirnie | skip_before_filter :require_mail, :only => [:edit, :update, :logout]
|
|
b7589c32 | Jan Pazdziora | skip_before_filter :require_login, :authorize, :session_expiry, :update_activity_time, :set_taxonomy, :set_gettext_locale_db, :only => [:login, :logout, :extlogout]
|
|
skip_before_filter :authorize, :only => :extlogin
|
|||
d9a2ebac | Ohad Levy | after_filter :update_activity_time, :only => :login
|
|
1ba05a93 | Ohad Levy | ||
6874bbd9 | Paul Kelly | def index
|
|
4a8190ef | Ohad Levy | begin
|
|
users = User.search_for(params[:search], :order => params[:order])
|
|||
rescue => e
|
|||
error e.to_s
|
|||
f2c78d4a | Joseph Magen | users = User.search_for('', :order => params[:order])
|
|
4a8190ef | Ohad Levy | end
|
|
f2c78d4a | Joseph Magen | @users = users.includes(:auth_source).paginate(:page => params[:page])
|
|
6874bbd9 | Paul Kelly | end
|
|
def new
|
|||
@user = User.new
|
|||
end
|
|||
def create
|
|||
if @user.save
|
|||
b28fdce4 | Ohad Levy | process_success
|
|
6874bbd9 | Paul Kelly | else
|
|
b28fdce4 | Ohad Levy | process_error
|
|
6874bbd9 | Paul Kelly | end
|
|
end
|
|||
def edit
|
|||
355bce36 | Ohad Levy | editing_self?
|
|
9fd7478e | Paul Kelly | if @user.user_facts.count == 0
|
|
user_fact = @user.user_facts.build :operator => "==", :andor => "or"
|
|||
5d264a2d | Ohad Levy | user_fact.fact_name_id = FactName.first.id if FactName.first
|
|
9fd7478e | Paul Kelly | end
|
|
6874bbd9 | Paul Kelly | end
|
|
def update
|
|||
if @user.update_attributes(params[:user])
|
|||
355bce36 | Ohad Levy | update_sub_hostgroups_owners
|
|
process_success((editing_self? && !current_user.allowed_to?({:controller => 'users', :action => 'index'})) ? { :success_redirect => hosts_path } : {})
|
|||
6874bbd9 | Paul Kelly | else
|
|
b28fdce4 | Ohad Levy | process_error
|
|
6874bbd9 | Paul Kelly | end
|
|
end
|
|||
def destroy
|
|||
8ba2e00a | Ohad Levy | if @user == User.current
|
|
ab7baec6 | Bryan Kearney | notice _("You are currently logged in, suicidal?")
|
|
7a4ec5cf | Paul Kelly | redirect_to :back and return
|
|
end
|
|||
8ba2e00a | Ohad Levy | if @user.destroy
|
|
b28fdce4 | Ohad Levy | process_success
|
|
6874bbd9 | Paul Kelly | else
|
|
b28fdce4 | Ohad Levy | process_error
|
|
6874bbd9 | Paul Kelly | end
|
|
end
|
|||
1ba05a93 | Ohad Levy | ||
7a4ec5cf | Paul Kelly | # Called from the login form.
|
|
f5df7d44 | Paul Kelly | # Stores the user id in the session and redirects required URL or default homepage
|
|
1ba05a93 | Ohad Levy | def login
|
|
7e64f911 | Ohad Levy | session[:user] = User.current = nil
|
|
e2c2abfe | Lukas Zapletal | session[:locale] = nil
|
|
1ba05a93 | Ohad Levy | if request.post?
|
|
4e7ea9b8 | Marek Hulan | user = User.try_to_login(params[:login]['login'].downcase, params[:login]['password'])
|
|
1ba05a93 | Ohad Levy | if user.nil?
|
|
#failed to authenticate, and/or to generate the account on the fly
|
|||
69be1641 | Bryan Kearney | error _("Incorrect username or password")
|
|
6874bbd9 | Paul Kelly | redirect_to login_users_path
|
|
1ba05a93 | Ohad Levy | else
|
|
#valid user
|
|||
4e7ea9b8 | Marek Hulan | login_user(user)
|
|
1ba05a93 | Ohad Levy | end
|
|
8ee46221 | Amos Benari | else
|
|
1245d238 | Ohad Levy | render :layout => 'login'
|
|
1ba05a93 | Ohad Levy | end
|
|
end
|
|||
b7589c32 | Jan Pazdziora | ||
def extlogin
|
|||
if session[:user]
|
|||
user = User.find_by_id(session[:user])
|
|||
login_user(user)
|
|||
end
|
|||
end
|
|||
1ba05a93 | Ohad Levy | # Called from the logout link
|
|
# Clears the rails session and redirects to the login action
|
|||
def logout
|
|||
f4430a08 | Tomas Strachota | TopbarSweeper.expire_cache(self)
|
|
6c563741 | Marek Hulan | sso_logout_path = get_sso_method.try(:logout_url)
|
|
9fd7478e | Paul Kelly | session[:user] = @user = User.current = nil
|
|
754b1a01 | Ohad Levy | if flash[:notice] or flash[:error]
|
|
1ba05a93 | Ohad Levy | flash.keep
|
|
else
|
|||
9fd7478e | Paul Kelly | session.clear
|
|
69be1641 | Bryan Kearney | notice _("Logged out - See you soon")
|
|
1ba05a93 | Ohad Levy | end
|
|
6c563741 | Marek Hulan | redirect_to sso_logout_path || login_users_path
|
|
1ba05a93 | Ohad Levy | end
|
|
b4b12197 | Lukas Zapletal | def extlogout
|
|
render :extlogout, :layout => 'login'
|
|||
end
|
|||
9fd7478e | Paul Kelly | private
|
|
22d5c68d | Amos Benari | ||
355bce36 | Ohad Levy | def find_resource
|
|
@user ||= User.find(params[:id])
|
|||
16ce9a7a | Daniel Lobato | end
|
|
4e7ea9b8 | Marek Hulan | def login_user(user)
|
|
session[:user] = user.id
|
|||
uri = session[:original_uri]
|
|||
session[:original_uri] = nil
|
|||
redirect_to (uri || hosts_path)
|
|||
end
|
|||
1ba05a93 | Ohad Levy | end
|