Class: EgovUtils::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/egov_utils/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#approveObject



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?
  authorize!(:manage, User)
  @user.update(active: true, last_login_at: Time.current)
  redirect_back(fallback_location: @user)
end

#confirmObject



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

#createObject



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.
  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).(@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.full_messages, status: :unprocessable_entity }
    end
  end
end

#destroyObject



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

#editObject



52
# File 'app/controllers/egov_utils/users_controller.rb', line 52

def edit; end

#indexObject



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

#newObject



25
# File 'app/controllers/egov_utils/users_controller.rb', line 25

def new; end

#searchObject



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
  authorize!(:read, User)
  authorize!(: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

#showObject



50
# File 'app/controllers/egov_utils/users_controller.rb', line 50

def show; end

#unarchiveObject



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

#updateObject



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