Пример #1
0
        public ActionResult ResetPassword(string username, bool isOtpSent = false, string otp = null, string newpassword = null)
        {
            ViewData["Username"] = username;
            ViewBag.IsOTPSent    = isOtpSent;
            if (!string.IsNullOrEmpty(otp))
            {
                var result = objDbTrx.ValidatePasswordResetRequest(username, otp);
                if (result && !string.IsNullOrEmpty(newpassword))
                {
                    var defaultPassword = newpassword;
                    result = objDbTrx.UpdateUserPassword(username, defaultPassword);
                    if (result)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ViewData["Message"] = "Invalid OTP Or New Password is empty";
                }
                ViewBag.IsOTPSent = true;
            }
            else
            {
                DataTable dt = objDbTrx.GetBDMSUserDtlByUserName(username);

                if (dt.Rows.Count == 1)
                {
                    var mobile  = dt.Rows[0]["MOBILE_NO"] != null && !string.IsNullOrWhiteSpace(Convert.ToString(dt.Rows[0]["MOBILE_NO"])) ? dt.Rows[0]["MOBILE_NO"].ToString() : dt.Rows[0]["USERTBL_MOBILE_NO"].ToString();
                    var EMAILID = dt.Rows[0]["EMAIL_ID"] != null && !string.IsNullOrWhiteSpace(Convert.ToString(dt.Rows[0]["EMAIL_ID"])) ? dt.Rows[0]["EMAIL_ID"].ToString() : dt.Rows[0]["USERTBL_EMAIL_ID"].ToString();
                    var OTP     = objDbTrx.CreatePasswordResetRequest(username, mobile);
                    if (!string.IsNullOrEmpty(OTP))
                    {
                        var MailSubject = "Forget Password OTP for BDMS";
                        var MailContent = "Your one time password is " + OTP + ". Please use the OTP to login in BDMS";
                        Utility.SendForgetpassEmail(EMAILID, MailSubject, MailContent);

                        //if (!Utility.SendSMS(mobile, "Your one time password is " + OTP + ". Please use the OTP to login in " + username))
                        if (!Utility.SendSMS(mobile, "Your one time password is " + OTP + ". Please use the OTP to login in BDMS"))
                        {
                            ViewData["Message"] = "OTP Failed";
                        }
                        else
                        {
                            ViewData["Message"] = "OTP Sent to " + mobile;
                            ViewBag.IsOTPSent   = true;
                        }
                    }
                }
                else
                {
                    ViewData["Message"] = "User doesn't exist";
                }
            }

            return(View("ForgotPassword"));
        }
Пример #2
0
        public HttpResponseMessage SaveData(MobileReceipt mobileReceipt)
        {
            string          ipstackKey = string.Empty;
            string          ipstackAPI = string.Empty;
            string          result     = "";
            WebRequest      request    = null;
            HttpWebResponse response   = null;

            try
            {
                var userObj = objDbTrx.GetBDMSUserDtlByUserName(mobileReceipt.UserID);

                mobileReceipt.UserID    = userObj != null && userObj.Rows.Count > default(int) ? userObj.Rows[0]["USER_ID"].ToString() : mobileReceipt.UserID;
                mobileReceipt.PhoneNo   = userObj != null && userObj.Rows.Count > default(int) ? userObj.Rows[0]["MOBILE_NO"].ToString() : "";
                mobileReceipt.SendersIP = System.Web.HttpContext.Current.Request.UserHostAddress;
                try
                {
                    if (string.IsNullOrWhiteSpace(mobileReceipt.Place.Trim()))
                    {
                        ipstackKey = ConfigurationManager.AppSettings["ipstackKey"] != null ? ConfigurationManager.AppSettings["ipstackKey"] : "09e51f44f1f8ed47c09a4e8f5c06de45";
                        ipstackAPI = ConfigurationManager.AppSettings["ipstackAPI"] != null ? ConfigurationManager.AppSettings["ipstackAPI"] : "http://api.ipstack.com/";

                        request  = WebRequest.Create(string.Format("{0}{1}?access_key={2}", ipstackAPI, mobileReceipt.SendersIP, ipstackKey));
                        response = (HttpWebResponse)request.GetResponse();

                        Stream       stream = response.GetResponseStream();
                        Encoding     ec     = System.Text.Encoding.GetEncoding("utf-8");
                        StreamReader reader = new System.IO.StreamReader(stream, ec);
                        result = reader.ReadToEnd();
                        reader.Close();
                        stream.Close();

                        RootObject obj = JsonConvert.DeserializeObject <RootObject>(result);
                        mobileReceipt.Place = string.Format("latitude - {0}, longitude - {1}, city - {2}, region_name - {3}, pin - {4}", obj.latitude, obj.longitude, obj.city, obj.region_name, obj.zip);
                    }
                }
                catch (Exception)
                {
                    mobileReceipt.Place = mobileReceipt.Place;
                }

                var smsCodeObj = objDbTrx.GetSMSCodeByChallan(mobileReceipt.ChallanBarcode);
                if (smsCodeObj != null && smsCodeObj.Rows.Count > default(int))
                {
                    var smscode = smsCodeObj.Rows[0]["SMSCode"] != null ? smsCodeObj.Rows[0]["SMSCode"].ToString() : string.Empty;
                    if (!string.IsNullOrWhiteSpace(smscode.Trim()))
                    {
                        if (smscode.Trim() == mobileReceipt.ReceiverCode.Trim())
                        {
                            objDbTrx.MobileCircleChallanReceived(mobileReceipt);
                            try
                            {
                                DataTable dtl       = objDbTrx.GetIDByChallanBarcode(mobileReceipt.ChallanBarcode);
                                string    challanid = dtl != null && dtl.Rows.Count > default(int) ? dtl.Rows[0]["ID"].ToString() : string.Empty;
                                if (!string.IsNullOrWhiteSpace(challanid))
                                {
                                    SendEmailAndSmsInOneShot(challanid);
                                }
                            }
                            catch (Exception excc) { }
                            return(Request.CreateResponse(HttpStatusCode.OK, new { Success = 1, Message = "Data has been submitted successfully in our system" }));
                        }
                        else
                        {
                            throw new Exception(string.Format("SMS Code does not matched for {0}", mobileReceipt.ChallanBarcode));
                        }
                    }
                    else
                    {
                        throw new Exception(string.Format("SMS Code does not exists for {0}", mobileReceipt.ChallanBarcode));
                    }
                }
                else
                {
                    throw new Exception(string.Format("Wrong challan number. {0} is not exists in our system", mobileReceipt.ChallanBarcode));
                }
            }
            catch (Exception ex)
            {
                string msg   = string.Empty;
                int    index = ex.Message.IndexOf("\r\n");
                if (index > 0)
                {
                    msg = ex.Message.Substring(0, index);
                }
                else
                {
                    msg = ex.Message;
                }

                objDbTrx.SaveSystemErrorLog(ex, System.Web.HttpContext.Current.Request.UserHostAddress);
                return(Request.CreateResponse(HttpStatusCode.OK, new { Success = default(int), Message = msg }));
            }
            //return Request.CreateResponse(HttpStatusCode.OK, new { Success = 1, Message = "Data has been submitted successfully in our system" });
        }