public ActionResult GetOTPNo(string mobileNo)
        {
            try
            {
                String no     = null;
                Random random = new Random();
                for (int i = 0; i < 1; i++)
                {
                    int n = random.Next(0, 999);
                    no += n.ToString("D4") + "";
                }
                // ApplicationUserViewModelDtos objApplicationUserViewModelDtos = new ApplicationUserViewModelDtos();
                var obj = _unitofWork.applicationUser.GetAll().Where(x => x.PhoneNumber == mobileNo.Trim()).FirstOrDefault();

                if (obj != null)
                {
                    var Dtosobj = new ApplicationUserViewModelDtos();
                    Dtosobj = _mapper.Map <ApplicationUserViewModelDtos>(obj);


                    return(Ok(Dtosobj));
                }
                else
                {
                    #region "sms"
                    try
                    {
                        string Password     = "******";
                        string Msg          = "OTP :" + no + ".  Please Use this OTP.This is usable once and expire in 10 minutes";;
                        string userdetails  = "ezacus";
                        string OPTINS       = "MSGSAY";
                        string MobileNumber = mobileNo;
                        // string type = "3";
                        string template_id = "123";
                        string strUrl      = "https://bulksms.co/sendmessage.php?&user="******"&password="******"&mobile=" + MobileNumber + "&message=" + Msg + "&sender=" + OPTINS + "&type=" + 3 + "&template_id=" + template_id;
                        ServicePointManager.Expect100Continue = true;
                        ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                        System.Net.WebRequest request  = System.Net.WebRequest.Create(strUrl);
                        HttpWebResponse       response = (HttpWebResponse)request.GetResponse();
                        Stream       s          = (Stream)response.GetResponseStream();
                        StreamReader readStream = new StreamReader(s);
                        string       dataString = readStream.ReadToEnd();
                        s.Close();
                        readStream.Close();
                        response.Close();
                    }

                    catch
                    { }
                    #endregion
                    ApplicationUserViewModelDtos objApplicationUserViewModelDtos = new ApplicationUserViewModelDtos();
                    objApplicationUserViewModelDtos.OTPNo = no;
                    return(Ok(objApplicationUserViewModelDtos));
                }
            }
            catch (Exception obj)
            {
                return(BadRequest());
            }
        }
        public async Task <ActionResult> UserLogin([FromBody] LoginViewModel model)
        {
            if (model == null)
            {
                return(BadRequest(ModelState));
            }

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

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

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

                if (obj == null)
                {
                    return(NotFound());
                }
                else
                {
                    var Dtosobj = new ApplicationUserViewModelDtos();
                    Dtosobj = _mapper.Map <ApplicationUserViewModelDtos>(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 #3
0
        public ActionResult GetOTPNo(string mobileNo)
        {
            try
            {
                String no     = null;
                Random random = new Random();
                for (int i = 0; i < 1; i++)
                {
                    int n = random.Next(0, 999);
                    no += n.ToString("D4") + "";
                }
                // ApplicationUserViewModelDtos objApplicationUserViewModelDtos = new ApplicationUserViewModelDtos();
                var obj = _unitofWork.applicationUser.GetAll().Where(x => x.PhoneNumber == mobileNo.Trim()).FirstOrDefault();

                if (obj != null)
                {
                    //var Dtosobj = new ApplicationUserViewModelDtos();
                    //Dtosobj = _mapper.Map<ApplicationUserViewModelDtos>(obj);
                    string myJson = "{\"message\": " + "\"This Mobile Number Allready Exist\"" + "}";


                    return(StatusCode(409, myJson));
                    //  return Ok(Dtosobj);
                }
                else
                {
                    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);

                    ApplicationUserViewModelDtos objApplicationUserViewModelDtos = new ApplicationUserViewModelDtos();
                    objApplicationUserViewModelDtos.OTPNo       = no;
                    objApplicationUserViewModelDtos.PhoneNumber = mobileNo;
                    return(Ok(objApplicationUserViewModelDtos));
                    // return Ok(objApplicationUserViewModelDtos);
                }
            }
            catch (Exception obj)
            {
                return(BadRequest());
            }
        }
        public ActionResult GetUserDetails(String id)
        {
            // var affilatereg = _db.applicationUsers.FirstOrDefault(u => u.Id == model.id);
            var obj = _unitofWork.applicationUser.GetAll().Where(x => x.Id == id).FirstOrDefault();

            //var obj = _unitofWork.applicationUser.GetAll().Where(x => x.Id == id).FirstOrDefault();

            if (obj == null)
            {
                return(NotFound());
            }
            else
            {
                var Dtosobj = new ApplicationUserViewModelDtos();
                Dtosobj = _mapper.Map <ApplicationUserViewModelDtos>(obj);
                return(Ok(Dtosobj));
            }

            return(Ok(obj));
        }