Exemplo n.º 1
0
        public async Task <ActionResult> Login(string phone)
        {
            try
            {
                //if (!_agencyDa.CheckExitsByPhone(phone))
                //{
                //    _agencyDa.Add(new DN_Agency()
                //    {
                //        Phone = phone,
                //        IsDelete = false,
                //        CreateDate = DateTime.Now.TotalSeconds(),
                //    });
                //    customerDA.Save();
                //}
                var otp     = FDIUtils.RandomOtp(4);
                var otppost = new PostOtpLoginAppIG4()
                {
                    msisdn    = phone.Remove(0, 1).Insert(0, "84"),
                    brandname = "G-STORE",
                    msgbody   = "IG4: Ma xac minh cua ban la " + otp,
                    user      = "******",
                    pass      = "******",
                    charset   = "8"
                };
                var url    = "http://123.31.20.167:8383/restservice/";
                var result = await PostDataAsync <List <ResultotpAppIG4> >(url, otppost);

                if (result.FirstOrDefault()?.Result.code == "200")
                {
                    tokenOtpDA.Add(new TokenOtp()
                    {
                        ObjectId    = phone,
                        Token       = otp,
                        IsDeleted   = false,
                        IsUsed      = false,
                        TypeToken   = (int)TokenOtpType.Authen,
                        DateCreated = DateTime.Now,
                    });
                    tokenOtpDA.Save();
                }
                else
                {
                    return(Json(new JsonMessage(-1, "Gửi mã OTP thất bại"), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new JsonMessage(-2, e.ToString()), JsonRequestBehavior.AllowGet));
            }

            return(Json(new JsonMessage(200, "Ok"), JsonRequestBehavior.AllowGet));
        }