private string GetReturnData(SystemUserLoginItem user) { var lstProvider = ConfigurationManager.AppSettings["DefaultDomain"].Split(',').ToList(); if (lstProvider.Contains(user.Provider)) { string token = ConfigurationManager.AppSettings["DefaultToken"]; string timeLogin = DateTime.Now.ToString(); string hashCode = CryptoEngine.Md5x2(user.UserName + timeLogin + token); string returnData = CryptorEngine.Encrypt(string.Format("{0}#{1}#{2}#{3}", 100, user.UserName, timeLogin, hashCode), token); return(returnData); } else { var userClientInfomation = objUserClientIdDA.GetListByUsernameAndDomain(user.UserName, user.Provider); if (userClientInfomation.Count() < 1) { return("101"); } var lstUserName = string.Join(",", userClientInfomation.Select(p => p.UserIDClient)); string token = userClientInfomation.FirstOrDefault().Token; string timeLogin = DateTime.Now.ToString(); string hashCode = CryptoEngine.Md5x2(lstUserName + timeLogin + token); string returnData = CryptorEngine.Encrypt(string.Format("{0}#{1}#{2}#{3}", 100, lstUserName, timeLogin, hashCode), token); return(returnData); } }
public ActionResult LoginCallback(string returnUrl) { SystemUserLoginItemExtend item = new SystemUserLoginItemExtend() { Remember = true, ReturnUrl = returnUrl, Provider = GetDomain(returnUrl) }; if (User != null) { SystemUserLoginItem user = new SystemUserLoginItem(); user.UserName = User.Account; user.Provider = GetDomain(returnUrl); #region Xử lý nếu User đã đăng xuất tại client var clientDA = new ClientDA(); var client = clientDA.GetByDomain(user.Provider); //lấy ra client mà user đang sử dụng if (client != null) { var userClientDa = new UserClientDA(); var userClient = userClientDa.GetListByUsernameAndClientId(User.Account, client.Id); if (userClient != null) //check nếu user có account của client đấy không { if (userClient.IsLogin == false) { ViewBag.ReturnUrl = returnUrl; return(View(item)); } } else { return(Redirect(returnUrl)); } } #endregion if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(string.Format("{0}{1}{2}", returnUrl, "?data=", HttpUtility.UrlEncode(GetReturnData(user))))); } else { return(Redirect(ConfigurationManager.AppSettings["DefaultReturnUrl"])); } } ViewBag.ReturnUrl = returnUrl; return(View(item)); }