Class: SlingUsers::User

Inherits:
Principal show all
Defined in:
lib/nakamura/users.rb

Direct Known Subclasses

AnonymousUser

Instance Attribute Summary collapse

Attributes inherited from Principal

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Principal

#message_path_for, #private_path_for, #public_path_for

Constructor Details

#initialize(username, password = $DEFAULT_PASSWORD) ⇒ User

Returns a new instance of User.



163
164
165
166
# File 'lib/nakamura/users.rb', line 163

def initialize(username, password=$DEFAULT_PASSWORD)
  super(username)
  @password = password
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



161
162
163
# File 'lib/nakamura/users.rb', line 161

def email
  @email
end

#firstNameObject

Returns the value of attribute firstName.



158
159
160
# File 'lib/nakamura/users.rb', line 158

def firstName
  @firstName
end

#lastNameObject

Returns the value of attribute lastName.



159
160
161
# File 'lib/nakamura/users.rb', line 159

def lastName
  @lastName
end

#passwordObject

Returns the value of attribute password.



157
158
159
# File 'lib/nakamura/users.rb', line 157

def password
  @password
end

Class Method Details

.admin_userObject



168
169
170
# File 'lib/nakamura/users.rb', line 168

def self.admin_user
  return User.new("admin", "admin")
end

.anonymousObject



172
173
174
# File 'lib/nakamura/users.rb', line 172

def self.anonymous
  return AnonymousUser.new
end

.url_for(name) ⇒ Object



225
226
227
# File 'lib/nakamura/users.rb', line 225

def self.url_for(name)
  return "#{$USERMANAGER_URI}user/#{name}"
end

Instance Method Details

#change_password(sling, newpassword) ⇒ Object



214
215
216
# File 'lib/nakamura/users.rb', line 214

def change_password(sling, newpassword)
   return sling.execute_post(sling.url_for("#{user_url}.changePassword.html"), "oldPwd" => @password, "newPwd" => newpassword, "newPwdConfirm" => newpassword)
end

#do_curl_auth(c) ⇒ Object



180
181
182
# File 'lib/nakamura/users.rb', line 180

def do_curl_auth(c)
  c.userpwd = "#{@name}:#{@password}"
end

#do_request_auth(req) ⇒ Object



176
177
178
# File 'lib/nakamura/users.rb', line 176

def do_request_auth(req)
  req.basic_auth(@name, @password)
end

#home_path_for(sling) ⇒ Object

Get the home folder of a group.



220
221
222
# File 'lib/nakamura/users.rb', line 220

def home_path_for(sling)
  return "/~#{@name}"
end

#to_sObject



184
185
186
# File 'lib/nakamura/users.rb', line 184

def to_s
  return "User: #{@name} (pass: #{@password})"
end

#update_properties(sling, props) ⇒ Object



188
189
190
# File 'lib/nakamura/users.rb', line 188

def update_properties(sling, props)
  return sling.execute_post(sling.url_for("#{user_url}.update.html"), props)
end

#update_user(sling) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/nakamura/users.rb', line 192

def update_user(sling)
    data = {}
    if (!firstName.nil? and !lastName.nil? and !email.nil?)
        data[":sakai:profile-import"] = JSON.generate({'basic' => {'access' => 'everybody', 'elements' => {'email' => {'value' => email}, 'firstName' => {'value' => firstName}, 'lastName' => {'value' => lastName}}}})
        # data[":sakai:pages-template"] = "/var/templates/site/defaultuser"
    end

    if (!firstName.nil?)
        data["firstName"] = firstName
    end

    if (!lastName.nil?)
        data["lastName"] = lastName
    end

    if (!email.nil?)
        data["email"] = email
    end

    return update_properties(sling, data)
end