Class: CamaleonCms::Admin::UsersController

Inherits:
CamaleonCms::AdminController
  • Object
show all
Defined in:
app/controllers/camaleon_cms/admin/users_controller.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Instance Method Details

#createObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 73

def create
  user_data = params[:user]
  @user = current_site.users.new(user_data)
  if @user.save
    @user.set_metas(params[:meta]) if params[:meta].present?
    @user.set_field_values(params[:field_options])
    r={user: @user}; hooks_run('user_created', r)
    flash[:notice] = t('camaleon_cms.admin.users.message.created')
    redirect_to action: :index
  else
    new
  end
end

#destroyObject



87
88
89
90
91
92
93
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 87

def destroy
  if @user.destroy
    flash[:notice] = t('camaleon_cms.admin.users.message.deleted')
    r={user: @user}; hooks_run('user_destroyed', r)
  end
  redirect_to action: :index
end

#editObject



58
59
60
61
62
63
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 58

def edit
  add_breadcrumb I18n.t("camaleon_cms.admin.button.edit")
  r = {user: @user, render: 'form' }
  hooks_run('user_edit', r)
  render r[:render]
end

#indexObject



14
15
16
17
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 14

def index
  add_breadcrumb I18n.t("camaleon_cms.admin.users.list_users")
  @users = current_site.users.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
end

#newObject



65
66
67
68
69
70
71
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 65

def new
  @user ||= current_site.users.new
  add_breadcrumb I18n.t("camaleon_cms.admin.button.new")
  r = {user: @user, render: 'form' }
  hooks_run('user_new', r)
  render r[:render]
end

#profileObject



19
20
21
22
23
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 19

def profile
  add_breadcrumb I18n.t("camaleon_cms.admin.users.profile")
  @user = params[:user_id].present? ? current_site.the_user(params[:user_id].to_i).object : cama_current_user.object
  return edit
end

#profile_editObject



25
26
27
28
29
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 25

def profile_edit
  add_breadcrumb I18n.t("camaleon_cms.admin.users.profile")
  @user = cama_current_user.object
  return edit
end

#showObject



31
32
33
34
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 31

def show
  add_breadcrumb I18n.t("camaleon_cms.admin.users.profile")
  render 'profile'
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 36

def update
  if @user.update(params[:user])
    @user.set_metas(params[:meta]) if params[:meta].present?
    @user.set_field_values(params[:field_options])
    r = {user: @user, message: t('camaleon_cms.admin.users.message.updated'), params: params}; hooks_run('user_after_edited', r)
    flash[:notice] = r[:message]
    if cama_current_user.id == @user.id
      redirect_to action: :profile_edit
    else
      redirect_to action: :index
    end
  else
    render 'form'
  end
end

#updated_ajaxObject

update som ajax requests from profile or user form



53
54
55
56
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 53

def updated_ajax
  @user = current_site.users.find(params[:user_id])
  render inline: @user.update(params[:password]) ? "" : @user.errors.full_messages.join(', ')
end