예제 #1
0
        public static async Task <UserModel> ApiLoginClient(UserRequestLogin login)
        {
            var req = new RestRequest("api/Account/user/login", Method.POST);

            req.RequestFormat  = DataFormat.Json;
            req.JsonSerializer = JsonSerializer.Default;
            req.AddBody(login);
            var response = await RestJukeBox.ExecuteAsync <UserResponse>(req);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                if (response.StatusCode != HttpStatusCode.Accepted)
                {
                    throw new Exception(response.StatusDescription, new Exception(response.Content));
                }
            }

            return(response.Data.ResponseObject);
        }
예제 #2
0
        public async Task <ActionResult> Index(UserRequestLogin model)
        {
            if (model.UserName != null && model.Password != null)
            {
                //Set time loggedOn
                var user = await JukeBox.BLL.Administration.Account.ApiLoginClient(model);

                if (user != null)
                {
                    // var usrEnabled = (bool)user.basic.Enabled;
                    if (user != null)
                    {
                        var actionList = (string)System.Web.HttpContext.Current.Session["AccessToken"];

                        if (actionList == null)
                        {
                            System.Web.HttpContext.Current.Session["AccessToken"] = "xhsu5stgajksa7ssjs7s67scs";
                        }
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        // If we got this far, something failed, redisplay form
                        ViewBag.Error = "User name not active";
                        return(View(model));
                    }
                }
                else
                {
                    // If we got this far, something failed, redisplay form
                    ViewBag.Error = "Invalid Username / Password";
                    return(View(model));
                }
            }
            else
            {
                // If we got this far, something failed, redisplay form
                ViewBag.Error = "The user name or password provided is incorrect.";
                return(View(model));
            }
        }