public void GenerateOTP(string EmailID)
        {
            if (!CheckEmailID(EmailID))
            {
                throw new UserDefinedException(string.Format(StringResource.AlreadyTaken, "Email id"));
            }
            int      MaxAttempts = Convert.ToInt32(ConfigurationManager.AppSettings["ReSendOtpAttempts"]);
            DateTime objDT       = DateTime.Now.Date;
            int      Count       = uow.OtpLogs.Queryable().Where(x => x.emailId == EmailID && x.isVerified == false && objDT >= x.CreatedOn).Count();

            if (MaxAttempts < Count)
            {
                throw new UserDefinedException(StringResource.ReachedMaxAttempts);
            }
            OtpLog objOL = new OtpLog
            {
                otpID      = RandomHelpers.Instance.RandomString(6, true),
                emailId    = EmailID,
                isVerified = false,
                CreatedOn  = DateTime.Now
            };

            uow.OtpLogs.Add(objOL);
            int RowCount = uow.Save();

            if (RowCount > 0)
            {
                MailUtility objMu = new MailUtility();
                objMu.SendMail(objOL.emailId, "Otp", true, "Your Otp is " + objOL.otpID);
            }
        }
Пример #2
0
        public async Task <int> CheckMobileAllReadyRegisteredOrNot([FromBody] Users obj)
        {
            try
            {
                List <Users> lstuser = new List <Users>();
                lstuser = this._usersBAL.CheckMobileAlreadyRegisteredOrNot(obj).Result;
                string urlParameters = "";

                if (lstuser.Count == 0)
                {
                    Random _random = new Random();
                    int    otp     = _random.Next(100000, 999999);
                    string api_key = "c47c40de-e3cf-11ea-9fa5-0200cd936042";

                    string URL = "https://2factor.in/API/V1/" + api_key + "/SMS/+91" + obj.MobileNo.ToString() + "/" + otp.ToString() + "/Regotp";

                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(URL);

                    // Add an Accept header for JSON format.
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // List data response.
                    HttpResponseMessage response = client.GetAsync(urlParameters).Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.
                    if (response.IsSuccessStatusCode)
                    {
                        var jsonData = await response.Content.ReadAsStringAsync();

                        dynamic data         = JObject.Parse(jsonData);
                        string  OTPsessionid = ((Newtonsoft.Json.Linq.JValue)((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JContainer)data).Last).Value).Value.ToString();

                        OtpLog _objOtpLog = new OtpLog();
                        _objOtpLog.MobileNo  = obj.MobileNo.ToString();
                        _objOtpLog.OTP       = otp.ToString();
                        _objOtpLog.SessionId = OTPsessionid;

                        int res = await Task.Run(() => this._usersBAL.InsertOtp(_objOtpLog));

                        return(0);
                    }

                    else
                    {
                        return(-1);
                        //return 0;
                    }
                }

                return(await Task.Run(() => lstuser.Count));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log($"Something went wrong inside UsersController checkMobileAllReadyRegisteredOrNot action: {ex.Message}");
                ErrorLogger.Log(ex.StackTrace);

                Logger.LogError($"Something went wrong inside UsersController checkMobileAllReadyRegisteredOrNot action: {ex.Message}");
                return(-1);
            }
        }
Пример #3
0
        public static void SendOTPUsername(string phone_number, string otp)
        {
            string message  = System.Configuration.ConfigurationManager.AppSettings["SMS_MESSAGE_OTP_USERNAME"];
            string time_exp = System.Configuration.ConfigurationManager.AppSettings["OTPPwdExpired"];

            message = message.Replace("{otp}", otp);
            message = message.Replace("{time}", time_exp);
            OtpLog log    = new OtpLog();
            string result = fire(phone_number, message, log);
        }
Пример #4
0
        public static void SendOTPReg(string phone_number, string otp)//ORIGIN
        //public static string SendOTPReg(string phone_number, string otp)//DEBUG
        {
            string message  = System.Configuration.ConfigurationManager.AppSettings["SMS_MESSAGE_OTP_REG"];
            string time_exp = System.Configuration.ConfigurationManager.AppSettings["OTPPwdExpired"];

            message = message.Replace("{otp}", otp);
            message = message.Replace("{time}", time_exp);
            OtpLog log    = new OtpLog();
            string result = fire(phone_number, message, log); //ORIGIN
            //return result;//DEBUG
        }
        public bool VerifyOtp(string EmailID, string OTP)
        {
            OtpLog obj = uow.OtpLogs.GetAll().Where(x => x.emailId == EmailID).OrderByDescending(x => x.CreatedOn).FirstOrDefault();

            if (obj != null)
            {
                if (obj.otpID == OTP)
                {
                    obj.isVerified = true;
                    obj.UpdatedOn  = DateTime.Now;
                    uow.OtpLogs.Edit(obj);
                    return(uow.Save() > 0 ? true : false);
                }
            }
            return(false);
        }
Пример #6
0
        public async Task <int> Verifymobileotp(OtpLog obj)
        {
            try
            {
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("@MobileNo", obj.MobileNo);
                parameters.Add("@OTP", obj.OTP);

                var res = await SqlMapper.ExecuteScalarAsync(con, "p_CheckOtp_mobile", param : parameters, commandType : StoredProcedure);

                return(Convert.ToInt32(res));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public async Task <int> VerifyMobileOtp([FromBody] OtpLog obj)
        {
            try
            {
                int res = await this._usersBAL.Verifymobileotp(obj);

                if (res > 0)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Something went wrong inside UsersController Verifymobileotp action: {ex.Message}");
                return(-1);
            }
        }
Пример #8
0
        public static void SendUsername(string phone_number)
        {
            using (var db = new EchoContext())
            {
                AccountMobile am       = db.AccountMobiles.Where(x => x.Mobile_Number.Equals(phone_number)).Where(x => x.Status_Cd.Equals("AC")).SingleOrDefault();
                string        username = "";

                if (am != null)
                {
                    Account ac = db.Accounts.SingleOrDefault(x => x.Account_Id == am.Account_Id);
                    if (ac != null)
                    {
                        username = ac.User_Name;
                        string message = System.Configuration.ConfigurationManager.AppSettings["SMS_MESSAGE_FORGOT_USERNAME"];
                        message = message.Replace("{username}", username);
                        OtpLog log    = new OtpLog();
                        string result = fire(phone_number, message, log);
                    }
                }
            }
        }
Пример #9
0
 public Task <int> Verifymobileotp(OtpLog obj)
 {
     return(_users.Verifymobileotp(obj));
 }
Пример #10
0
 public Task <int> InsertOtp(OtpLog obj)
 {
     return(_users.InsertOtp(obj));
 }
Пример #11
0
        private static string fire(string phone_number, string msg, object log)
        {
            string result = string.Empty;

            System.Type type_of = log.GetType();                                       //ORIGIN

            System.Configuration.ConfigurationManager.AppSettings["SEND_SMS"] = "YES"; //dummy data for DEBUG

            if (System.Configuration.ConfigurationManager.AppSettings["SEND_SMS"].Equals("YES"))
            {
                string postData = "ACCOUNT=" + System.Configuration.ConfigurationManager.AppSettings["MOBILE_ACCOUNT"];
                postData += "&PASSWORD="******"MOBILE_PWD"];
                postData += "&MOBILE=" + phone_number;

                postData += "&MESSAGE=" + msg;

                postData += "&LANGUAGE=" + System.Configuration.ConfigurationManager.AppSettings["MESSAGE_LANGUAGE"];
                postData += "&SENDER=" + System.Configuration.ConfigurationManager.AppSettings["SENDER_NAME"];
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Encoding iso  = Encoding.GetEncoding("ISO-8859-11");
                Encoding utf8 = Encoding.UTF8;
                byte[]   data = encoding.GetBytes(postData);
                data = Encoding.Convert(utf8, iso, data);

                DateTime start_res = DateTime.Now;

                //result = "System.Configuration.ConfigurationManager.AppSettings['SEND_SMS'].Equals('Yes')"; //DEBUG

                try
                {
                    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["SMS_GATEWAY"]);
                    httpRequest.Method        = "POST";
                    httpRequest.Host          = System.Configuration.ConfigurationManager.AppSettings["SMS_HOST"]; //"203.146.102.26";
                    httpRequest.ContentType   = "application/x-www-form-urlencoded";
                    httpRequest.ContentLength = data.Length;
                    MemoryStream Memstream = new MemoryStream(data);
                    Stream       stream    = httpRequest.GetRequestStream();
                    Memstream.WriteTo(stream);
                    stream.Close();

                    Callback(httpRequest, (response) =>
                    {
                        var res_stream      = new StreamReader(response.GetResponseStream());
                        DateTime end_res    = DateTime.Now;
                        int index           = 0;
                        string[] result_rsp = new string[] { "", "", "", "" };
                        string rsp_str      = "";
                        while (res_stream.Peek() >= 0)
                        {
                            result_rsp[index] = res_stream.ReadLine();
                            index++;
                        }
                        foreach (var txt in result_rsp)
                        {
                            rsp_str += txt + " ";
                        }

                        //saving
                        using (var db = new EchoContext())
                        {
                            if (type_of == typeof(OtpLog))
                            {
                                OtpLog logger        = new OtpLog();
                                logger.Mobile_Number = phone_number;
                                logger.Request_At    = start_res;
                                logger.Response_At   = end_res;
                                logger.Response_Text = rsp_str;
                                db.OtpLogs.Add(logger);
                                db.SaveChanges();
                            }
                            else
                            {
                                if (type_of == typeof(ActivationSmsLog))
                                {
                                    ActivationSmsLog logger = new ActivationSmsLog();
                                    logger.Mobile_Number    = phone_number;
                                    logger.Request_At       = start_res;
                                    logger.Response_At      = end_res;
                                    logger.Response_Text    = rsp_str;
                                    db.ActivationSmsLogs.Add(logger);
                                    db.SaveChanges();
                                }
                            }
                        }
                        res_stream.Close();
                    });
                }
                catch (WebException wex)
                {
                    using (var db = new EchoContext())
                    {
                        if (type_of == typeof(OtpLog))
                        {
                            OtpLog logger = new OtpLog();
                            logger.Mobile_Number = phone_number;
                            logger.Request_At    = start_res;
                            logger.Response_At   = DateTime.Now;
                            logger.Response_Text = wex.Message;
                            db.OtpLogs.Add(logger);
                            db.SaveChanges();
                        }
                        else
                        {
                            if (type_of == typeof(ActivationSmsLog))
                            {
                                ActivationSmsLog logger = new ActivationSmsLog();
                                logger.Mobile_Number = phone_number;
                                logger.Request_At    = start_res;
                                logger.Response_At   = DateTime.Now;
                                logger.Response_Text = wex.Message;
                                db.ActivationSmsLogs.Add(logger);
                                db.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    FreebieEvent.AddError(ex, 0);
                }
            }
            else
            {
                result = ".AppSettings['SEND_SMS'].Equals('NO')"; //DEBUG
            }

            return(result);//ORIGIN
        }