Пример #1
0
        public bool Authenticate(ApiCredential credentials, HttpResponseBase response)
        {
            var apiClient = new ApiClient(credentials);
            if (!apiClient.Ping())
                return false;

            var userData = credentials.ToNameValueCollection();
            new FormsAuthentication().SetAuthCookie(response, "tinyPM User", true, userData);

            return true;
        }
        public ApiCredentialProvider(HttpContextBase context)
        {
            var identity = context.User.Identity as FormsIdentity;

            var userData = identity != null && identity.IsAuthenticated
                ? identity.Ticket.GetStructuredUserData()
                : null;

            credential = userData != null
                ? ApiCredential.FromNameValueCollection(userData)
                : null;
        }
Пример #3
0
        public ActionResult Login(ApiCredential credentials, string returnUrl)
        {
            if (!ModelState.IsValid)
                return View(credentials);

            var isLoginValid = securityService.Authenticate(credentials, Response);

            if (isLoginValid)
            {
                return Url.IsLocalUrl(returnUrl)
                    ? (ActionResult)Redirect(returnUrl)
                    : RedirectToRoute(RouteNames.ListProjects);
            }

            ModelState.AddModelError("login-failed", "The login failed.");
            return View(credentials);
        }