public ActionResult Submit2FA(string username, string pinCode)
        {
            var resultValidate = _twoAuthFact.ValidateTwoFactorPIN_2FA(username, pinCode);

            if (resultValidate == false)
            {
                ModelState.AddModelError("", "Validate invalid. Please confirm again");
                return(RedirectToAction("Confirm2FA", "EmailFunc", new { username = username }));
            }
            else
            {
                var _user = _userManager.FindByName(username);
                //cập nhật ip vào db web
                _user.IP_login         = IPClient.getIP();
                _user.TwoFactorEnabled = true;
                _userManager.Update(_user);
                ModelState.AddModelError("", "Validate success. Please login");
                return(RedirectToAction("LoginAferConfrim_2faAsync", "Account", new { username = _user.UserName }));
            }
        }
Example #2
0
 public JsonResult Validate_2fa(string username, string pinCode)
 {
     try
     {
         log.Info("Start validate 2FA");
         var result = _twoFactAuth.ValidateTwoFactorPIN_2FA(username, pinCode);
         if (result == true)
         {
             log.Info("validate 2FA success");
             return(Json(new { Message = "Validate success!!", status = "Success" }));
         }
         else
         {
             log.Info("validate 2FA failed");
             return(Json(new { Message = "Validate unsuccessful", status = "Failed" }));
         }
     }
     catch (Exception ex)
     {
         log.Info("Error exception: " + ex);
         return(Json(new { Message = "Validate unsuccessful", status = "Failed" }));
     }
 }
 public JsonResult Enable_2FA(string username, string pinCode)
 {
     try
     {
         var resultEnable = _twoFact.ValidateTwoFactorPIN_2FA(username, pinCode);
         if (resultEnable == true)
         {
             var user = _userManager.FindByName(username);
             user.TwoFactorEnabled = true;
             _userManager.Update(user);
             log.Info(DateTime.Now + "_Start Validate success 2FA");
             return(Json(new { Message = "Enable success", Status = 1 }));
         }
         else
         {
             return(Json(new { Message = "Enable unsuccessful", Status = -1 }));
         }
     }
     catch (Exception ex)
     {
         log.Info("ERROR Exception_" + DateTime.Now + ":" + ex);
         return(Json(new { Message = "ERROR Validate 2FA", Status = -1 }));
     }
 }