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