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