public async Task <JsonResult> OTPVerificationCodeCheck(ConfirmOTPModel oTPModel)
        {
            if (oTPModel.UserName != null && oTPModel.Password != null && oTPModel.VarificationCode > 99999)
            {
                try
                {
                    string userName        = _protector.Unprotect(oTPModel.UserName);
                    string password        = _protector.Unprotect(oTPModel.Password);
                    var    userLogin       = _db.UserLogin.FirstOrDefault(a => a.UserName == userName && a.Password == password);
                    var    userInformation = _db.UserInformation.FirstOrDefault(a => a.Id == userLogin.UserId);
                    if (userLogin.Otpcode == oTPModel.VarificationCode)
                    {
                        await UserSignIn(userLogin, userInformation, oTPModel.ReturnUrl, oTPModel.RememberMe == "true"?true : false);

                        userLogin.IsLoginBefore    = oTPModel.IsLoginBefore == "false"? true : userLogin.IsLoginBefore;//if first login
                        userLogin.Otpcode          = null;
                        _db.Entry(userLogin).State = EntityState.Modified;
                        _db.SaveChanges();
                        return(Json("success"));
                    }
                }
                catch (Exception)
                {
                    return(Json(false));
                }
            }
            return(Json(false));
        }
        public JsonResult ConfirmOTP4Digit(ConfirmOTPModel oTPModel)
        {
            if (oTPModel.UserName != null && oTPModel.Password != null && oTPModel.Last4Digit != null)
            {
                try
                {
                    string userName        = _protector.Unprotect(oTPModel.UserName);
                    string password        = _protector.Unprotect(oTPModel.Password);
                    var    userLogin       = _db.UserLogin.FirstOrDefault(a => a.UserName == userName && a.Password == password);
                    var    userInformation = _db.UserInformation.FirstOrDefault(a => a.Id == userLogin.UserId);
                    if (userInformation.MobileNumber.Substring(7) == oTPModel.Last4Digit)
                    {
                        if (userLogin.Otpcode > 99999)
                        {
                            SendSMS.DoSendSMS(new SendSMSModel
                            {
                                Message      = $"{userLogin.Otpcode} is your login code. Don't reply this message.",
                                MobileNumber = $"88{userInformation.MobileNumber}"
                            });
                        }
                        else
                        {
                            Random rnd      = new Random();
                            int    rnd_Code = rnd.Next(100000, 999999);//6digit random number
                            SendSMS.DoSendSMS(new SendSMSModel
                            {
                                Message      = $"{rnd_Code} is your login code. Don't reply this message.",
                                MobileNumber = $"88{userInformation.MobileNumber}"
                            });

                            userLogin.Otpcode          = rnd_Code;
                            _db.Entry(userLogin).State = EntityState.Modified;
                            _db.SaveChanges();
                        }

                        return(Json("success"));
                    }
                }
                catch (Exception)
                {
                    return(Json(false));
                }
            }
            return(Json(false));
        }
Beispiel #3
0
        public IHttpActionResult confirmOTP(ConfirmOTPModel data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var userNew = _service.confirmOTP(data);

                return(Ok <FlutterUserModel>(userNew));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public FlutterUserModel confirmOTP(ConfirmOTPModel data)
        {
            if (!checkUser(data.phone.Trim()))
            {
                base.register(new UserRegisterModel()
                {
                    phone = data.phone.Trim(), password = data.otp
                });
            }
            else
            {
                changePassword(data.phone.Trim(), data.otp);
            }

            return(getUser(new UserRegisterModel()
            {
                phone = data.phone.Trim(), password = data.otp
            }));
        }
 //[Authorize]
 public IActionResult ConfirmOTP(string q, string p, string IsLoginBefore, string RememberMe, string ReturnUrl)
 {
     if (q != null && p != null)
     {
         try
         {
             string userName        = _protector.Unprotect(q);
             string password        = _protector.Unprotect(p);
             var    userLogin       = _db.UserLogin.FirstOrDefault(a => a.UserName == userName && a.Password == password);
             var    userInformation = _db.UserInformation.FirstOrDefault(a => a.Id == userLogin.UserId);
             if (!(userLogin.IsConfirmed || userInformation.Role > 0))
             {
                 return(View(new ConfirmOTPModel {
                     Error = true
                 }));
             }
             var OTP = new ConfirmOTPModel
             {
                 UserName      = q,
                 Password      = p,
                 IsLoginBefore = IsLoginBefore,
                 RememberMe    = RememberMe,
                 ReturnUrl     = ReturnUrl,
                 MobileNumber  = userInformation.MobileNumber.Substring(0, 7),
                 Error         = false
             };
             return(View(OTP));
         }
         catch
         {
             return(View(new ConfirmOTPModel {
                 Error = true
             }));
         }
     }
     return(View(new ConfirmOTPModel {
         Error = true
     }));
 }