Пример #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());
        }
Пример #3
0
        public ActionResult LogOff()
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            FormsAuthentication.SignOut();
            CMSApiClient client = new CMSApiClient(HttpContext);

            client.LogOut();
            return(RedirectToAction("Login", "Account"));
        }
Пример #4
0
        public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            CMSApiClient client = new CMSApiClient(HttpContext);
            var          result = client.Post(APIUrls.ChangePassword, model);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }

            return(View());
        }
Пример #5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                CMSApiClient client = new CMSApiClient(HttpContext);
                var          result = client.Post(APIUrls.Register, model, true);

                if (result.StatusCode == HttpStatusCode.OK)
                {
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    return(RedirectToAction("Login"));
                }
            }

            return(View(model));
        }
Пример #6
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     client = new CMSApiClient(HttpContext);
 }