public bool CheckEmailVerificationCode(string emailAddressId, string verificationCode, GlobalObject globalObject) { UserId.IsNullThrowException("You are not logged in"); emailAddressId.IsNullOrWhiteSpaceThrowArgumentException("emailAddressId"); verificationCode.IsNullOrWhiteSpaceThrowArgumentException("verificationCode"); EmailAddress emailAddress = Find(emailAddressId); emailAddress.IsNullThrowException("Email not found"); if (emailAddress.VerificationNumber == verificationCode) { //verification code matches... verifiy the email address //emailAddress.IsVerified = true; emailAddress.VerificationDateComplex.SetToTodaysDate(UserName, UserId); emailAddress.VerificationStatusEnum = VerificaionStatusENUM.Verified; emailAddress.VerificationDateComplex.SetToTodaysDate(UserName, UserId); ControllerCreateEditParameter param = new ControllerCreateEditParameter(); param.Entity = emailAddress as ICommonWithId; param.GlobalObject = globalObject; UpdateAndSave(param); ErrorsGlobal.AddMessage(string.Format("Email: '{0} has been VERIFIED'", emailAddress.Name)); return(true); } ErrorsGlobal.AddMessage(string.Format("Email: '{0}' -VERIFICATION FAILED!", emailAddress.Name)); return(false); }
//public override string SelectListCacheKey //{ // get { return "EmailAddressesSelectListData"; } //} /// <summary> /// This sends the user an email verification code to their email address to verify their email /// </summary> /// <param name="userId"></param> /// <param name="emailAddressId"></param> public void SendEmailConfirmation(string emailAddressId, GlobalObject globalObject) { UserId.IsNullThrowException("You are not logged in"); emailAddressId.IsNullOrWhiteSpaceThrowArgumentException("emailAddressId"); //get the email address. EmailAddress emailAddress = Find(emailAddressId); emailAddress.IsNullThrowException("Email Not found"); RandomNoGenerator randomGen = new RandomNoGenerator(5); string verificationNumber = randomGen.GetRandomNumber(1000); verificationNumber.IsNullOrWhiteSpaceThrowArgumentException("Random number not generated"); emailAddress.VerificationNumber = verificationNumber.ToString(); emailAddress.VerificationDateComplex.SetToTodaysDate(UserName, UserId); //time allowed for verification is 60 min. string body = string.Format("Your verification Id is: {0}", verificationNumber); string subject = string.Format("Verification for email: {0}", emailAddress.Name); string smtpServer = ConfigManagerHelper.SmtpServer; string portStr = ConfigManagerHelper.SmtpPort; portStr.IsNullOrWhiteSpaceThrowArgumentException("No port has been listed."); int portInt; bool success = int.TryParse(portStr, out portInt); if (!success) { throw new Exception("The port number is not a number."); } string userName = ConfigManagerHelper.SmtpUser; string from = ConfigManagerHelper.SmtpFromEmailAddress; string password = ConfigManagerHelper.SmtpPassword; List <string> sendToList = new List <string>(); sendToList.Add(emailAddress.Name); Emails emailClient = new Emails(smtpServer, portInt, userName, password, true); try { emailClient.SendEmailMsg(from, subject, body, sendToList, null); emailAddress.VerificationStatusEnum = VerificaionStatusENUM.Mailed; ControllerCreateEditParameter param = new ControllerCreateEditParameter(); param.Entity = emailAddress as ICommonWithId; param.GlobalObject = globalObject; PersonBiz.UpdateAndSave(param); //UpdateAndSave(emailAddress); ErrorsGlobal.AddMessage(string.Format("Verification Email Sent to: '{0}'", emailAddress.Name)); } catch (Exception e) { ErrorsGlobal.Add(string.Format("Unable to send Email to: '{0}'", emailAddress.Name), MethodBase.GetCurrentMethod(), e); } }