-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-update.put.json.js
executable file
·46 lines (33 loc) · 1.4 KB
/
user-update.put.json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
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
logger.warn("SCIM: PUT '/Users' Request with templateArgs " + url.templateArgs + " and body " + jsonUtils.toJSONString(json));
var id = url.templateArgs["id"];
//var userName = json.get("userName");
var firstName = jsonUtils.toObject(json.get("name")).givenName;
var lastName = jsonUtils.toObject(json.get("name")).familyName;
var mailAddress = jsonUtils.toObject(json.get("emails"))[0].value;
var active = jsonUtils.toObject(json.get("active"));
var user = people.getPerson(id);
if (user) {
try {
user.properties["cm:firstName"] = firstName;
user.properties["cm:lastName"] = lastName;
user.properties["cm:email"] = mailAddress;
user.save();
(active)?people.enableAccount(id):people.disableAccount(id);
status.code = 200;
model.user = {
"id": user.properties["cm:userName"],
"userName": user.properties["cm:userName"],
"active":(people.isAccountDisabled(id))?false:true,
"givenName": user.properties["cm:firstName"],
"familyName": user.properties["cm:lastName"],
"email": user.properties["cm:email"]
};
} catch(error) {
status.code = 500;
status.message = "Error updating user: " + id;
}
} else {
status.code = 404;
status.message = "User not found";
}
logger.warn("SCIM: PUT '/Users' Request had response " + jsonUtils.toJSONString(model.user) );