Class: Authengine::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/authengine/users_controller.rb

Overview

Besides the ususal REST actions, this controller contains show_self, edit_self and update_self actions. This permits access to be explicitly controlled via the check_permissions filter, distinguishing between actions on one’s own model vs. actions on other users’ models.

Instance Method Summary collapse

Instance Method Details

#activateObject

account was created by admin and now user is entering username/password



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/authengine/users_controller.rb', line 58

def activate
  # TODO must remember to reset the session[:activation_code]
  # looks as if setting current user (next line) was causing the user to be
  # logged-in after activation
  user = User.find_and_activate!(params[:activation_code])
  if user.update_attributes(params[:user].slice(:login, :email, :password, :password_confirmation))
    redirect_to root_path
  else
    flash[:warn] = user.errors.full_messages
    redirect_to (user)
  end
rescue User::ArgumentError
  flash[:notice] = 'Activation code not found. Please ask the database administrator to create an account for you.'
  redirect_to new_authengine_user_path
rescue User::ActivationCodeNotFound
  flash[:notice] = 'Activation code not found. Please ask the database administrator to create an account for you.'
  redirect_to new_authengine_user_path
rescue User::AlreadyActivated
  flash[:notice] = 'Your account has already been activated. You can log in below.'
  redirect_to 
end

#createObject

users may only be created by the administrator from the index page



37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/authengine/users_controller.rb', line 37

def create
  cookies.delete :auth_token
  @user = User.new(params[:user])
  @user.save!
  redirect_to authengine_users_path
rescue ActiveRecord::RecordInvalid
  flash[:error] = "There was a problem creating the user account."
  @roles=Role.all
  render :action => 'new'
end

#destroyObject



101
102
103
104
105
# File 'app/controllers/authengine/users_controller.rb', line 101

def destroy
  @user = User.find(params[:id])
  @user.destroy
  redirect_to authengine_users_path
end

#disableObject



107
108
109
110
111
112
113
# File 'app/controllers/authengine/users_controller.rb', line 107

def disable
  @user = User.find(params[:id])
  unless @user.update_attribute(:enabled, false)
    flash[:error] = "There was a problem disabling this user."
  end
  redirect_to authengine_users_path
end

#editObject

edit a user profile with id given



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

def edit # edit a user profile with id given
  @user = User.find(params[:id])
end

#edit_selfObject

edit profile of current user



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

def edit_self # edit profile of current user
  @user = current_user
  render :template => 'users/edit'
end

#enableObject



115
116
117
118
119
120
121
# File 'app/controllers/authengine/users_controller.rb', line 115

def enable
  @user = User.find(params[:id])
  unless @user.update_attribute(:enabled, true)
    flash[:error] = "There was a problem enabling this user."
  end
  redirect_to authengine_users_path
end

#indexObject



17
18
19
# File 'app/controllers/authengine/users_controller.rb', line 17

def index
  @users = User.find(:all, :order=>"lastName, firstName")
end

#newObject



30
31
32
33
34
# File 'app/controllers/authengine/users_controller.rb', line 30

def new
  @user = User.new
  @user.user_roles.build
  @roles = Role.all
end

#showObject



21
22
23
# File 'app/controllers/authengine/users_controller.rb', line 21

def show
  @user = User.find(params[:id])
end

#show_selfObject



25
26
27
28
# File 'app/controllers/authengine/users_controller.rb', line 25

def show_self
  @user = current_user
  render :template=>"users/show"
end

#signupObject



123
124
125
# File 'app/controllers/authengine/users_controller.rb', line 123

def 
  @user = User.find(params[:id])
end

#updateObject



91
92
93
94
95
96
97
98
99
# File 'app/controllers/authengine/users_controller.rb', line 91

def update
  @user = User.find(params[:id])
  if @user.update_attributes(params[:user])
    flash[:notice] = "User updated"
    redirect_to authengine_users_path
  else
    render :action => 'edit'
  end
end

#update_selfObject



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

def update_self
  @user = User.find(current_user.id)
  if @user.update_attributes(params[:user])
    flash[:notice] = "Your profile has been updated"
    redirect_to authengine_users_path
  else
    flash[:notice] = @user.errors.full_messages
    render :action => 'edit'
  end
end