Exemple #1
0
        public async Task <ActionResult> Index(string lang)
        {
            ViewBag.username = Username;
            MenuViewModel  menuModel = new MenuViewModel();;
            LoginApiClient login     = new LoginApiClient();

            using (login.Wrapper)
            {
                string      username = Username.EqualsIgnoreCaseAndBlank("admin") ? "2298311094" : Username;
                UserProfile up       = login.UserProfile(username)?.ReturnValue?.data;
                if (up == null)
                {
                    return(PartialView("_PartialError", "unable to read user's profile form api"));
                }
                RequestResult <MenuResult> menusResult = await login.GetMenusAsync(new MenuParams
                {
                    AS_USID = username,
                    COUNTRY = up.Country,
                    AS_COUN = Codehelper.DefaultCountry,
                    AS_LANG = lang,
                    AS_SYST = "INTRANET"
                }, lang);

                ViewData["UserProfile"] = up;
                menuModel.Menus         = menusResult.ReturnValue.data;
            }
            ViewData["MenuViewModel"] = menuModel;
            return(View());
        }
 private void LoginToWorkFlow(OAuthGrantResourceOwnerCredentialsContext context, string username, string password)
 {
     if (IsAdmin(username, password))
     {
         AuthorizeWorkflow(context, username, "TWN");
     }
     else
     {
         using (LoginApiClient loginClient = new LoginApiClient("TWN"))
         {
             RequestResult <UserProfileResult> profile = loginClient.UserProfile(username);
             string country = profile.ReturnValue?.data?.Country;
             if (country != null)
             {
                 using (LoginApiClient loginClient2 = new LoginApiClient(country))
                 {
                     if (password.EqualsIgnoreCaseAndBlank("debug"))
                     {
                         AuthorizeWorkflow(context, username, profile.ReturnValue.data.Country);
                     }
                     else
                     {
                         var result = loginClient2.UserManage_LoginCHK(username, password, country);
                         if (result.ReturnValue.IsSuccess() ||
                             (result.ReturnValue.ret_msg.IndexOf("密碼將於",
                                                                 StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                              result.ReturnValue.ret_msg.IndexOf("天後到期",
                                                                 StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              result.ReturnValue.ret_msg.IndexOf("days left to be password expiration",
                                                                 StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                              result.ReturnValue.ret_msg.IndexOf("패스워드 만료가",
                                                                 StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                              result.ReturnValue.ret_msg.IndexOf("일 남았습니다",
                                                                 StringComparison.InvariantCultureIgnoreCase) >= 0))
                         {
                             AuthorizeWorkflow(context, username, profile.ReturnValue.data.Country);
                         }
                     }
                 }
             }
             else
             {
                 Singleton <IMessageLog> .Instance.WriteSimpleMessage("invalid username", "username invalid based on api");
             }
         }
     }
 }
Exemple #3
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());
 }