List of usage examples for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY
String THEME_DISPLAY
To view the source code for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY.
Click Source Link
From source file:com.abubusoft.liferay.linkedin.LinkedinOAuth.java
License:Open Source License
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long companyId = themeDisplay.getCompanyId(); //String linkedinAuthURL = PropsUtil.get("linkedin.api.auth.url"); String linkedinApiKey = PrefsPropsUtil.getString(companyId, "linkedin.api.key"); String linkedinApiSecret = PrefsPropsUtil.getString(companyId, "linkedin.api.secret"); String linkedinCallbackURL = PrefsPropsUtil.getString(companyId, "linkedin.api.callback.url"); String cmd = ParamUtil.getString(request, Constants.CMD); if (cmd.equals("login")) { final OAuth20Service service = new ServiceBuilder().apiKey(linkedinApiKey).apiSecret(linkedinApiSecret) .scope("r_basicprofile,r_emailaddress") // replace with desired scope .callback(linkedinCallbackURL).state("some_params").build(LinkedInApi20.instance()); // Obtain the Request Token String url = service.getAuthorizationUrl(); response.sendRedirect(url);// w w w. j av a 2 s . co m } else if (cmd.equals("token")) { final OAuth20Service service = new ServiceBuilder().apiKey(linkedinApiKey).apiSecret(linkedinApiSecret) .scope("r_basicprofile,r_emailaddress") // replace with desired scope .callback(linkedinCallbackURL).state("some_params").build(LinkedInApi20.instance()); String code = ParamUtil.getString(request, "code"); final OAuth2AccessToken accessToken = service.getAccessToken(code); HttpSession session = request.getSession(); Map<String, Object> linkedinData = getLinkedinData(service, accessToken); User user = getOrCreateUser(themeDisplay.getCompanyId(), linkedinData); if (user != null) { session.setAttribute(LinkedinConstants.LINKEDIN_ID_LOGIN, user.getUserId()); sendLoginRedirect(request, response); return null; } session.setAttribute(LinkedinConstants.LINKEDIN_LOGIN_PENDING, Boolean.TRUE); sendCreateAccountRedirect(request, response, linkedinData); } return null; }
From source file:com.abubusoft.liferay.linkedin.LinkedinOAuth.java
License:Open Source License
protected void sendLoginRedirect(HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setWindowState(LiferayWindowState.POP_UP); portletURL.setParameter("struts_action", "/login/login_redirect"); response.sendRedirect(portletURL.toString()); }
From source file:com.abubusoft.liferay.linkedin.LinkedinOAuth.java
License:Open Source License
protected void sendCreateAccountRedirect(HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception { // String[] names = data.get("name").toString().split("\\s+"); String[] names = { data.get("firstName").toString(), data.get("lastName").toString() }; ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); redirectURL.setParameter("struts_action", "/login/login_redirect"); redirectURL.setParameter("anonymousUser", Boolean.FALSE.toString()); redirectURL.setPortletMode(PortletMode.VIEW); redirectURL.setWindowState(LiferayWindowState.POP_UP); PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("saveLastPath", Boolean.FALSE.toString()); portletURL.setParameter("struts_action", "/login/create_account"); portletURL.setParameter("redirect", redirectURL.toString()); portletURL.setParameter("linkedinId", data.get("id").toString()); portletURL.setParameter("screenName", (names[0] + "." + names[1] + ".linkedin").toLowerCase()); portletURL.setParameter("firstName", names[0]); portletURL.setParameter("lastName", names[1]); portletURL.setParameter("emailAddress", data.get("emailAddress").toString()); portletURL.setPortletMode(PortletMode.VIEW); portletURL.setWindowState(LiferayWindowState.POP_UP); response.sendRedirect(portletURL.toString()); }
From source file:com.abubusoft.liferay.twitter.CreateAccountAction.java
License:Open Source License
public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpSession session = request.getSession(); Boolean twitterLoginPending = (Boolean) session.getAttribute(TwitterConstants.TWITTER_LOGIN_PENDING); if ((twitterLoginPending != null) && twitterLoginPending.booleanValue()) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { throw new PrincipalException(); }// w w w .j av a 2s. co m try { addUser(actionRequest, actionResponse); } catch (Exception e) { if (e instanceof DuplicateUserEmailAddressException || e instanceof DuplicateUserScreenNameException || e instanceof AddressCityException || e instanceof AddressStreetException || e instanceof AddressZipException || e instanceof CaptchaMaxChallengesException || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException || e instanceof ContactFirstNameException || e instanceof ContactFullNameException || e instanceof ContactLastNameException || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException || e instanceof NoSuchCountryException || e instanceof NoSuchListTypeException || e instanceof NoSuchOrganizationException || e instanceof NoSuchRegionException || e instanceof OrganizationParentException || e instanceof PhoneNumberException || e instanceof RequiredFieldException || e instanceof RequiredUserException || e instanceof ReservedUserEmailAddressException || e instanceof ReservedUserScreenNameException || e instanceof TermsOfUseException || e instanceof UserEmailAddressException || e instanceof UserIdException || e instanceof UserPasswordException || e instanceof UserScreenNameException || e instanceof UserSmsException || e instanceof WebsiteURLException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { throw e; } } } else { originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse); } }
From source file:com.abubusoft.liferay.twitter.CreateAccountAction.java
License:Open Source License
protected void addUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpSession session = request.getSession(); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); long creatorUserId = 0; long facebookId = ParamUtil.getLong(actionRequest, "facebookId"); boolean autoPassword = true; boolean autoScreenName = false; boolean male = ParamUtil.getBoolean(actionRequest, "male", true); boolean sendEmail = true; String twitterId = ParamUtil.getString(actionRequest, "twitterId"); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); String screenName = ParamUtil.getString(actionRequest, "screenName"); String firstName = ParamUtil.getString(actionRequest, "firstName"); String lastName = ParamUtil.getString(actionRequest, "lastName"); String middleName = ParamUtil.getString(actionRequest, "middleName"); String password1 = StringPool.BLANK; String password2 = StringPool.BLANK; String jobTitle = ParamUtil.getString(actionRequest, "jobTitle"); String openId = StringPool.BLANK; int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth"); int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay"); int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear"); int prefixId = ParamUtil.getInteger(actionRequest, "prefixId"); int suffixId = ParamUtil.getInteger(actionRequest, "suffixId"); Locale locale = themeDisplay.getLocale(); long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; long[] userGroupIds = null; if (GetterUtil.getBoolean(PropsUtil.get(PropsKeys.LOGIN_CREATE_ACCOUNT_ALLOW_CUSTOM_PASSWORD))) { autoPassword = false;/*w w w.j a va2 s .c om*/ password1 = ParamUtil.getString(actionRequest, "password1"); password2 = ParamUtil.getString(actionRequest, "password2"); } ServiceContext serviceContext = new ServiceContext(); User user = UserLocalServiceUtil.addUser(creatorUserId, company.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext); user = UserLocalServiceUtil.updateLastLogin(user.getUserId(), user.getLoginIP()); user = UserLocalServiceUtil.updatePasswordReset(user.getUserId(), false); user = UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), false); ExpandoValueLocalServiceUtil.addValue(company.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, TwitterConstants.TWITTER_ID_COLUMN_NAME, user.getUserId(), twitterId); session.setAttribute(TwitterConstants.TWITTER_ID_LOGIN, new Long(user.getUserId())); session.removeAttribute(TwitterConstants.TWITTER_LOGIN_PENDING); PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setWindowState(LiferayWindowState.POP_UP); portletURL.setParameter("struts_action", "/login/login_redirect"); actionResponse.sendRedirect(portletURL.toString()); }
From source file:com.abubusoft.liferay.twitter.TwitterOAuth.java
License:Open Source License
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String cmd = ParamUtil.getString(request, Constants.CMD); long companyId = themeDisplay.getCompanyId(); String twitterApiKey = PrefsPropsUtil.getString(companyId, "twitter.api.key"); String twitterApiSecret = PrefsPropsUtil.getString(companyId, "twitter.api.secret"); String twitterCallbackURL = PrefsPropsUtil.getString(companyId, "twitter.api.callback.url"); if (cmd.equals("login")) { final OAuth10aService service = new ServiceBuilder().apiKey(twitterApiKey).apiSecret(twitterApiSecret) .callback(twitterCallbackURL).build(TwitterApi.instance()); // Obtain the Request Token final OAuth1RequestToken requestToken = service.getRequestToken(); String url = service.getAuthorizationUrl(requestToken); response.sendRedirect(url);/* w ww . j a va2s . co m*/ } else if (cmd.equals("token")) { HttpSession session = request.getSession(); String oauthVerifier = ParamUtil.getString(request, "oauth_verifier"); String oauthToken = ParamUtil.getString(request, "oauth_token"); if (Validator.isNull(oauthVerifier) || Validator.isNull(oauthToken)) { return null; } final OAuth10aService service = new ServiceBuilder().apiKey(twitterApiKey).apiSecret(twitterApiSecret) .callback(twitterCallbackURL).build(TwitterApi.instance()); final OAuth1RequestToken requestToken = new OAuth1RequestToken(oauthToken, twitterApiSecret); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); Map<String, Object> twitterData = getTwitterData(service, accessToken); User user = getOrCreateUser(themeDisplay.getCompanyId(), twitterData); if (user != null) { session.setAttribute(TwitterConstants.TWITTER_ID_LOGIN, user.getUserId()); sendLoginRedirect(request, response); return null; } session.setAttribute(TwitterConstants.TWITTER_LOGIN_PENDING, Boolean.TRUE); sendCreateAccountRedirect(request, response, twitterData); } return null; }
From source file:com.abubusoft.liferay.twitter.TwitterOAuth.java
License:Open Source License
protected void sendCreateAccountRedirect(HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception { String[] names = data.get("name").toString().split("\\s+"); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); redirectURL.setParameter("struts_action", "/login/login_redirect"); redirectURL.setParameter("anonymousUser", Boolean.FALSE.toString()); redirectURL.setPortletMode(PortletMode.VIEW); redirectURL.setWindowState(LiferayWindowState.POP_UP); PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("saveLastPath", Boolean.FALSE.toString()); portletURL.setParameter("struts_action", "/login/create_account"); portletURL.setParameter("redirect", redirectURL.toString()); portletURL.setParameter(TwitterConstants.TWITTER_ID_COLUMN_NAME, data.get("id").toString()); portletURL.setParameter("screenName", data.get("screen_name").toString()); portletURL.setParameter("firstName", names[0]); portletURL.setParameter("lastName", names[1]); portletURL.setPortletMode(PortletMode.VIEW); portletURL.setWindowState(LiferayWindowState.POP_UP); response.sendRedirect(portletURL.toString()); }
From source file:com.amf.registration.portlet.RegistrationPortlet.java
License:Open Source License
public void registrationUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String username = ParamUtil.getString(actionRequest, "username"); String firstName = ParamUtil.getString(actionRequest, "first_name"); String lastName = ParamUtil.getString(actionRequest, "last_name"); String emailAddress = ParamUtil.getString(actionRequest, "email_address"); boolean male = ParamUtil.getBoolean(actionRequest, "male", true); int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth"); int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay"); int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear"); String password1 = ParamUtil.getString(actionRequest, "password1"); String password2 = ParamUtil.getString(actionRequest, "password2"); String homePhone = ParamUtil.getString(actionRequest, "home_phone"); String mobilePhone = ParamUtil.getString(actionRequest, "mobile_phone"); String address = ParamUtil.getString(actionRequest, "address"); String address2 = ParamUtil.getString(actionRequest, "address2"); String city = ParamUtil.getString(actionRequest, "city"); long stateId = ParamUtil.getLong(actionRequest, "state"); String zip = ParamUtil.getString(actionRequest, "zip"); String securityQuestion = ParamUtil.getString(actionRequest, "security_question"); String securityAnswer = ParamUtil.getString(actionRequest, "security_answer"); boolean acceptedTou = ParamUtil.getBoolean(actionRequest, "accepted_tou"); Country country = CountryServiceUtil.getCountryByName(CountryConstants.UNITED_STATES); List<ListType> addressTypes = ListTypeServiceUtil.getListTypes(ListTypeConstants.CONTACT_ADDRESS); int typeId = 0; for (ListType addressType : addressTypes) { if (addressType.getName().equals("personal")) { typeId = addressType.getListTypeId(); break; }/*from ww w .j a v a2 s .com*/ } ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); validate(firstName, lastName, emailAddress, username, birthdayMonth, birthdayDay, birthdayYear, password1, password2, homePhone, mobilePhone, address, address2, city, zip, securityQuestion, securityAnswer, acceptedTou); User user = UserLocalServiceUtil.addUser(0, themeDisplay.getCompanyId(), false, password1, password2, false, username, emailAddress, 0, null, LocaleUtil.getDefault(), firstName, null, lastName, 0, 0, male, birthdayMonth, birthdayDay, birthdayYear, null, null, null, null, null, false, serviceContext); UserLocalServiceUtil.updatePasswordReset(user.getUserId(), false); UserLocalServiceUtil.updateReminderQuery(user.getUserId(), securityQuestion, securityAnswer); UserLocalServiceUtil.updateAgreedToTermsOfUse(user.getUserId(), acceptedTou); List<ListType> phoneTypes = ListTypeServiceUtil.getListTypes(ListTypeConstants.CONTACT_PHONE); for (ListType phoneType : phoneTypes) { if (phoneType.getName().equals("personal") && Validator.isNotNull(homePhone)) { PhoneLocalServiceUtil.addPhone(user.getUserId(), Contact.class.getName(), user.getContactId(), homePhone, null, phoneType.getListTypeId(), false); } else if (phoneType.getName().equals("mobile-phone") && Validator.isNotNull(mobilePhone)) { PhoneLocalServiceUtil.addPhone(user.getUserId(), Contact.class.getName(), user.getContactId(), mobilePhone, null, phoneType.getListTypeId(), false); } } AddressLocalServiceUtil.addAddress(user.getUserId(), Contact.class.getName(), user.getContactId(), address, address2, StringPool.BLANK, city, zip, stateId, country.getCountryId(), typeId, false, true); EventMonitorLocalServiceUtil.addEvent(user.getCompanyId(), user.getUserId(), user.getScreenName(), EventTypeConstants.REGISTRATION, IpConstants.DEFAULT); }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editSeller(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/* ww w. j av a 2 s .co m*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long sellerId = ParamUtil.getLong(actionRequest, "sellerId"); String name = ParamUtil.getString(actionRequest, "name"); boolean active = ParamUtil.getBoolean(actionRequest, "active"); if (Validator.isNull(name)) SessionErrors.add(actionRequest, "name-required"); if (!SessionErrors.isEmpty(actionRequest)) { actionResponse.setRenderParameters(actionRequest.getParameterMap()); return; } ServiceContext serviceContext = ServiceContextFactory.getInstance(Seller.class.getName(), actionRequest); Seller seller; if (sellerId == 0) { PaymentAppPermission.check(permissionChecker, themeDisplay.getScopeGroupId(), ActionKeys.ADD_SELLER); seller = SellerLocalServiceUtil.addSeller(themeDisplay.getUserId(), name, active, serviceContext); } else { SellerPermission.check(permissionChecker, sellerId, ActionKeys.UPDATE); seller = SellerLocalServiceUtil.updateSeller(sellerId, name, active, serviceContext); } String redirect = ParamUtil.getString(actionRequest, "successURL"); redirect = HttpUtil.setParameter(redirect, "_1_WAR_onlinepaymentportlet_sellerId", seller.getSellerId()); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-seller.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editRule(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {//w w w . j av a2s .c o m ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long ruleId = ParamUtil.getLong(actionRequest, "ruleId"); long paymentPluginConfigId = ParamUtil.getLong(actionRequest, "paymentPluginConfigId"); String content = ParamUtil.getString(actionRequest, "content"); PaymentPluginConfigPermission.check(permissionChecker, paymentPluginConfigId, ActionKeys.UPDATE); ServiceContext serviceContext = ServiceContextFactory.getInstance(Rule.class.getName(), actionRequest); Rule rule; if (ruleId == 0) { rule = RuleLocalServiceUtil.addRule(themeDisplay.getUserId(), paymentPluginConfigId, content, 0, serviceContext); } else { // Check that the user can update the previous config rule = RuleLocalServiceUtil.getRule(ruleId); PaymentPluginConfigPermission.check(permissionChecker, rule.getPaymentPluginConfigId(), ActionKeys.UPDATE); rule = RuleLocalServiceUtil.updateRule(ruleId, paymentPluginConfigId, content, rule.getPriority(), serviceContext); } String redirect = ParamUtil.getString(actionRequest, "successURL"); redirect = HttpUtil.setParameter(redirect, "_1_WAR_onlinepaymentportlet_ruleId", rule.getRuleId()); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-rule.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }