Пример #1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            CMSApiClient client = new CMSApiClient(HttpContext, model.Email, model.Password);
            var          result = client.GetToken();

            if (result.StatusCode == HttpStatusCode.OK)
            {
                var userResult = client.Get <CMS_Entity.Db.User>(APIUrls.LoggedInUser);
                var user       = userResult.Data;
                CreateCookie(user);

                this.HttpContext.Cache.Insert(KeyConstants.User.ToString(), user, null,
                                              DateTime.UtcNow.AddSeconds(60 * 60), Cache.NoSlidingExpiration);

                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Пример #2
0
        public ActionResult Index()
        {
            CMSApiClient client = new CMSApiClient(HttpContext);

            var result = client.Get <User>(APIUrls.LoggedInUser);

            return(View());
        }