1
19
20 package com.liferay.portlet.login.action;
21
22 import com.liferay.portal.kernel.language.LanguageUtil;
23 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
24 import com.liferay.portal.kernel.servlet.SessionErrors;
25 import com.liferay.portal.kernel.servlet.SessionMessages;
26 import com.liferay.portal.kernel.util.Constants;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portlet.PortletPreferencesFactoryUtil;
30
31 import javax.portlet.ActionRequest;
32 import javax.portlet.ActionResponse;
33 import javax.portlet.PortletConfig;
34 import javax.portlet.PortletPreferences;
35 import javax.portlet.RenderRequest;
36 import javax.portlet.RenderResponse;
37
38
45 public class ConfigurationActionImpl extends BaseConfigurationAction {
46
47 public void processAction(
48 PortletConfig portletConfig, ActionRequest actionRequest,
49 ActionResponse actionResponse)
50 throws Exception {
51
52 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
53
54 if (!cmd.equals(Constants.UPDATE)) {
55 return;
56 }
57
58 String portletResource = ParamUtil.getString(
59 actionRequest, "portletResource");
60
61 PortletPreferences preferences =
62 PortletPreferencesFactoryUtil.getPortletSetup(
63 actionRequest, portletResource);
64
65 String tabs1 = ParamUtil.getString(actionRequest, "tabs1");
66
67 if (tabs1.equals("general")) {
68 updateGeneral(actionRequest, preferences);
69 }
70 else if (tabs1.equals("email-notifications")) {
71 updateEmailNotifications(actionRequest, preferences);
72 }
73
74 SessionMessages.add(
75 actionRequest, portletConfig.getPortletName() + ".doConfigure");
76 }
77
78 public String render(
79 PortletConfig portletConfig, RenderRequest renderRequest,
80 RenderResponse renderResponse)
81 throws Exception {
82
83 return "/html/portlet/login/configuration.jsp";
84 }
85
86 protected void updateEmailNotifications(
87 ActionRequest actionRequest, PortletPreferences preferences)
88 throws Exception {
89
90 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
91
92 if (tabs2.equals("password-changed-notification")) {
93 String languageId = LanguageUtil.getLanguageId(actionRequest);
94
95 String emailPasswordSentEnabled = ParamUtil.getString(
96 actionRequest, "emailPasswordSentEnabled");
97 String emailPasswordSentSubject = ParamUtil.getString(
98 actionRequest, "emailPasswordSentSubject_" + languageId);
99 String emailPasswordSentBody = ParamUtil.getString(
100 actionRequest, "emailPasswordSentBody_" + languageId);
101
102 preferences.setValue(
103 "emailPasswordSentEnabled", emailPasswordSentEnabled);
104 preferences.setValue(
105 "emailPasswordSentSubject_" + languageId,
106 emailPasswordSentSubject);
107 preferences.setValue(
108 "emailPasswordSentBody_" + languageId, emailPasswordSentBody);
109
110 preferences.store();
111 }
112 else {
113 String emailFromName = ParamUtil.getString(
114 actionRequest, "emailFromName");
115 String emailFromAddress = ParamUtil.getString(
116 actionRequest, "emailFromAddress");
117
118 preferences.setValue("emailFromName", emailFromName);
119
120 if (Validator.isNotNull(emailFromAddress) &&
121 !Validator.isEmailAddress(emailFromAddress)) {
122
123 SessionErrors.add(actionRequest, "emailFromAddress");
124 }
125 else {
126 preferences.setValue("emailFromName", emailFromName);
127 preferences.setValue("emailFromAddress", emailFromAddress);
128
129 preferences.store();
130 }
131 }
132 }
133
134 protected void updateGeneral(
135 ActionRequest actionRequest, PortletPreferences preferences)
136 throws Exception {
137
138 String authType = ParamUtil.getString(actionRequest, "authType");
139
140 preferences.setValue("authType", authType);
141
142 preferences.store();
143 }
144
145 }