Example #1
0
        public async Task <ActionResult> LoginWithMobileNoandPassword(string mobileNo, string password)//([FromBody] LoginViewModel model)
        {
            if (string.IsNullOrEmpty(mobileNo) || string.IsNullOrEmpty(password))
            {
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _signInManager.PasswordSignInAsync(mobileNo, password, true, lockoutOnFailure : false);

            if (result.Succeeded)
            {
                var obj = _unitofWork.applicationUser.GetAll().Where(x => x.PhoneNumber == mobileNo).FirstOrDefault();

                if (obj == null)
                {
                    return(NotFound());
                }
                else
                {
                    var Dtosobj = new LoginWhiteMobilenoandPasswordDtos();
                    Dtosobj = _mapper.Map <LoginWhiteMobilenoandPasswordDtos>(obj);
                    return(Ok(Dtosobj));
                }
            }
            else
            {
                if (result.IsLockedOut)
                {
                    ModelState.AddModelError("", "User account locked out.");
                    return(StatusCode(404, ModelState));
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return(StatusCode(404, ModelState));
                }
            }
        }
Example #2
0
        public async Task <ActionResult> LoginWithMobileNo(string mobileNo)
        {
            if (!string.IsNullOrEmpty(mobileNo))
            {
                var obj = _unitofWork.applicationUser.GetAll().Where(x => x.PhoneNumber == mobileNo).FirstOrDefault();
                if (obj == null)
                {
                    ModelState.AddModelError("", "Mobile No Not Found");
                    return(StatusCode(404, ModelState));
                }
                else
                {
                    String no     = null;
                    Random random = new Random();
                    for (int i = 0; i < 1; i++)
                    {
                        int n = random.Next(0, 999);
                        no += n.ToString("D4") + "";
                    }
                    string  Msg = "OTP :" + no + ".  Please Use this OTP.This is usable once and expire in 10 minutes";
                    SendSMS s   = new SendSMS();
                    bool    flg = s.smsSent(mobileNo, Msg);



                    var Dtosobj = new LoginWhiteMobilenoandPasswordDtos();
                    Dtosobj     = _mapper.Map <LoginWhiteMobilenoandPasswordDtos>(obj);
                    Dtosobj.OTP = no;
                    return(Ok(Dtosobj));
                }
            }
            else
            {
                ModelState.AddModelError("", "Please Enter Mobile No");
                return(StatusCode(404, ModelState));
            }
        }