Esempio n. 1
0
        public ActionResult Otp(OtpModel model)
        {
            ViewBag.ExpirationMinutes        = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.OtpExpirationMinutes);
            ViewBag.AttemptCount             = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.OtpMisMatchAttemptCount);
            model.IsAllowSafeComputerEnabled = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.AllowSafeComputerRemember) == "True";

            var userId = (long)Session["UserId"];

            model.UserId = userId;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool isOtpExpired;
            bool isAttemptExpired;
            var  isOtpVerified = _loginOtpService.VerifyOtp(model.Otp, userId, out isOtpExpired, out isAttemptExpired);

            if (isAttemptExpired)
            {
                _loginRepository.AssignUserLoginLock(userId);
                model.IsOtpVerified   = false;
                model.IsAccountLocked = true;
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Your account has been locked, due to too many attempts. Please contact " +
                                                                                  _settings.SupportEmail + " OR call us at " + _settings.PhoneTollFree);
                return(View(model));
            }
            if (isOtpExpired)
            {
                model.IsOtpVerified   = false;
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("The OTP is expired. Please use resend link to generate a new OTP.");
                return(View(model));
            }
            if (!isOtpVerified)
            {
                model.IsOtpVerified   = false;
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("The OTP entered is wrong. Please try again.");
                return(View(model));
            }
            if (model.MarkAsSafe)
            {
                var browserName  = Request.Browser.Browser + " " + Request.Browser.Version;
                var requestingIp = Request.UserHostAddress;
                var safeComputer = new SafeComputerHistory()
                {
                    BrowserType = browserName, ComputerIp = requestingIp, DateCreated = DateTime.Now, DateModified = DateTime.Now, IsActive = true, UserLoginId = userId
                };
                _safeComputerHistoryService.Save(safeComputer);
            }
            return(GoToDashboard(userId));
        }