コード例 #1
0
        public IActionResult generateOTP([FromBody] GenerateOTP otp)
        {
            try
            {
                string OTPValue = Common.GenerateOTP();

                SMSResponse results = new SMSResponse();

                var message = "";

                //otp.emailorPhone = "+14087224019";

                string SaveOtpValue = Data.User.GenerateOTP(OTPValue, otp);

                if (SaveOtpValue == "Success")
                {
                    results = SmsNotification.SendMessage(otp.phone, "Hi User, your OTP is " + OTPValue + " and it's expiry time is 15 minutes.");

                    string status = results.messages[0].status.ToString();

                    if (status == "0")
                    {
                        message = "Message sent successfully.";
                    }
                    else
                    {
                        string err = results.messages[0].error_text.ToString();
                        message = err;
                    }


                    return(StatusCode((int)HttpStatusCode.OK, new { message }));
                }

                else
                {
                    return(StatusCode((int)HttpStatusCode.InternalServerError, new { ErrorMessage = SaveOtpValue }));
                }
            }

            catch (Exception e)
            {
                string SaveErrorLog = Data.Common.SaveErrorLog("generateOTP", e.Message.ToString());

                return(StatusCode((int)HttpStatusCode.InternalServerError, new { ErrorMessage = e.Message.ToString() }));
            }
        }
コード例 #2
0
        public IActionResult SmsOTP(string PhoneNumber)
        {
            try
            {
                string OTPValue = Common.GenerateOTP();

                SMSResponse results = new SMSResponse();
                //results = SmsNotification.SendMessage(PhoneNumber, "Hi User, your OTP is" + OTPValue + "and it's expiry time is 5 minutes.").ToString();
                //// results = SmsNotification.SendMessage(userlogin.PhoneNumber, "Hi User, your OTP is" + OTPValue + "and it's expiry time is 5 minutes.").Status.ToString();

                var SmsStatus = "";
                //if (results == "RanToCompletion")
                //{
                //    string SaveOtpValue = Data.Common.SaveOTP("4560123045", OTPValue, "Phone");
                //    SmsStatus = "Message sent successfully.";
                //}
                //else
                //{
                //    SmsStatus = "Message not sent..";
                //}
                PhoneNumber = "+14087224019";

                string SaveOtpValue = Data.Common.SaveOTP(PhoneNumber, OTPValue, "Phone");

                if (SaveOtpValue == "Success")
                {
                    //SMSResponse results = SmsNotification.SendMessage(PhoneNumber, "Hi User, your OTP is " + OTPValue + " and it's expiry time is 5 minutes.");

                    results = SmsNotification.SendMessage(PhoneNumber, "Hi User, your OTP is " + OTPValue + " and it's expiry time is 5 minutes.");

                    string status = results.messages[0].status.ToString();

                    if (status == "0")
                    {
                        SmsStatus = "Message sent successfully.";
                    }
                    else
                    {
                        string err = results.messages[0].error_text.ToString();
                        SmsStatus = err;
                    }


                    // results = SmsNotification.SendMessage(PhoneNumber, "Hi User, your OTP is " + OTPValue + " and it's expiry time is 5 minutes.");
                    //var res = new List<SMSResponseDetail>();
                    //res = results.messages;



                    return(StatusCode((int)HttpStatusCode.OK, new { SmsStatus }));       //results.messages,
                }

                else
                {
                    return(StatusCode((int)HttpStatusCode.Forbidden, new { error = new { message = "Phone number not available" } }));
                }
            }

            catch (Exception e)
            {
                string SaveErrorLog = Data.Common.SaveErrorLog("SmsOTP", e.Message.ToString());

                return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = e.Message.ToString() } }));
            }
        }