class UserMgr {

	public VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail) {
		checkAccess(gjUser);
		if (gjUser.getEmailAddress() != null) {
			throw restErrorUtil.createRESTException(
					"serverMsg.userMgrEmailChange",
					MessageEnums.OPER_NO_PERMISSION, null, null, ""
							+ changeEmail);
		}

		String encryptedOldPwd = encrypt(gjUser.getLoginId(),
				changeEmail.getOldPassword());

		if (!stringUtil.validateEmail(changeEmail.getEmailAddress())) {
			logger.info("Invalid email address." + changeEmail);
			throw restErrorUtil.createRESTException(
					"serverMsg.userMgrInvalidEmail",
					MessageEnums.INVALID_INPUT_DATA, changeEmail.getId(),
					"emailAddress", changeEmail.toString());

		}

		if (!stringUtil.equals(encryptedOldPwd, gjUser.getPassword())) {
			logger.info("changeEmailAddress(). Invalid  password. changeEmail="
					+ changeEmail);

			throw restErrorUtil.createRESTException(
					"serverMsg.userMgrWrongPassword",
					MessageEnums.OPER_NO_PERMISSION, null, null, ""
							+ changeEmail);
		}

		// Normalize email. Make it lower case
		gjUser.setEmailAddress(stringUtil.normalizeEmail(changeEmail
				.getEmailAddress()));

		// loginId
		gjUser.setLoginId(gjUser.getEmailAddress());

		String saltEncodedpasswd = encrypt(gjUser.getLoginId(),
				changeEmail.getOldPassword());

		gjUser.setPassword(saltEncodedpasswd);

		daoManager.getXXPortalUser().update(gjUser);
		return mapXXPortalUserVXPortalUser(gjUser);
	}

	public  UserMgr();

}