Class: AppyantraAdmin::ProfilesController

Inherits:
ApplicationController show all
Includes:
Utils
Defined in:
app/controllers/appyantra_admin/profiles_controller.rb

Instance Method Summary collapse

Methods included from Utils

#list_page_layouts, #random_password

Methods inherited from ApplicationController

#add_breadcrumb, #asset_display_name, #current_breadcrumb, #get_object_name, #set_objects

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 25

def create
  selected_admin_user = Admin.new(params[:admin_user])
  # TODO random password
  password = random_password
  selected_admin_user.password = password
  selected_admin_user.password_confirmation = password
  respond_to do |format|
    if selected_admin_user.save
      format.html do |format|
        flash[:notice] = "Admin user was successfully created" 
        redirect_to main_app.admin_profiles_path
      end
    else
      # TODO handle errors
    end
  end  
end

#destroyObject



86
87
88
89
90
91
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 86

def destroy
  admin_user = Admin.find(params[:id])
  admin_user.destroy
  flash[:notice] = "Admin was successfully deleted."
  redirect_to main_app.admin_profiles_path
end

#editObject



53
54
55
56
57
58
59
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 53

def edit
  @admin_user = Admin.find(params[:id])
  @page_title = 'Admin User | ' + @admin_user.display_name
  add_breadcrumb([@admin_user.display_name, main_app.admin_profile_path(@admin_user)])
  current_breadcrumb 'Edit'
  render 'edit'
end

#indexObject



12
13
14
15
16
17
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 12

def index
  @page_title = 'Admin Profiles'
  current_breadcrumb @page_title
	@admin_users = Admin.all
  render 'index'
end

#newObject



19
20
21
22
23
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 19

def new
  @page_title = 'New Admin User'
  current_breadcrumb 'New'
  @admin_user = Admin.new
end

#showObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 43

def show
  @selected_admin_user = Admin.find(params[:id])
  @page_title = 'Admin User | ' + @selected_admin_user.display_name
  current_breadcrumb @selected_admin_user.display_name
  respond_to do |format|
    format.html
    format.js
  end	
end

#updateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 61

def update
	selected_admin_user = Admin.find(params[:id])
  respond_to do |format|
    if selected_admin_user.update_attributes(params[:admin_user])
      format.html do |format|
        flash[:notice] = "Profile was successfully updated." 
        redirect_to main_app.admin_profiles_path
      end
    else
      # TODO handle errors
    end
  end
end

#update_passwordObject



75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/appyantra_admin/profiles_controller.rb', line 75

def update_password
  admin_user = Admin.find(params[:id])
  password_params = params[:admin_user]
  admin_user.reset_password!(password_params[:password], password_params[:password_confirmation])
  # TODO Fix auto logout issue when password is changed
  (current_admin, :bypass => true)
  flash[:notice] = "Password was successfully updated."
  redirect_to main_app.admin_profiles_path
  # TODO handle errors
end