Beispiel #1
0
        public async Task <ActionResult> ValidateToken(string token, string phone, string tokenDevice)
        {
            //if (!tokenOtpDA.ValidateToken(token, phone, (int)TokenOtpType.Authen))
            //{
            //    return Json(new JsonMessage(1000, "Thông tin đăng nhập không hợp lệ"), JsonRequestBehavior.AllowGet);
            //}
            //tokenOtpDA.UpdateIsUsed(token, phone);
            //await tokenOtpDA.SaveAsync();
            var customer = _agencyDa.GetByPhone(phone);
            var key      = Guid.NewGuid();
            IAuthContainerModel model = new JWTContainerModel()
            {
                Claims = new Claim[]
                {
                    new Claim("Phone", customer.Phone),
                    new Claim("Type", "Token"),
                    new Claim("ID", customer.ID.ToString()),
                },
                ExpireMinutes = 10,
            };
            IAuthContainerModel modelRefreshToken = new JWTContainerModel()
            {
                Claims = new Claim[]
                {
                    new Claim("Phone", customer.Phone),
                    new Claim("Type", "RefreshToken"),
                    new Claim("key", key.ToString()),
                    new Claim("ID", customer.ID.ToString()),
                },
                ExpireMinutes = 60 * 24 * 30,
            };
            var tokenResponse = JWTService.Instance.GenerateToken(model);
            var refreshToken  = JWTService.Instance.GenerateToken(modelRefreshToken);

            _agencyDa.InsertToken(new TokenRefresh()
            {
                GuidId = key
            });
            customer.TokenDevice = tokenDevice;
            _agencyDa.Save();
            return(Json(new BaseResponse <CustomerAppIG4Item>()
            {
                Code = 200, Erros = false, Message = "", Data = new CustomerAppIG4Item()
                {
                    Token = tokenResponse, RefreshToken = refreshToken, ID = customer.ID, IsPrestige = customer.IsFdi, IsVerify = customer.IsVerify, IsBank = customer.IsBank, IsActive = customer.IsActive
                }
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UpdateAgencyQR(string phone)
        {
            try
            {
                var agency = _agencyDa.GetByPhone(phone);
                var cus    = customerDA.GetById(CustomerId);
                cus.AgencyID = agency.ID;
                customerDA.Save();
            }
            catch (Exception e)
            {
                return(Json(new JsonMessage {
                    Code = 404, Message = e.ToString()
                }));
            }

            return(Json(new JsonMessage {
                Code = 200, Message = ""
            }));
        }