use of org.hisp.dhis.webapi.webdomain.user.UserAccount in project dhis2-core by dhis2.
the class CurrentUserController method postUserAccountJson.
@RequestMapping(value = { "/profile", "/user-account" }, method = RequestMethod.POST, consumes = "application/json")
public void postUserAccountJson(HttpServletResponse response, HttpServletRequest request) throws Exception {
UserAccount userAccount = renderService.fromJson(request.getInputStream(), UserAccount.class);
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
// basic user account
currentUser.setFirstName(userAccount.getFirstName());
currentUser.setSurname(userAccount.getSurname());
currentUser.setEmail(userAccount.getEmail());
currentUser.setPhoneNumber(userAccount.getPhoneNumber());
// profile
currentUser.setIntroduction(userAccount.getIntroduction());
currentUser.setJobTitle(userAccount.getJobTitle());
currentUser.setGender(userAccount.getGender());
if (userAccount.getBirthday() != null && !userAccount.getBirthday().isEmpty()) {
currentUser.setBirthday(DateUtils.getMediumDate(userAccount.getBirthday()));
}
currentUser.setNationality(userAccount.getNationality());
currentUser.setEmployer(userAccount.getEmployer());
currentUser.setEducation(userAccount.getEducation());
currentUser.setInterests(userAccount.getInterests());
currentUser.setLanguages(userAccount.getLanguages());
userService.updateUser(currentUser);
}
use of org.hisp.dhis.webapi.webdomain.user.UserAccount in project dhis2-core by dhis2.
the class CurrentUserController method getUserAccount.
private UserAccount getUserAccount() throws NotAuthenticatedException {
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
UserAccount userAccount = new UserAccount();
// user account
userAccount.setId(currentUser.getUid());
userAccount.setUsername(currentUser.getUsername());
userAccount.setFirstName(currentUser.getFirstName());
userAccount.setSurname(currentUser.getSurname());
userAccount.setEmail(currentUser.getEmail());
userAccount.setPhoneNumber(currentUser.getPhoneNumber());
// profile
userAccount.setIntroduction(currentUser.getIntroduction());
userAccount.setJobTitle(currentUser.getJobTitle());
userAccount.setGender(currentUser.getGender());
if (currentUser.getBirthday() != null) {
userAccount.setBirthday(DateUtils.getMediumDateString(currentUser.getBirthday()));
}
userAccount.setNationality(currentUser.getNationality());
userAccount.setEmployer(currentUser.getEmployer());
userAccount.setEducation(currentUser.getEducation());
userAccount.setInterests(currentUser.getInterests());
userAccount.setLanguages(currentUser.getLanguages());
userAccount.getSettings().put(UserSettingKey.UI_LOCALE.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.UI_LOCALE)));
userAccount.getSettings().put(UserSettingKey.DB_LOCALE.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.DB_LOCALE)));
userAccount.getSettings().put(UserSettingKey.MESSAGE_EMAIL_NOTIFICATION.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.MESSAGE_EMAIL_NOTIFICATION)));
userAccount.getSettings().put(UserSettingKey.MESSAGE_SMS_NOTIFICATION.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.MESSAGE_SMS_NOTIFICATION)));
userAccount.getSettings().put(UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getName(), TextUtils.toString(userSettingService.getUserSetting(UserSettingKey.ANALYSIS_DISPLAY_PROPERTY)));
return userAccount;
}
use of org.hisp.dhis.webapi.webdomain.user.UserAccount in project dhis2-core by dhis2.
the class CurrentUserController method getUserAccountJson.
@RequestMapping(value = { "/profile", "/user-account" }, produces = { "application/json", "text/html" })
public void getUserAccountJson(HttpServletResponse response) throws Exception {
UserAccount userAccount = getUserAccount();
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), userAccount);
}
use of org.hisp.dhis.webapi.webdomain.user.UserAccount in project dhis2-core by dhis2.
the class CurrentUserController method getUserAccountJsonP.
@RequestMapping(value = { "/profile", "/user-account" }, produces = { "application/javascript" })
public void getUserAccountJsonP(@RequestParam(defaultValue = "callback") String callback, HttpServletResponse response, HttpServletRequest request) throws Exception {
UserAccount userAccount = getUserAccount();
response.setContentType("application/javascript");
renderService.toJsonP(response.getOutputStream(), userAccount, callback);
}
Aggregations