/// <summary> /// Resends an OTP message. /// If there is a current OTP, then the same OTP is resent. /// Otherwise a new OTP is generated and sent. /// </summary> /// <param name="userId">Id of the recipient user.</param> /// <param name="phoneNumber">Phone number to send OTP to.</param> /// <param name="userType">The user type.</param> public static void ResendOTP(int userId, string phoneNumber, string userType) { OneTimePwd otp = null; string otpString = string.Empty; using (OneTimePwdDao dao = new OneTimePwdDao()) { ReapOldOTPs(dao); otp = dao.FindByUserId(userId); // Check if there is a current OTP for the user. if (otp != null) // If there is, just reset the timestamp on the OTP { otpString = otp.Otg; otp.CreatedDate = DateTime.Now; dao.Update(otp); } else { otpString = GenerateOTP(); otp = new OneTimePwd { Otg = otpString, UserID = userId, UserType = userType, CreatedDate = DateTime.Now }; dao.Insert(otp); } } SendOTP(phoneNumber, otpString); }
public static bool SaveOTP(string otp, int userId, string userType) { OneTimePwd otpEntity = new OneTimePwd { Otg = otp, UserID = userId, UserType = userType, CreatedDate = DateTime.Now }; using (OneTimePwdDao dao = new OneTimePwdDao()) { dao.Insert(otpEntity); } return(true); }