Search in sources :

Example 1 with UserAccount

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);
}
Also used : User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) UserAccount(org.hisp.dhis.webapi.webdomain.user.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserAccount

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;
}
Also used : User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) UserAccount(org.hisp.dhis.webapi.webdomain.user.UserAccount)

Example 3 with 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);
}
Also used : UserAccount(org.hisp.dhis.webapi.webdomain.user.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with 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);
}
Also used : UserAccount(org.hisp.dhis.webapi.webdomain.user.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserAccount (org.hisp.dhis.webapi.webdomain.user.UserAccount)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 User (org.hisp.dhis.user.User)2 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)2