コード例 #1
0
 public ActionResult LogOn(string token)
 {
     if (!string.IsNullOrWhiteSpace(token))
     {
         LoginProfile item = LoginProfile.Parse(token);
         if (item != null)
         {
             LoginApiClient login = new LoginApiClient();
             using (login.Wrapper)
             {
                 UserProfile profile = login.UserProfile(item.Username).ReturnValue?.data;
                 if (item.Username.EqualsIgnoreCaseAndBlank("admin") || profile != null && profile.Authority?.Any(p => p.EqualsIgnoreCaseAndBlank(item.Country)) == true)
                 {
                     CmdResult res = UpdateUsername(item.Username, profile?.UserName).Result;
                     RequestResult <string[]> result = GetAccessableBrands(item.Username);
                     if (!string.IsNullOrWhiteSpace(result.ErrorMessage))
                     {
                         ModelState.AddModelError("", result.ErrorMessage);
                     }
                     else
                     {
                         FormsAuthenticationHelper.SetAuthCookie(item.Username.Trim(), false, string.Join(",", result.ReturnValue));
                         return(RedirectToAction("Index", "Home", new { lang = item.Lang }));
                     }
                 }
                 else
                 {
                     ModelState.AddModelError("", $"You are not allowed to visit {item.Country}'s intranet");
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", StringResource.INVALID_USERNAME_OR_PASSWORD);
         }
     }
     Response.Buffer          = true;
     Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
     Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
     Response.Expires      = 0;
     Response.CacheControl = "no-cache";
     Response.Cache.SetNoStore();
     return(View());
 }