orbit-basic/app/controllers/panel/users_controller.rb

71 lines
1.8 KiB
Ruby
Raw Normal View History

class Panel::UsersController < ApplicationController
layout "panel"
before_filter :authenticate_user!
def index
@users = User.all.entries
end
def show
@user = User.find(params[:id])
2011-02-01 07:12:23 +00:00
@user_info_models = UserInfoModel.all.entries
end
def new
@user = User.new
2011-02-01 07:12:23 +00:00
@user_info_models = UserInfoModel.all.entries
2011-02-01 02:46:26 +00:00
@user_role_models = UserRoleModel.all.entries
session[:last_page] = get_go_back || panel_users_url
end
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = t('panel.create_success_user')
redirect_to :action => :index
else
render :action => :new
end
end
def edit
@user = User.find(params[:id])
2011-02-01 07:12:23 +00:00
@user_info_models = UserInfoModel.all.entries
2011-02-01 02:46:26 +00:00
@user_role_models = UserRoleModel.all.entries
session[:last_page] = get_go_back || panel_users_url
end
def update
@user = User.find(params[:id])
# Update changes to the avatar
@user.remove_avatar! if params[:file]
@user.avatar = params[:file] if params[:file]
2011-02-08 06:51:49 +00:00
if @user.id.to_s.eql?(session['warden.user.user.key'][1].to_s) && @user.admin != params[:user][:admin].to_i.to_b
flash.now[:error] = t('panel.cant_revoke_self_admin')
end
if !flash[:error] && @user.update_attributes(params[:user])
flash[:notice] = t('panel.update_success_user')
redirect_to :action => :index
else
2011-02-01 07:12:23 +00:00
@user_info_models = UserInfoModel.all.entries
2011-02-01 02:46:26 +00:00
@user_role_models = UserRoleModel.all.entries
render :action => :edit
end
end
def destroy
if params[:id].eql?(session['warden.user.user.key'][1].to_s)
flash[:error] = t('panel.cant_delete_self')
else
@user = User.find(params[:id])
@user.destroy
end
redirect_to :action => :index
end
end