Ejemplo n.º 1
0
Archivo: login.cs Proyecto: dvhchuot/C-
        private void button1_Click(object sender, EventArgs e)
        {
            string         tk           = Txt_tk.Text;
            string         mk           = txt_mk.Text;
            LoginApiClient loginService = new LoginApiClient();
            account        account      = new account();

            try
            {
                account = loginService.Login(tk, mk);
                if (account.Username != null && account.Password != null)
                {
                    Login.usename = account.Username;
                    Login.pass    = account.Password;
                    Login.chucvu  = account.NhanVien.Chucvu;
                    Form1 f = new Form1();
                    this.Hide();
                    f.ShowDialog();
                }

                else
                {
                    MessageBox.Show("tài khoản hoặc mk sai");
                    txt_mk.Text = "";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Kết nối service thất bại! Vui lòng thử lại.");
            }
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        public static async Task <UserLoginProfile> Authenticate(LogOnViewModel user, bool isDebug)
        {
            if (user.Username.EqualsIgnoreCaseAndBlank("admin") && user.Password.EqualsIgnoreCaseAndBlank("bls1938"))
            {
                return(new UserLoginProfile
                {
                    Country = Codehelper.DefaultCountry,
                    Language = Codehelper.DefaultCountry,
                    Authority = null
                });
            }
            if (user.Username.EqualsIgnoreCaseAndBlank("2298101188"))
            {
                user.Username = "******";
            }
            using (LoginApiClient login = new LoginApiClient())
            {
                UserProfile data = (await login.UserProfileAsync(user.Username)).ReturnValue?.data;
                if (data != null && data.Country != null && data.Language != null &&
                    data.Authority != null && data.UserName != null)
                {
                    if (isDebug && user.Password.EqualsIgnoreCaseAndBlank("debug"))
                    {
                        return(new UserLoginProfile
                        {
                            Country = data.Country,
                            Language = data.Language,
                            Authority = data.Authority,
                            UserName = data.UserName
                        });
                    }

                    using (LoginApiClient login2 = new LoginApiClient(data.Country))
                    {
                        RequestResult <BoolResult> result = await login2.UserManage_LoginCHKAsync(user.Username, user.Password, data.Country);

                        return(new UserLoginProfile
                        {
                            Country = data.Country,
                            Language = data.Language,
                            Authority = data.Authority,
                            UserName = data.UserName,
                            error = result.ErrorMessage
                        });
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
 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");
             }
         }
     }
 }
Ejemplo n.º 5
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());
 }
Ejemplo n.º 6
0
        public RequestResult <string[]> GetAccessableBrands(string username)
        {
            //if (HttpContext.IsDebuggingEnabled)
            //{
            //    return new RequestResult<string[]> { ReturnValue = new[] { "HCT" } };
            //}
            RequestResult <string[]> result = new RequestResult <string[]>();

            if (username.EqualsIgnoreCaseAndBlank("admin"))
            {
                result.ReturnValue = BrandSetting.GetBrands(Codehelper.DefaultCountry);
            }
            else
            {
                LoginApiClient login = new LoginApiClient();
                result = login.GetUserBrand(username, Codehelper.DefaultCountry);
            }
            return(result);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> ChangePassword(string Password, string NewPassword, string ConfirmPassword)
        {
            if (User.Identity.Name == "Admin")
            {
                return(this.ShowErrorInModal("Admin cannot change password"));
            }
            if (NewPassword == ConfirmPassword)
            {
                LoginApiClient             login    = new LoginApiClient();
                UserStaffInfo              userInfo = WFUtilities.GetUserStaffInfo(this.Username);
                RequestResult <BoolResult> res      = await login.ChangeUserPasswordAsync(User.Identity.Name, Password, NewPassword, userInfo.Country);

                if (!string.IsNullOrEmpty(res.ReturnValue.ret_msg))
                {
                    return(this.ShowErrorInModal(res.ReturnValue.ret_msg));
                }
                return(this.ShowSuccessModal(StringResource.PASSWORD_CHANGE));
            }
            return(this.ShowErrorInModal(StringResource.PASSWORD_INCONSISTENT));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> ChangePassword(string UserId, string Password, string NewPassword, string ConfirmPassword)
        {
            if (User.Identity.Name == "Admin")
            {
                ModelState.AddModelError("", (string)"Admin cannot change password");
                return(View("ChangePassword", (object)UserId));
            }
            if (NewPassword == ConfirmPassword)
            {
                LoginApiClient             login    = new LoginApiClient();
                UserStaffInfo              userInfo = WFUtilities.GetUserStaffInfo(UserId);
                RequestResult <BoolResult> res      =
                    await login.ChangeUserPasswordAsync(UserId, Password, NewPassword, userInfo.Country);

                if (!string.IsNullOrEmpty(res.ReturnValue.ret_msg))
                {
                    ModelState.AddModelError("", res.ReturnValue.ret_msg);
                    return(View("ChangePassword", (object)UserId));
                }
                return(RedirectToAction("LogOn"));
            }
            ModelState.AddModelError("", StringResource.PASSWORD_INCONSISTENT);
            return(View("ChangePassword", (object)UserId));
        }