Class: EgovUtils::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- EgovUtils::UsersController
- Defined in:
- app/controllers/egov_utils/users_controller.rb
Instance Method Summary collapse
- #approve ⇒ Object
- #confirm ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #unarchive ⇒ Object
- #update ⇒ Object
Instance Method Details
#approve ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/controllers/egov_utils/users_controller.rb', line 69 def approve @user = User.find_by(id: params[:id]) render_404 and return if @user.nil? || @user.active? (:manage, User) @user.update(active: true, last_login_at: Time.current) redirect_back(fallback_location: @user) end |
#confirm ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'app/controllers/egov_utils/users_controller.rb', line 77 def confirm @user = User.find_by(confirmation_code: params[:id]) render_404 and return if @user.nil? || @user.active? || @user.updated_at < (Time.now - 24.hours) @user.update(active: true) logged_user = @user flash[:notice] = t('success_user_confirm') redirect_to('/') end |
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/egov_utils/users_controller.rb', line 27 def create @user.mail ||= @user.login respond_to do |format| if @user.save if EgovUtils::Settings.allow_register? && !current_user.logged? UserMailer.with(host: mailer_host).confirmation_email(@user).deliver_later flash[:notice] = t('notice_signeup_with_mail') else if @user.auth_source.nil? @user.update(active: true) UserMailer.with(host: mailer_host).account_information(@user, @user.password).deliver_later end flash[:notice] = t('activerecord.successful.messages.created', model: User.model_name.human) end format.html { redirect_to main_app.root_path } format.json { render json: @user, status: :created } else format.html { render 'new' } format.json { render json: @user.errors., status: :unprocessable_entity } end end end |
#destroy ⇒ Object
64 65 66 67 |
# File 'app/controllers/egov_utils/users_controller.rb', line 64 def destroy @user.destroy redirect_to users_path, notice: t('activerecord.successful.messages.destroyed', model: User.model_name.human) end |
#edit ⇒ Object
52 |
# File 'app/controllers/egov_utils/users_controller.rb', line 52 def edit; end |
#index ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/egov_utils/users_controller.rb', line 13 def index params[:default_scope] ||= :without_deleted azahara_schema_index do |users| users.add_sort('provider') end @entities = @users.entities.includes(:groups).page(params[:page] || 1).per(50) if params[:search] @entities = @entities.search(params[:search]) end end |
#new ⇒ Object
25 |
# File 'app/controllers/egov_utils/users_controller.rb', line 25 def new; end |
#search ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/egov_utils/users_controller.rb', line 86 def search (:read, User) (:read, Group) user_results = []; group_results = [] @providers.each do |provider| user_results.concat(provider.search_user(params[:q])) group_results.concat(provider.search_group(params[:q])) end if params[:q].present? respond_to do |format| format.json do render json: { users: user_results, groups: group_results } end end end |
#show ⇒ Object
50 |
# File 'app/controllers/egov_utils/users_controller.rb', line 50 def show; end |
#unarchive ⇒ Object
101 102 103 104 105 |
# File 'app/controllers/egov_utils/users_controller.rb', line 101 def unarchive user = User.with_deleted.find(params[:id]) user.restore redirect_to users_path, notice: t('activerecord.successful.messages.unarchived', model: User.model_name.human) end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/egov_utils/users_controller.rb', line 54 def update @user.update(update_params) if @user.valid? redirect_to users_path, notice: t('activerecord.successful.messages.updated', model: User.model_name.human) else render :edit end end |