Class: CmsAdmin::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/cms_admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#change_passwordObject



104
105
106
# File 'app/controllers/cms_admin/users_controller.rb', line 104

def change_password
  @cms_user = CmsUser.find_by_id(params[:id])
end

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/cms_admin/users_controller.rb', line 14

def create
  @cms_user = CmsUser.new(params[:cms_user])
  if @cms_site.authentication == 'LDAP'
    username = @cms_user.
    ldap = Net::LDAP.new(:host => @cms_site.ldap_hostname, :base => @cms_site.ldap_base_DN)
    filter = Net::LDAP::Filter.eq(@cms_site.ldap_uid, username)
    ldap.search(:filter => filter) do |entry|
      username = entry.dn
    end
    if username == @cms_user.
      flash[:error] = "Username not in LDAP"
      render :action => 'new'
      return
    end
  else
    if @cms_user.password.nil? || @cms_user.password.empty?
      flash[:error] = 'Password can not be blank'
      render :action => 'new'
      return
    end
  end
  if CmsUser.find_by_admin_and_disabled(true,false).nil? 
    if @cms_user.admin == false || @cms_user.disabled == true
      flash[:error] = 'The first user you create must be an Active Admin'
      render :action => 'new'
    else
      if @cms_user.save
        flash[:notice] = 'User Created'
        redirect_to cms_admin_users_path
      else
        flash[:error] = 'User could not be created'
        render :action => 'new'
      end
    end
  else
    if @cms_user.save
      flash[:notice] = 'User Created'
      redirect_to cms_admin_users_path
    else
      flash[:error] = 'User could not be created'
      render :action => 'new'
    end
  end
end

#editObject



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

def edit
  @cms_user = CmsUser.find_by_id(params[:id])
end

#indexObject



6
7
8
# File 'app/controllers/cms_admin/users_controller.rb', line 6

def index
  @cms_users = CmsUser.find(:all, :order => 'last_name ASC')
end

#newObject



10
11
12
# File 'app/controllers/cms_admin/users_controller.rb', line 10

def new
  @cms_user = CmsUser.new
end

#updateObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/cms_admin/users_controller.rb', line 63

def update
  @cms_user = CmsUser.find(params[:id])
  @cms_user.attributes = params[:cms_user]
  if @cms_site.authentication == 'LDAP'
    username = @cms_user.
    ldap = Net::LDAP.new(:host => @cms_site.ldap_hostname, :base => @cms_site.ldap_base_DN)
    filter = Net::LDAP::Filter.eq(@cms_site.ldap_uid, username)
    ldap.search(:filter => filter) do |entry|
      username = entry.dn
    end
    if username == @cms_user.
      flash[:error] = "Username not in LDAP"
      render :action => 'edit'
      return
    end
  else
    if @cms_user.password.nil? || @cms_user.password.empty?
      flash[:error] = 'Password can not be blank'
      render :action => 'new'
      return
    end
  end
  if @cms_user.disabled == true && CmsUser.find(:all, :conditions => {:admin => true, :disabled => false}).count == 1 &&  CmsUser.find(:all, :conditions => {:admin => true, :disabled => false}).first.id == @cms_user.id
    flash[:error] = "You can not disable the only Admin"
    render :action => 'edit'
  else
    if @cms_user.admin == false && CmsUser.find(:all, :conditions => {:admin => true, :disabled => false}).count == 1 && CmsUser.find(:all, :conditions => {:admin => true, :disabled => false}).first.id == @cms_user.id
      flash[:error] = "You must have one Active Admin User"
      render :action => 'edit'
    else
      if @cms_user.save
         flash[:notice] = "User was updated"
         redirect_to cms_admin_users_path
      else
        flash[:error] = 'User could not be updated'
        render :action => 'edit'
      end
    end
  end
end

#update_passwordObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/cms_admin/users_controller.rb', line 108

def update_password
  @cms_user = CmsUser.find_by_id(params[:id])
  @cms_user.attributes = params[:cms_user]
  if @cms_user.password.nil? || @cms_user.password.empty?
    flash[:error] = 'Password can not be blank'
    render :action => 'change_password'
    return
  end
  if @cms_user.save
    flash[:notice] = "Password was updated"
    redirect_to cms_admin_users_path
  else
    flash[:error] = 'User could not be updated'
    render :action => 'change_password'
  end
end