Class: EgovUtils::UsersController

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

Instance Method Summary collapse

Instance Method Details

#approveObject



63
64
65
66
67
68
69
# File 'app/controllers/egov_utils/users_controller.rb', line 63

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



71
72
73
74
75
76
77
78
# File 'app/controllers/egov_utils/users_controller.rb', line 71

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/egov_utils/users_controller.rb', line 23

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



58
59
60
61
# File 'app/controllers/egov_utils/users_controller.rb', line 58

def destroy
  @user.destroy
  redirect_to users_path, notice: t('activerecord.successful.messages.destroyed', model: User.model_name.human)
end

#editObject



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

def edit
end

#indexObject



11
12
13
14
15
16
17
18
# File 'app/controllers/egov_utils/users_controller.rb', line 11

def index
  providers
  @groups = EgovUtils::Group.accessible_by(current_ability).order(:provider)
  @new_user = EgovUtils::User.new(generate_password: true)
  azahara_schema_index do |users|
    users.add_sort('provider')
  end
end

#newObject



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

def new
end

#searchObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/egov_utils/users_controller.rb', line 80

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{ render json: {users: user_results, groups: group_results} }
  end
end

#showObject



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

def show
end

#updateObject



52
53
54
55
56
# File 'app/controllers/egov_utils/users_controller.rb', line 52

def update
  @user.update(update_params)

  redirect_to users_path, notice: t('activerecord.successful.messages.updated', model: User.model_name.human)
end