public async Task <ActionResult> TokenLogin(string a, int e)
        {
            //APIDTO.APIToken oauthToken = new APIDTO.APIToken() { access_token = a, expires_in = e };
            APIDTO.APIUserInformation apiUser = null;
            string backendServiceUrl          = System.Configuration.ConfigurationManager.AppSettings["BackendServiceUrl"].ToString();
            string errMsg         = string.Empty;
            string errDescription = string.Empty;

            // get user info
            //apiUser = JsonConvert.DeserializeObject<APIDTO.APIUserInformation>(Customize.Helper.PostRequestAPI(backendServiceUrl + "api/account/getuserinfo", string.Empty, "application/json", "application/json", "bearer " + oauthToken.access_token, out errMsg, out errDescription));
            apiUser = JsonConvert.DeserializeObject <APIDTO.APIUserInformation>(Customize.Helper.GetAPIUserData(backendServiceUrl + "api/account/getuserinfo", a, out errMsg));
            if (!string.IsNullOrEmpty(errMsg))
            {
                throw new Exception(errMsg);
            }
            if (apiUser.Message.Type == APIDTO.NotificationType.Error)
            {
                throw new Exception(apiUser.Message.Message);
            }

            // all gone well, start registering user and permission
            CustomIdentity user = new CustomIdentity()
            {
                Id       = apiUser.Data.UserId.ToString(),
                UserName = apiUser.Data.UserName,
                Email    = apiUser.Data.Email
            };

            await SignInAsync(user, false);

            // register custom information to session
            Session[Customize.Common.ProjectDefinition.TOKEN_SESSION]     = a;
            Session[Customize.Common.ProjectDefinition.USER_INFO_SESSION] = apiUser;
            return(RedirectToAction("Index", "DashBoard", new object()
            {
            }));
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                CustomIdentity user = null;

                string backendServiceUrl = System.Configuration.ConfigurationManager.AppSettings["BackendServiceUrl"].ToString();
                string providedLoginInfo = "grant_type=password&username="******"&password="******"+", "[plus]"));
                //APIDTO.APIToken oauthToken = null;
                string token = string.Empty;
                APIDTO.APIUserInformation apiUser = null;
                string errMsg         = string.Empty;
                string errDescription = string.Empty;

                // login - get token
                //oauthToken = JsonConvert.DeserializeObject<APIDTO.APIToken>(Customize.Helper.PostRequestAPI(backendServiceUrl + "token", providedLoginInfo, "application/json", "application-x-www-form-urlencode", string.Empty, out errMsg, out errDescription));
                token = Customize.Helper.GetAPIToken(backendServiceUrl + "token", model.Username, Url.Encode(model.Password.Replace("+", "[plus]")), out errMsg);
                if (!string.IsNullOrEmpty(errMsg))
                {
                    switch (errMsg)
                    {
                    case "IncorrectLogin":
                        ModelState.AddModelError("", "Username or password is invalid!");
                        break;

                    case "AccountDisabled":
                        ModelState.AddModelError("", "Account has been disabled!");
                        break;

                    case "ChangePassword":
                        return(RedirectToAction("ChangePassword", "Account", new { username = model.Username }));
                    }
                    return(View(model));
                }
                else
                {
                    // get user info
                    //apiUser = JsonConvert.DeserializeObject<APIDTO.APIUserInformation>(Customize.Helper.PostRequestAPI(backendServiceUrl + "api/account/getuserinfo", providedLoginInfo, "application/json", "application/json", "bearer " + token, out errMsg, out errDescription));
                    apiUser = JsonConvert.DeserializeObject <APIDTO.APIUserInformation>(Customize.Helper.GetAPIUserData(backendServiceUrl + "api/account/getuserinfo", token, out errMsg));
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        ModelState.AddModelError("", errMsg);
                        return(View(model));
                    }
                    if (apiUser.Message.Type == APIDTO.NotificationType.Error)
                    {
                        ModelState.AddModelError("", apiUser.Message.Message);
                        return(View(model));
                    }

                    // all gone well, start registering user and permission
                    user = new CustomIdentity()
                    {
                        Id       = apiUser.Data.UserId.ToString(),
                        UserName = apiUser.Data.UserName,
                        Email    = apiUser.Data.Email
                    };
                    await SignInAsync(user, false);

                    // register custom information to session
                    Session[Customize.Common.ProjectDefinition.TOKEN_SESSION]     = token;
                    Session[Customize.Common.ProjectDefinition.USER_INFO_SESSION] = apiUser;

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "DashBoard", new object()
                        {
                        }));
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }