Beispiel #1
0
 public ActionResult ForgetPassword(Users model)
 {
     if (TempData.Peek("Page") == "userid")
     {
         if (string.IsNullOrWhiteSpace(model.UserID))
         {
             TempData["Page"] = "userid";
             DisplayMessage("Please Enter User ID", "User ID Can not be left blank", 'w');
             return(View(model));
         }
         if (Session["captchaText"].ToString() != model.CaptchaCode)
         {
             TempData["Page"] = "userid";
             DisplayMessage("Invalid Captch Code", "Please Enter a Valid Captcha", 'w');
             return(View(model));
         }
         Session["UserID"] = model.UserID;
         TempData["Page"]  = "otp";
         model.OTP         = GenerateOtp.Random();
         var lst = db.UpdateOTP <Users>(model);
         if (lst != null && lst.Count() > 0)
         {
             objcomman.SendMail(lst.First().Email, "Forget Password OTP ", "Your OTP Is" + model.OTP);
             DisplayMessage("Otp has been Sent on Registered Mail ID ", " Please Check and Verify OTP", 's');
         }
         return(View());
     }
     if (TempData.Peek("Page") == "otp")
     {
         if (string.IsNullOrWhiteSpace(model.OTP))
         {
             DisplayMessage("Please Enter OTP", "OTP Can not be left blank", 'w');
             return(View(model));
         }
         model.UserID = Session["UserID"].ToString();
         var lst = db.VerifyOTP <Users>(model);
         if (lst != null && lst.Count() > 0)
         {
             TempData["Page"] = "ForgetPassword";
             DisplayMessage("Otp Verified Succefully", "Please Enter new Password", 's');
             return(View());
         }
         else
         {
             TempData["Page"] = "otp";
             DisplayMessage("Otp Not Verified Succefully", "Please Enter  Valid OTP", 's');
             return(View());
         }
     }
     return(View());
 }
 public ActionResult Register(Users model)
 {
     if (!(
             (string.IsNullOrWhiteSpace(model.Name)) ||
             (string.IsNullOrWhiteSpace(model.FatherName)) ||
             (string.IsNullOrWhiteSpace(model.Email)) ||
             (string.IsNullOrWhiteSpace(model.Contact)) ||
             (string.IsNullOrWhiteSpace(model.Address)) ||
             (string.IsNullOrWhiteSpace(model.Gender))
             ))
     {
         if (!(objcomman.ValidateEmail(model.Email)))
         {
             DisplayMessage("Emaiil is Not Valid", "", 'w');
             return(View(model));
         }
         if (model.Contact != "" && model.Contact.Length != 10)
         {
             DisplayMessage("Contact is Not Valid", "", 'w');
             return(View(model));
         }
         if (!(model.File.ContentLength > 0))
         {
             DisplayMessage("Upload User Image", "", 'w');
             return(View(model));
         }
         model.OTP             = GenerateOtp.Random();
         model.DisplayPassword = Common.Generate(8);
         model.Password        = Common.EncodePasswordToBase64(model.DisplayPassword);
         byte [] data = new byte[model.File.ContentLength];
         model.File.InputStream.Read(data, 0, model.File.ContentLength);
         model.ImageData = data;
         var    lst  = new DataLayer().RegisterUser <Users>(model).First();
         string Body = "Your OTP IS :" + lst.OTP + " . Please Verify in order to Complete your Registratin";
         objcomman.SendMail(lst.Email, "OTP Verification", Body);
         DisplayMessage("User Registered Successfully", "OTP has been Sent on your Registered Email Id Please Check and Verify. ", 's');
         TempData["Page"] = "OTP";
         return(View(lst));
     }
     else
     {
         DisplayMessage("Please Fill All Fields", "", 'w');
         return(View());
     }
 }
        public async Task <IActionResult> ResendOtp([FromBody] GetOTP getOtp)
        {
            int userId = 0;
            var otp    = new GenerateOtp();

            if (string.IsNullOrEmpty(getOtp.PhoneNumber))
            {
                return(BadRequest(new
                {
                    Response = new JsonResponseHandler
                    {
                        IsSuccess = false,
                        ErrorMessage = AppStrings.PhoneNumberOrCountryCodeEmpty
                    }
                }));
            }

            // Generating OTP Passcode
            var otpPassCode = otp.GetOtpNumber();
            var otpSms      = AppStrings.ConnectApi + otpPassCode;

            // Get Number Of OTP Attemps
            int numberOfAttempts = await _service.GetNumberOfAttempts(getOtp.PhoneNumber);

            //Get UserID with PhoneNumber
            var user = await _service.GetUserByPhoneNumber(getOtp.PhoneNumber);

            if (user != null)
            {
                userId = user.Id;
            }

            //Get UserOTP with PhoneNumber
            var userOtp = await _service.GetUserOtpInfoByPhoneNumber(getOtp.PhoneNumber);

            // Exceeded OTP Attempts Response
            if (numberOfAttempts > AppConstants.OtpNumberOfAttempts ||
                userOtp.CreatedDate.AddMinutes(AppConstants.DurationUntilOtpCodeActive) < DateTime.UtcNow)
            {
                return(BadRequest(new
                {
                    Response = new JsonResponseHandler
                    {
                        ErrorMessage = AppStrings.OtpCodeAttemptsExceeded,
                        IsSuccess = false
                    }
                }));
            }

            ++numberOfAttempts;

            //To Save Otp Code Against PhoneNumber
            await _service.SaveResentOtpAgainstPhoneNumber(otpPassCode, getOtp.PhoneNumber, numberOfAttempts, userId);

            //Send OTP Code To Mobile
            var twilioSmsHelper = new TwilioSmsSendHelper();
            var responseTwilio  = await twilioSmsHelper.SendSms(otpSms, getOtp.PhoneNumber);

            return(Ok(new
            {
                Code = otpPassCode,
                Response = new JsonResponseHandler
                {
                    IsSuccess = true,
                    ErrorMessage = responseTwilio
                }
            }));
        }
        public async Task <IActionResult> SendOtpCode([FromBody] GetOTP getOtp)
        {
            int userId           = 0;
            int numberOfAttempts = 1;

            var otp = new GenerateOtp();

            if (string.IsNullOrEmpty(getOtp.PhoneNumber))
            {
                return(BadRequest(new
                {
                    Response = new JsonResponseHandler
                    {
                        IsSuccess = false,
                        ErrorMessage = AppStrings.PhoneNumberOrCountryCodeEmpty
                    }
                }));
            }

            // Check if Phone Number is Digits Only
//            var checkPhoneNumberCorrect = _service.IsDigitsOnly(getOtp.PhoneNumber);
//            if (!checkPhoneNumberCorrect)
//            {
//                return BadRequest(new
//                {
//                    Response = new JsonResponseHandler
//                    {
//                        IsSuccess = false,
//                        ErrorMessage = AppStrings.InvalidPhoneNumberOrCountryCode,
//                    }
//                });
//            }


            // Generating OTP Passcode
            var otpPassCode = otp.GetOtpNumber();
            var otpSms      = AppStrings.ConnectApi + otpPassCode;

            //Get UserID with PhoneNumber
            var user = await _service.GetUserByPhoneNumber(getOtp.PhoneNumber);

            if (user != null)
            {
                userId = user.Id;
            }


            //To Save Otp Code Against PhoneNumber
            await _service.SaveGeneratedOtpAgainstPhoneNumber(otpPassCode, getOtp.PhoneNumber, numberOfAttempts,
                                                              userId);

            //Send OTP Code To Mobile
            var twilioSmsHelper = new TwilioSmsSendHelper();
            var responseTwilio  = await twilioSmsHelper.SendSms(otpSms, getOtp.PhoneNumber);


            return(Ok(new
            {
                Code = otpPassCode,
                Response = new JsonResponseHandler
                {
                    IsSuccess = true,
                    ErrorMessage = responseTwilio,
                }
            }));
        }