Liferay PortalURL in scheduler - liferay

I am creating a Scheduler in liferay Portlet and once the scheduler job is complete i have to send an email.
In this email i need to send the Portal URL as a link.
<a href="http://localhost:8080"
Can any body help me on how i can get the portal URL in scheduler.

You can use the following:
Company company = CompanyLocalServiceUtil.getCompany(companyId);
String portalURL = PortalUtil.getPortalURL(company.getVirtualHost(),
PortalUtil.getPortalPort(), false);
In the last call, the last parameter must be true if you are using https.
If you don't have access to the companyId in your class but you know that you have only one company in the DB (which is the normal case unless you are in a hosting/multitenant scenario) then you can use the following:
Company company = CompanyLocalServiceUtil.getCompanies().get(0);

Related

DocuSign how to customize name and company for each envelope without create users?

Is that possible to customize name and company name for each envelope without create all users? or even just hide it?
If this is not possible, what is the recommendations for the following scenario?
We have 5,000 users, they are from different companies(different email domain)
User purchase points on our system, and they use points to buy eSign envelope
We don't want to create 5,000 users under our DocuSign account (not only adding them, we also don't want them to have account to login to DocuSign and create envelope without pay us.
We like to show their name and company in highlight area below
We are OK the email send to the singer is from DocuSign
What you show is the name and company of the sender, the account holder, the person who initiated the request to sign. Not the signer, the person who needs to act on it. Hope this is clear.
You can change the name and company name of the sender/company account programmatically, and then send the next envelope.
However, if you want to do something like this, you won't be able to use bulk send, because it doesn't allow you to make the change between each envelope.
You can run a loop that does this:
Change name/company
Create envelope
Send envelope
Doing this 5000 times also has an issue with API limit (default to 3000/hour) so you will either have to throttle this or contact support to increase your limit
Changing the name of the account holder can be done like this:
Here is C# code for this:
var apiClient = new ApiClient(basePath);
// You will need to obtain an access token using your chosen authentication method
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
UsersApi usersApi = new UsersApi(apiClient);
UserProfile userProfile = new UserProfile();
userProfile.UserDetails = new UserInformation();
userProfile.UserDetails.FirstName = "Inbar";
userProfile.UserDetails.LastName = "Gazit";
usersApi.UpdateProfile(accountId, userId, userProfile);
You can find all other langs and more details here - https://www.docusign.com/blog/developers/common-api-tasks-update-the-name-docusign-user

Custom Post Login Action Hook in Liferay 7 using Blade

I am developing a liferay project where there are 2 sites, 1 for Admin and 1 for users. Admin and users are differentiated based on user groups. when an admin logs in he should be redirected to Admin page and when user logs in, they should be redirected to User page. How can we achieve this functionality in Liferay 7 using Blade or Hook plugin? Any help would be appreciated. Thanks!!!
You can find a plugin example here:
https://www.e-systems.tech/blog/-/blogs/liferay-7-how-to-get-a-session-object-after-login-
Basically, if you want a post login hook, this example should be enough.
To use liferay services, in the new style, you will need some references
private Portal portal;
private UserLocalService userLocalService;
#Reference
private void setUserLocalService(UserLocalService service){
this.userLocalService=service;
}
#Reference
private void setPortalUtil(Portal portal){
this.portal=portal;
}
now, to get user information and more data about the portal
final long companyId = portal.getCompanyId(request);
final HttpSession session = request.getSession();
This line should be useful to:
User user = (User)session.getAttribute(WebKeys.USER);
For redirection: use the redirect parameter in the URL.
or, this code would help..
Map params = new HashMap();
params.put("p_l_id", new String[] {"PRI.1.1"});
LastPath lastPath = new LastPath("/c", "/portal/layout", params);
ses.setAttribute(WebKeys.LAST_PATH, lastPath);
For this to work, you might also check the auth.forward.by.last.path property

How to use liferay inbuilt email templates programatically?

In my liferay application I am adding application users by using Expando programatically and not using liferay default User signup.
Now I want to send credentials to user to his email address using liferay default templates available from Control Panel - Portal Setting - Email Templates.
How can I trigger email using this liferay inbuilt template?
Any hint is appreciated.
Liferay uses template files(.tmpl) files to manage Email templates.
As per the Liferay Source,for User creation,given snippet is used to send out mail to users.
String body = PrefsPropsUtil.getContent(
user.getCompanyId(), PropsKeys.ADMIN_EMAIL_USER_ADDED_BODY);
SubscriptionSender subscriptionSender = new SubscriptionSender();
subscriptionSender.setBody(body);
subscriptionSender.setCompanyId(user.getCompanyId());
subscriptionSender.setContextAttributes(
"[$USER_ID$]", user.getUserId(), "[$USER_PASSWORD$]", password,
"[$USER_SCREENNAME$]", user.getScreenName());
subscriptionSender.setFrom(fromAddress, fromName);
subscriptionSender.setHtmlFormat(true);
subscriptionSender.setMailId(
"user", user.getUserId(), System.currentTimeMillis(),
PwdGenerator.getPassword());
subscriptionSender.setServiceContext(serviceContext);
subscriptionSender.setSubject(subject);
subscriptionSender.setUserId(user.getUserId());
subscriptionSender.addRuntimeSubscribers(toAddress, toName);
subscriptionSender.flushNotificationsAsync();
This is part of service impl class UserLocalServiceImpl.
Here "PropsKeys.ADMIN_EMAIL_USER_ADDED_BODY" is the path of the template for body content(default used by liferay).You can populate your custom data in the provided template.
Edit:
After you perform your custom logic,you can directly call
UserLocalServiceUtil.sendPassword(
long companyId, String emailAddress, String fromName,
String fromAddress, String subject, String body,
ServiceContext serviceContext)
method directly from custom class,which will take care of using liferay template as well as password management.

Liferay find User screenName from User Email

Is there any api to find out screen name by passing the email address as the input in liferay for LDAP configuration?
You'll need to get a request object, then do this
long companyID = PortalUtil.getCompanyId(request)
User user = UserLocalServiceUtil.getUserByEmailAddress(companyID, emailAddress);
String scrName = user.getScreenName();
EDIT : in your liferay control panel/portal/authentication/LDAP, there is field named 'user search filter'
use (cn=#screen_name#) if your users are logging with screenName
use (mail=#email_address#) if your users are logging with email address
This way you're supposed to import the users automatically.
Please update your question. According to your tags, it looked like you're searching for a Liferay API. If you wanted an LDAP API you should write it somewhere

FBA on Sharepoint 2010

I have implemented FBA (Claim based Authentication) on Sharepoint 2010. Following are implemented.
Custom Login page
Custom Sign-in Page
Password recovery page (ForgetPassword.aspx)
In ForgetPassword page user is asked to enter their email address, they used while sign-in and in code behind I am using this email to get the UserName using the Membership.GetUserNameByEmail function and then passing this username to Membership.GetUser function to get the user credential to be send through mail.
But now the code throws as exception saying "The function is not implemented". I am wondering; I am not using any custom database for which I had to create a Custom Membership Provider. Then why I am getting this error. Let me know if anyone has any clue or faced similar problem. Thanks.
Regards,
Paddy
When FBA is configured for SharePoint 2010, two membership providers are defined in the web.config file - Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider (usually named i) and System.Web.Security.SqlMembershipProvider (named FBAMembership in this case). Default membership provider must be set to the former (i.e. SharePoint claims one) in order for FBA authentication to work properly.
When the line containing Membership.GetUserNameByEmail(...) is executed, the default membership provider is used and as a result SPClaimsAuthMembershipProvider.GetUserNameByEmail is called. MSDN says that this method is reserved for internal use and is not intended to be used directly from your code and according to the comment in the Community Content section it throws NotImplementedException.
You need to retrieve an instance of the SqlMembershipProvider provider from the Membership.Providers collection and then call the GetUserNameByEmail method using this instance.
I use prefixes when configuring providers in the web.config file and the retrieve them like this:
string applicationNamePrefix = "fbaProvider_";
MembershipProvider fbaProvider;
foreach (MembershipProvider provider in Membership.Providers)
{
if (provider.ApplicationName.StartsWith(applicationNamePrefix, StringComparison.InvariantCultureIgnoreCase))
{
fbaProvider = provider;
}
}
throw new InvalidOperationException("Appropriate provider was not found.");

Resources