Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To send confirmation email to user after register on WSO2 API Manager Store #4070

Closed
pcalero opened this issue Dec 10, 2018 · 7 comments
Closed

Comments

@pcalero
Copy link

pcalero commented Dec 10, 2018

Description:
It is not possible to send confirmation email to user after register (sign up) on API Store (of WSO2 API Manager).

Suggested Labels:
Type/Bug
Severity/Major
product-apim

Suggested Assignees:

Affected Product Version:
WSO2 API Manager 2.5.0

OS, DB, other environment details and versions:
Cluster of two nodes with load balancer. High availability

Steps to reproduce:

  1. User register (sign up) on API Store.
  2. No email is received in his/her inbox.

Related Issues:
https://stackoverflow.com/questions/53308357/how-to-send-account-confirmation-e-mail-after-self-sign-up-on-wso2-api-manager/
#2265
https://stackoverflow.com/questions/41828554/wso2-api-manager-user-authencation-email

@pcalero pcalero changed the title To send confirmation email to user after register on WSO2 API Manager To send confirmation email to user after register on WSO2 API Manager Store Dec 19, 2018
@pubudu538
Copy link
Contributor

This is possible with the use of user signup workflow in APIM [1]. As explains in [2], you can send an email when a user sign up request comes or when a user sign up request completes.

[1] - https://docs.wso2.com/display/AM260/Adding+a+User+Signup+Workflow
[2] - https://docs.wso2.com/display/AM260/Customizing+a+Workflow+Extension

Thank you!

@apercova
Copy link

Hi @pubudu538

I have an issue related to @pcalero 's one.

As you've said above in your reply to @pcalero, it's in fact possible to send an email to any custom email address, however it's no possible get the email address provided at user registration even though email address is required in order to complete user registration.

I've successfully implemented user signup workflow with Azure Flow by writing a custom implementation, but as explained before, there's no way to get registered-user's email address and send them back an email confirmation for their user-registration approval status.

Here is an excerpt with default WSO2 user signup workflow implementation attributes carried by org.wso2.carbon.apimgt.impl.dto.WorkflowDTO class

		String tenantDomain = workflowDTO.getTenantDomain();
		String tenantAwareUserName = MultitenantUtils
				.getTenantAwareUsername(workflowDTO.getWorkflowReference());
		String externalRef = workflowDTO.getExternalWorkflowReference();
		String callBackURL = workflowDTO.getCallbackUrl();

Do you know any possible way to programmatically get the user email from username?

Thank you!

@pubudu538
Copy link
Contributor

You can use APIMgtDAO and do as follows. In this way, you can access any DAO layer.

ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();

Probably you can try the following method to get the email address of a user. https://github.com/wso2/carbon-apimgt/blob/master/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java#L1198

@apercova
Copy link

Hi @pubudu538 thanks for your quick reply.

Unfortunately this approach is for retrieve a Subscriber from it's username. At the time users sign up their requested user is completely new and has no subscriptions.

I've tried follow query targeted to UM_USER_ATTRIBUTE table but seems that getting the connection object as in ApiMgtDAO points to WSO2AM DB.

SELECT UM_ATTR_NAME AS EMAIL_ADDRESS 
  FROM UM_USER_ATTRIBUTE 
 WHERE LOWER(UM_USER_ID) = ? 
   AND UM_TENANT_ID = ? 
   AND UM_ATTR_NAME = 'mail'

I wonder whether there's a similar way to get a connection pointing to WSO2UM DB. I've looked at code but couldn't find any User DTO or something similar.

Thanks in advance.

@apercova
Copy link

apercova commented Aug 22, 2019

Hi @pubudu538
I've followed this approach for retrieving user email from custom user signup workflow implementation.
I use default WSO2 org.wso2.carbon.apimgt.impl.token.ClaimsRetriever as user gets already registered (although pending for approval) at PRIMARY userstore.

private static final String EMAIL_CLAIM_ADDRESS = "http://wso2.org/claims/emailaddress";
....
/* Getting user claims for tenantAwareUserName*/
private Map<String, String> getUserClaims(String tenantAwareUserName) {
	/* Getting user claims */
	
	Map<String, String> claims = new HashMap<>();
	try {
		ClaimsRetriever claimsRetriever = new DefaultClaimsRetriever();
		claimsRetriever.init();

		claims = claimsRetriever.getClaims(tenantAwareUserName);
		log.debug("Begin user claims =================");
		claims.entrySet().stream()
		.forEach(c -> log.debug(String.format("%s=%s%n", c.getKey(), c.getValue())));
		log.debug("End user claims =================");
	} catch (APIManagementException e) {
		log.error("Error getting user claims");
	}
	return claims;
}
....
/* Looking for email claim for tenantAwareUserName*/
private String getUserEmail (String tenantAwareUserName){
	String userEmail;
	Map<String, String> claims = getUserClaims(tenantAwareUserName);
	
	userEmail = claims.entrySet().stream()
	.filter(c -> EMAIL_CLAIM_ADDRESS.equals(c.getKey()))
	.findFirst()
	.map(f -> f.getValue())
	.orElse("");
	
	log.debug(String.format("%s=%s%n", EMAIL_CLAIM_ADDRESS, userEmail));
	return userEmail;
}

Thanks for your support.
Regards

@tgtshanika
Copy link
Contributor

Answered, hence resolving. Please reopen if you need further help on this.

@amir-dh
Copy link

amir-dh commented Mar 8, 2020

Hi @pubudu538
I send the confirmation code for the user and easily confirm her account.
but I can't expire confirmation code. I want if a user didn't confirm his account, delete it after 24 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants