Commit 6bbedec8 by chenith

Updated email address change process.

parent 7dd8c1c2
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<column name="verification_mail_send_date" type="Date" nullable="true"/> <column name="verification_mail_send_date" type="Date" nullable="true"/>
<column name="verification_key" type="String" nullable="true" length="10"/> <column name="verification_key" type="String" nullable="true" length="10"/>
<column name="is_account_verified" type="Boolean" nullable="true"/> <column name="is_account_verified" type="Boolean" nullable="true"/>
<column name="is_email_changed" type="Boolean" nullable="true"/>
<column name="user_id" type="Long" length="11" nullable="true"/> <column name="user_id" type="Long" length="11" nullable="true"/>
<column name="company_id" type="Long" length="11" nullable="true"/> <column name="company_id" type="Long" length="11" nullable="true"/>
</NODE> </NODE>
......
...@@ -15,6 +15,7 @@ CREATE TABLE oneit_sec_user_extension ( ...@@ -15,6 +15,7 @@ CREATE TABLE oneit_sec_user_extension (
verification_mail_send_date datetime NULL, verification_mail_send_date datetime NULL,
verification_key varchar(10) NULL, verification_key varchar(10) NULL,
is_account_verified char(1) NULL, is_account_verified char(1) NULL,
is_email_changed char(1) NULL,
user_id numeric(12) NULL, user_id numeric(12) NULL,
company_id numeric(12) NULL company_id numeric(12) NULL
); );
......
...@@ -16,6 +16,7 @@ CREATE TABLE oneit_sec_user_extension ( ...@@ -16,6 +16,7 @@ CREATE TABLE oneit_sec_user_extension (
verification_mail_send_date date NULL, verification_mail_send_date date NULL,
verification_key varchar2(10) NULL, verification_key varchar2(10) NULL,
is_account_verified char(1) NULL, is_account_verified char(1) NULL,
is_email_changed char(1) NULL,
user_id number(12) NULL, user_id number(12) NULL,
company_id number(12) NULL company_id number(12) NULL
); );
......
...@@ -16,6 +16,7 @@ CREATE TABLE oneit_sec_user_extension ( ...@@ -16,6 +16,7 @@ CREATE TABLE oneit_sec_user_extension (
verification_mail_send_date timestamp NULL, verification_mail_send_date timestamp NULL,
verification_key varchar(10) NULL, verification_key varchar(10) NULL,
is_account_verified char(1) NULL, is_account_verified char(1) NULL,
is_email_changed char(1) NULL,
user_id numeric(12) NULL, user_id numeric(12) NULL,
company_id numeric(12) NULL company_id numeric(12) NULL
); );
......
...@@ -7,12 +7,16 @@ import oneit.email.ConfigurableArticleTemplateEmailer; ...@@ -7,12 +7,16 @@ import oneit.email.ConfigurableArticleTemplateEmailer;
import oneit.logging.LogLevel; import oneit.logging.LogLevel;
import oneit.logging.LogMgr; import oneit.logging.LogMgr;
import oneit.objstore.StorageException; import oneit.objstore.StorageException;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.security.SecUser;
import oneit.servlets.forms.SubmissionDetails; import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult; import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState; import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.SaveFP; import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException; import oneit.utils.BusinessException;
import oneit.utils.InitialisationException; import oneit.utils.InitialisationException;
import oneit.utils.MultiException;
import oneit.utils.StringUtils;
import performa.orm.CompanyUser; import performa.orm.CompanyUser;
import performa.utils.Utils; import performa.utils.Utils;
...@@ -21,6 +25,28 @@ public class ResendVerificationFP extends SaveFP ...@@ -21,6 +25,28 @@ public class ResendVerificationFP extends SaveFP
{ {
protected ConfigurableArticleTemplateEmailer emailer; protected ConfigurableArticleTemplateEmailer emailer;
@Override
protected Map validate(SubmissionDetails submission, MultiException exceptions)
{
HttpServletRequest request = submission.getRequest();
CompanyUser companyUser = (CompanyUser) request.getAttribute("CompanyUser");
SecUser secUser = companyUser.getUser();
if(!companyUser.isLoggedViaSocial())
{
BusinessObjectParser.assertFieldCondition(StringUtils.isEmailAddress(secUser.getUserName()), secUser, SecUser.FIELD_Email, "invalid", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(!Utils.isCompanyUserEmailFound(secUser.getTransaction(), secUser.getUserName(), companyUser), secUser, SecUser.FIELD_UserName, "emailExists", exceptions, true, request);
}
else
{
BusinessObjectParser.assertFieldCondition(!Utils.isCompanyUserEmailFound(secUser.getTransaction(), secUser.getEmail(), companyUser), secUser, SecUser.FIELD_Email, "emailExists", exceptions, true, request);
}
return super.validate(submission, exceptions);
}
@Override @Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{ {
...@@ -31,12 +57,13 @@ public class ResendVerificationFP extends SaveFP ...@@ -31,12 +57,13 @@ public class ResendVerificationFP extends SaveFP
if(companyUser != null) if(companyUser != null)
{ {
Utils.sendVerificationMail(companyUser, request, emailer, ResendVerificationFP.class.getName()); Utils.sendEmailChangedMail(companyUser, request, emailer, ResendVerificationFP.class.getName());
} }
return super.processForm(process, submission, params); return super.processForm(process, submission, params);
} }
@Override @Override
public void init(ParticipantInitialisationContext context) throws InitialisationException public void init(ParticipantInitialisationContext context) throws InitialisationException
{ {
......
...@@ -63,6 +63,7 @@ public class SaveUserDetailsFP extends SaveFP ...@@ -63,6 +63,7 @@ public class SaveUserDetailsFP extends SaveFP
if(validPassword) if(validPassword)
{ {
companyUser.setIsAccountVerified(Boolean.FALSE); companyUser.setIsAccountVerified(Boolean.FALSE);
companyUser.setIsEmailChanged(Boolean.TRUE);
Utils.sendEmailChangedMail(companyUser, request, emailer, SaveUserDetailsFP.class.getName()); Utils.sendEmailChangedMail(companyUser, request, emailer, SaveUserDetailsFP.class.getName());
} }
...@@ -73,9 +74,9 @@ public class SaveUserDetailsFP extends SaveFP ...@@ -73,9 +74,9 @@ public class SaveUserDetailsFP extends SaveFP
//send email verification mail //send email verification mail
LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1,"Sending email resetted mail", companyUser ); LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1,"Sending email resetted mail", companyUser );
Utils.sendEmailChangedMail(companyUser, request, emailer, SaveUserDetailsFP.class.getName()); companyUser.setIsEmailChanged(Boolean.TRUE);
companyUser.setIsAccountVerified(Boolean.FALSE); Utils.sendEmailChangedMail(companyUser, request, emailer, SaveUserDetailsFP.class.getName());
} }
} }
...@@ -93,11 +94,11 @@ public class SaveUserDetailsFP extends SaveFP ...@@ -93,11 +94,11 @@ public class SaveUserDetailsFP extends SaveFP
if(!companyUser.isLoggedViaSocial()) if(!companyUser.isLoggedViaSocial())
{ {
BusinessObjectParser.assertFieldCondition(StringUtils.isEmailAddress(secUser.getUserName()), secUser, SecUser.FIELD_Email, "invalid", exceptions, true, request); BusinessObjectParser.assertFieldCondition(StringUtils.isEmailAddress(secUser.getUserName()), secUser, SecUser.FIELD_Email, "invalid", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(!isCompanyUserEmailFound(secUser.getTransaction(), secUser.getUserName(), companyUser), secUser, SecUser.FIELD_UserName, "emailExists", exceptions, true, request); BusinessObjectParser.assertFieldCondition(!Utils.isCompanyUserEmailFound(secUser.getTransaction(), secUser.getUserName(), companyUser), secUser, SecUser.FIELD_UserName, "emailExists", exceptions, true, request);
} }
else else
{ {
BusinessObjectParser.assertFieldCondition(!isCompanyUserEmailFound(secUser.getTransaction(), secUser.getEmail(), companyUser), secUser, SecUser.FIELD_Email, "emailExists", exceptions, true, request); BusinessObjectParser.assertFieldCondition(!Utils.isCompanyUserEmailFound(secUser.getTransaction(), secUser.getEmail(), companyUser), secUser, SecUser.FIELD_Email, "emailExists", exceptions, true, request);
} }
BusinessObjectParser.assertFieldCondition(secUser.getFirstName()!= null, secUser, SecUser.FIELD_FirstName, "mandatory", exceptions, true, request); BusinessObjectParser.assertFieldCondition(secUser.getFirstName()!= null, secUser, SecUser.FIELD_FirstName, "mandatory", exceptions, true, request);
...@@ -114,25 +115,4 @@ public class SaveUserDetailsFP extends SaveFP ...@@ -114,25 +115,4 @@ public class SaveUserDetailsFP extends SaveFP
emailer = (ConfigurableArticleTemplateEmailer) (context.getSingleChild("AccountVerificationEmailer")); emailer = (ConfigurableArticleTemplateEmailer) (context.getSingleChild("AccountVerificationEmailer"));
} }
private static Boolean isCompanyUserEmailFound(ObjectTransaction objTran, String email, CompanyUser currentUser)
{
if(email!=null)
{
SecUser user = SecUser.searchNAME(objTran, email.toLowerCase());
if(user!=null)
{
CompanyUser comUser = user.getExtension(CompanyUser.REFERENCE_CompanyUser);
if(comUser!=null && !CollectionUtils.equals(comUser, currentUser))
{
return Boolean.TRUE;
}
}
}
return Boolean.FALSE;
}
} }
\ No newline at end of file
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<ATTRIB name="VerificationMailSendDate" type="Date" dbcol="verification_mail_send_date" /> <ATTRIB name="VerificationMailSendDate" type="Date" dbcol="verification_mail_send_date" />
<ATTRIB name="VerificationKey" type="String" dbcol="verification_key" length="10"/> <ATTRIB name="VerificationKey" type="String" dbcol="verification_key" length="10"/>
<ATTRIB name="IsAccountVerified" type="Boolean" dbcol="is_account_verified" defaultValue="Boolean.FALSE"/> <ATTRIB name="IsAccountVerified" type="Boolean" dbcol="is_account_verified" defaultValue="Boolean.FALSE"/>
<ATTRIB name="IsEmailChanged" type="Boolean" dbcol="is_email_changed" defaultValue="Boolean.FALSE"/>
<SINGLEREFERENCE name="User" type="SecUser" dbcol="user_id" backreferenceName="Extensions" inSuper='TRUE'/> <SINGLEREFERENCE name="User" type="SecUser" dbcol="user_id" backreferenceName="Extensions" inSuper='TRUE'/>
<SINGLEREFERENCE name="Company" type="Company" dbcol="company_id" backreferenceName="Users"/> <SINGLEREFERENCE name="Company" type="Company" dbcol="company_id" backreferenceName="Users"/>
......
...@@ -379,6 +379,26 @@ public class Utils ...@@ -379,6 +379,26 @@ public class Utils
return Boolean.FALSE; return Boolean.FALSE;
} }
public static Boolean isCompanyUserEmailFound(ObjectTransaction objTran, String email, CompanyUser currentUser)
{
if(email!=null)
{
SecUser user = SecUser.searchNAME(objTran, email.toLowerCase());
if(user!=null)
{
CompanyUser comUser = user.getExtension(CompanyUser.REFERENCE_CompanyUser);
if(comUser!=null && !CollectionUtils.equals(comUser, currentUser))
{
return Boolean.TRUE;
}
}
}
return Boolean.FALSE;
}
public static Tuple.T2<SecUser, Boolean> getSecUserForCompanyIfAvailable(CompanyUser companyUser) public static Tuple.T2<SecUser, Boolean> getSecUserForCompanyIfAvailable(CompanyUser companyUser)
{ {
...@@ -432,25 +452,25 @@ public class Utils ...@@ -432,25 +452,25 @@ public class Utils
} }
catch (ConfigurableEmailerException ex) catch (ConfigurableEmailerException ex)
{ {
LogMgr.log(CompanyUser.LOG, LogLevel.SYSTEMERROR1, ex, "Error occured while sending mail for Candidate :: " + companyUser); LogMgr.log(CompanyUser.LOG, LogLevel.SYSTEMERROR1, ex, "Error occured while sending mail for user :: " + companyUser);
throw new BusinessException("We are unable to send mail. Please try again or contact Talentology for more details."); throw new BusinessException("We are unable to send mail. Please try again or contact Talentology for more details.");
} }
} }
else else
{ {
LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Call from " + callingClass + ". Account is already verified for candidate :: ", companyUser); LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Call from " + callingClass + ". Account is already verified for user :: ", companyUser);
} }
} }
public static void sendEmailChangedMail(CompanyUser companyUser, HttpServletRequest request, ConfigurableArticleTemplateEmailer emailer, String callingClass) throws BusinessException public static void sendEmailChangedMail(CompanyUser companyUser, HttpServletRequest request, ConfigurableArticleTemplateEmailer emailer, String callingClass) throws BusinessException
{ {
if(!CollectionUtils.equals(companyUser.getIsAccountVerified(), Boolean.TRUE)) if(companyUser.getIsEmailChanged()==Boolean.TRUE)
{ {
try try
{ {
LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Sending verification mail from " + callingClass + " to :: ", companyUser); LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Sending email changed mail from " + callingClass + " to :: ", companyUser);
RandomStringGen random = new RandomStringGen(); RandomStringGen random = new RandomStringGen();
...@@ -467,18 +487,18 @@ public class Utils ...@@ -467,18 +487,18 @@ public class Utils
Utils.sendMail(emailer, transform, new String[]{companyUser.getEmailAddressFromUser()}, null, companyUser); Utils.sendMail(emailer, transform, new String[]{companyUser.getEmailAddressFromUser()}, null, companyUser);
LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Sent verification mail successfully from " + callingClass + " to :: ", companyUser); LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Sent email changed mail successfully from " + callingClass + " to :: ", companyUser);
} }
catch (ConfigurableEmailerException ex) catch (ConfigurableEmailerException ex)
{ {
LogMgr.log(CompanyUser.LOG, LogLevel.SYSTEMERROR1, ex, "Error occured while sending mail for Candidate :: " + companyUser); LogMgr.log(CompanyUser.LOG, LogLevel.SYSTEMERROR1, ex, "Error occured while sending mail for user :: " + companyUser);
throw new BusinessException("We are unable to send mail. Please try again or contact Talentology for more details."); throw new BusinessException("We are unable to send mail. Please try again or contact Talentology for more details.");
} }
} }
else else
{ {
LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Call from " + callingClass + ". Account is already verified for candidate :: ", companyUser); LogMgr.log(CompanyUser.LOG, LogLevel.PROCESSING1, "Call from " + callingClass + ". Account is already verified for user :: ", companyUser);
} }
} }
} }
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
<AccountVerificationEmailer factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="EmailChangedMail"/> <AccountVerificationEmailer factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="EmailChangedMail"/>
</FORM> </FORM>
<FORM name="*.resendVerification" factory="Participant" class="performa.form.ResendVerificationFP"> <FORM name="*.resendVerification" factory="Participant" class="performa.form.ResendVerificationFP">
<AccountVerificationEmailer factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="CompanyAccountVerificationMail"/> <AccountVerificationEmailer factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="EmailChangedMail"/>
</FORM> </FORM>
<FORM name="*.saveClient" factory="Participant" class="performa.form.SaveClientFP"/> <FORM name="*.saveClient" factory="Participant" class="performa.form.SaveClientFP"/>
<FORM name="*.saveCompany" factory="Participant" class="performa.form.SaveCompanyFP"/> <FORM name="*.saveCompany" factory="Participant" class="performa.form.SaveCompanyFP"/>
......
...@@ -11,9 +11,51 @@ ...@@ -11,9 +11,51 @@
<% <%
ORMProcessState process = (ORMProcessState) ProcessDecorator.getDefaultProcess(request); ORMProcessState process = (ORMProcessState) ProcessDecorator.getDefaultProcess(request);
ObjectTransaction objTran = process.getTransaction (); ObjectTransaction objTran = process.getTransaction ();
%> String nextPage = WebUtils.getArticleByShortCut(process.getTransaction(), WebUtils.ADMIN_HOME).getLink(request);
//to process company user verification
String id = request.getParameter("id");
String key = request.getParameter("key");
Boolean invalid = Boolean.TRUE;
if(id!=null && key!=null)
{
CompanyUser companyUser = CompanyUser.searchIdPin(objTran, Long.parseLong(id), key);
if(companyUser!=null && companyUser.getIsEmailChanged()==Boolean.TRUE)
{
try
{
companyUser.setIsEmailChanged(Boolean.FALSE);
companyUser.setIsAccountVerified(Boolean.TRUE);
objTran.commit();
objTran.commitResources();
}
finally
{
objTran.releaseResources();
}
Email verified! invalid = Boolean.FALSE;
// response.sendRedirect(nextPage);
}
}
if(invalid)
{
%>
<h3>Verification Error</h3>
<p><span>Access expired.</span></p>
<%
}
else
{
%>
<p>Your e-mail address is successfully verified! Please login to access your account!</p>
<a class="btn btn-primary" href="<%= nextPage %>">Go to login</a>
<%
}
%>
<%@ include file="inc/htmlfooter_nopriv.jsp" %> <%@ include file="inc/htmlfooter_nopriv.jsp" %>
\ No newline at end of file
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<% } <% }
if(!CollectionUtils.equals(companyUser.getIsAccountVerified(), Boolean.TRUE)) if(companyUser.getIsAccountVerified()!=Boolean.TRUE || companyUser.getIsEmailChanged()==Boolean.TRUE)
{ {
%> %>
<div class="email-verify">Email address not yet verified. <div class="email-verify">Email address not yet verified.
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
{ {
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser); CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
if(companyUser!=null && companyUser.getIsAccountVerified()!=Boolean.TRUE) if(companyUser!=null && companyUser.isLoggedViaSocial() && companyUser.getIsAccountVerified()!=Boolean.TRUE)
{ {
response.sendRedirect(WebUtils.getArticleByShortCut(process.getTransaction(), WebUtils.COMPANY_ACCOUNT_VERIFICATION).getLink(request)); response.sendRedirect(WebUtils.getArticleByShortCut(process.getTransaction(), WebUtils.COMPANY_ACCOUNT_VERIFICATION).getLink(request));
return; return;
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.RedefineTableOperation">
<tableName factory="String">oneit_sec_user_extension</tableName>
<column name="is_email_changed" type="Boolean" nullable="true"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment