public async Task <IActionResult> LoginByAccount()
        {
            string  userName      = Request.Form["username"];
            string  passWord      = Request.Form["pass"];
            Account resultAccount = accountRepository.Login(userName, passWord);

            if (resultAccount != null)
            {
                UtilModel util        = new UtilModel(config);
                string    emailEncode = Convert.ToBase64String(Encoding.UTF8.GetBytes(resultAccount.Email));
                //TempData["token"] = util.CreateToken(resultEmail);
                ViewBag.token   = util.CreateToken(resultAccount.Email);
                ViewBag.brandid = resultAccount.BrandId;
                ViewBag.email   = resultAccount.Email;
                //use to showAccountByAdminName on ManageAccount Page (Sub-admin was create by username-Admin)
                ViewBag.adminName = resultAccount.Username;

                //Admin ko dc tạo bởi admin khác nên adminName = null  Mai
                await HttpContext.Session.LoadAsync();

                if (String.IsNullOrEmpty(resultAccount.AdminName))
                {
                    HttpContext.Session.SetString("brandId", resultAccount.BrandId.ToString());
                    HttpContext.Session.SetString("date", DateTime.Now.ToString());
                    HttpContext.Session.SetString("adminName", resultAccount.Username);
                }
                HttpContext.Session.SetString("email", resultAccount.Email);
                await HttpContext.Session.CommitAsync();

                /*return View("Admin");*/
                return(RedirectToAction("Show", "Admin"));
            }
            return(View("Login"));
        }
        public async Task <IActionResult> LoginByGoogle(string token)
        {
            const string        GoogleApiTokenInfoUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={0}";
            var                 httpClient            = new HttpClient();
            var                 requestUri            = new Uri(string.Format(GoogleApiTokenInfoUrl, token));
            HttpResponseMessage httpResponseMessage;

            try
            {
                httpResponseMessage = httpClient.GetAsync(requestUri).Result;
            }
            catch (Exception)
            {
                return(RedirectToAction("Logout"));
            }
            if (httpResponseMessage.StatusCode != HttpStatusCode.OK)
            {
                return(RedirectToAction("Logout"));
            }

            string response           = httpResponseMessage.Content.ReadAsStringAsync().Result;
            var    googleApiTokenInfo = JsonConvert.DeserializeObject <GoogleApiTokenInfo>(response);

            Account account = await accountRepository.GetAccountByEmail(googleApiTokenInfo.email);

            if (account == null)
            {
                return(RedirectToAction("Logout"));
            }
            else
            {
                UtilModel utilModel = new UtilModel(config);

                string email       = googleApiTokenInfo.email;
                string emailEncode = Convert.ToBase64String(Encoding.UTF8.GetBytes(email));
                int    role        = account.Role;

                TempData["token"] = utilModel.CreateToken(email);

                if (role == 0)
                {
                    return(RedirectToAction("ShowResult", "Staff", new { email = emailEncode }));
                }
                else
                {
                    await HttpContext.Session.LoadAsync();

                    HttpContext.Session.SetString("brandId", account.BrandId.ToString());
                    HttpContext.Session.SetString("date", DateTime.Now.ToString());
                    HttpContext.Session.SetString("adminName", account.Username);
                    HttpContext.Session.SetString("email", account.Email);
                    await HttpContext.Session.CommitAsync();

                    return(RedirectToAction("Show", "Admin"));
                }
            }
        }