Class: CamaleonCms::Admin::UsersController
- Inherits:
-
CamaleonCms::AdminController
- Object
- ApplicationController
- CamaleonController
- CamaleonCms::AdminController
- CamaleonCms::Admin::UsersController
- Defined in:
- app/controllers/camaleon_cms/admin/users_controller.rb
Constant Summary
Constants included from UploaderHelper
UploaderHelper::SUSPICIOUS_PATTERNS
Instance Method Summary collapse
- #create ⇒ Object
- #current_user_is?(user) ⇒ Boolean
- #destroy ⇒ Object
- #edit ⇒ Object
- #impersonate ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #profile ⇒ Object
- #profile_edit ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_auth_token_in_cookie(token) ⇒ Object
-
#updated_ajax ⇒ Object
update some ajax requests from profile or user form.
Methods inherited from CamaleonCms::AdminController
Methods included from ApplicationHelper
#cama_do_pagination, #cama_get_i18n_frontend, #cama_shortcode_print
Methods included from CustomFieldsHelper
#cama_custom_field_elements, #cf_add_model
Methods included from CategoryHelper
#cama_category_get_options_html
Methods included from PostTypeHelper
#cama_hierarchy_post_list, #post_type_html_inputs, #post_type_list_taxonomy, #post_type_status
Methods included from MenusHelper
#admin_menu_add_menu, #admin_menu_append_menu_item, #admin_menu_draw, #admin_menu_insert_menu_after, #admin_menu_insert_menu_before, #admin_menu_prepend_menu_item, #admin_menus_add_commons
Methods included from BreadcrumbHelper
#admin_breadcrumb_add, #cama_admin_title_draw
Methods inherited from CamaleonController
Methods included from EmailHelper
#cama_send_email, #cama_send_mail_to_admin, #send_email, #send_password_reset_email, #send_user_confirm_email
Methods included from HooksHelper
#hook_run, #hook_skip, #hooks_run
Methods included from PluginsHelper
#current_plugin, #plugin_asset_path, #plugin_asset_url, #plugin_destroy, #plugin_install, #plugin_layout, #plugin_load_helpers, #plugin_uninstall, #plugin_upgrade, #plugin_view, #plugins_initialize, #self_plugin_key
Methods included from SiteHelper
#cama_current_site_host_port, #cama_get_list_layouts_files, #cama_get_list_template_files, #cama_is_test_request?, #current_locale, #current_site, #current_theme, #site_after_install, #site_install_theme, #site_uninstall_theme
Methods included from UploaderHelper
#cama_crop_image, #cama_file_path_to_url, #cama_resize_and_crop, #cama_resize_upload, #cama_tmp_upload, #cama_uploader, #cama_uploader_generate_thumbnail, #cama_url_to_file_path, #slugify, #slugify_folder, #upload_file, #uploader_verify_name
Methods included from CamaleonHelper
#cama_cache_fetch, #cama_draw_timer, #cama_edit_link, #cama_is_admin_request?, #cama_pluralize_text, #cama_requestAction, #cama_sitemap_cats_generator, #cama_t, #ct
Methods included from CaptchaHelper
#cama_captcha_build, #cama_captcha_increment_attack, #cama_captcha_reset_attack, #cama_captcha_tag, #cama_captcha_tags_if_under_attack, #cama_captcha_total_attacks, #cama_captcha_under_attack?, #cama_captcha_verified?, #captcha_verify_if_under_attack
Methods included from ContentHelper
#cama_content_after_draw, #cama_content_append, #cama_content_before_draw, #cama_content_init, #cama_content_prepend
Methods included from ThemeHelper
#self_theme_key, #theme_asset_file_path, #theme_asset_path, #theme_asset_url, #theme_home_page, #theme_init, #theme_layout, #theme_view
Methods included from ShortCodeHelper
#cama_strip_shortcodes, #do_shortcode, #render_shortcode, #shortcode_add, #shortcode_change_template, #shortcode_delete, #shortcodes_init
Methods included from UserRolesHelper
Methods included from HtmlHelper
#append_asset_content, #append_asset_libraries, #append_pre_asset_content, #cama_assets_library_register, #cama_draw_custom_assets, #cama_draw_pre_asset_contents, #cama_get_options_html_from_items, #cama_html_helpers_init, #cama_html_tooltip, #cama_load_libraries
Methods included from SessionHelper
#cama_authenticate, #cama_current_role, #cama_current_user, #cama_get_session_id, #cama_logout_user, #cama_on_heroku?, #cama_register_user, #cama_sign_in?, #cookie_auth_token_complete?, #cookie_split_auth_token, #login_user, #login_user_with_password, #session_back_to_parent, #session_switch_user, #user_auth_token_from_cookie
Instance Method Details
#create ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 90 def create user_data = params.require(:user).permit! @user = current_site.users.new(user_data) r = { user: @user } hooks_run('user_create', r) if @user.save @user.(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 |
#current_user_is?(user) ⇒ Boolean
69 70 71 72 73 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 69 def current_user_is?(user) == user.auth_token rescue StandardError false end |
#destroy ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 107 def destroy if cama_current_user.id == @user.id flash[:error] = t('camaleon_cms.admin.users.message.user_can_not_delete_own_account', default: 'User can not delete own account') elsif @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 |
#edit ⇒ Object
75 76 77 78 79 80 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 75 def edit I18n.t('camaleon_cms.admin.button.edit') r = { user: @user, render: 'form' } hooks_run('user_edit', r) render r[:render] end |
#impersonate ⇒ Object
120 121 122 123 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 120 def impersonate :impersonate, @user session_switch_user(@user, cama_admin_dashboard_path) end |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 8 def index I18n.t('camaleon_cms.admin.users.list_users') @users = current_site.users.paginate(page: params[:page], per_page: current_site.admin_per_page) end |
#new ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 82 def new @user ||= current_site.users.new I18n.t('camaleon_cms.admin.button.new') r = { user: @user, render: 'form' } hooks_run('user_new', r) render r[:render] end |
#profile ⇒ Object
13 14 15 16 17 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 13 def profile 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 edit end |
#profile_edit ⇒ Object
19 20 21 22 23 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 19 def profile_edit I18n.t('camaleon_cms.admin.users.profile') @user = cama_current_user.object edit end |
#show ⇒ Object
25 26 27 28 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 25 def show I18n.t('camaleon_cms.admin.users.profile') render 'profile' end |
#update ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 30 def update r = { user: @user } hooks_run('user_update', r) if @user.update(user_params) @user.(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] r = { user: @user } hooks_run('user_updated', r) if cama_current_user.id == @user.id redirect_to action: :profile_edit else redirect_to action: :index end else render 'form' end end |
#update_auth_token_in_cookie(token) ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 61 def (token) return unless current_token = updated_token = [token, *current_token[1..]] [:auth_token] = updated_token.join('&') end |
#updated_ajax ⇒ Object
update some ajax requests from profile or user form
52 53 54 55 56 57 58 59 |
# File 'app/controllers/camaleon_cms/admin/users_controller.rb', line 52 def updated_ajax @user = current_site.users.find(params[:user_id]) update_session = current_user_is?(@user) @user.update(params.require(:password).permit!) render inline: @user.errors..join(', ') # keep user logged in when changing their own password @user.auth_token if update_session && @user.saved_change_to_password_digest? end |