コード例 #1
0
        /// <summary>
        /// Deal with an already known social identity
        /// </summary>
        private dynamic HandleKnownIdentity(UserIdentity userIdentity, INancyModule nancyModule, string returnUrl)
        {
            // Get the currently logged in user
            var loggedInUser = GetLoggedInUser(nancyModule);

            // If we aren't logged in, log ourselves in
            if (loggedInUser == null)
            {
                User user = null;//ReadStore.Users.FindAllByUserId(userIdentity.UserId).FirstOrDefault();
                if (user == null)
                {
                    // Something went wrong
                    //nancyModule.AddAlertMessage();
                    return(nancyModule.AsRedirectQueryStringOrDefault("~/dashboard"));
                }

                nancyModule.SignIn(user);

                return(string.IsNullOrWhiteSpace(returnUrl)
                    ? nancyModule.AsRedirectQueryStringOrDefault("~/dashboard")
                    : nancyModule.Response.AsRedirect(returnUrl));
            }

            // If we are logged in, we are trying to link ourselves, check if we are allowed
            //if (loggedInUser.UserId != userIdentity.UserId)
            //{
            //    // You can't link an account that's already attached to another user
            //    // TODO: Implement
            //    //nancyModule.AddAlertMessage("error", string.Format("This {0} account has already been linked to another user.", providerName));
            //}

            // We are logged in, and are trying to link ourselves to something that has already been linked, just redirect
            // TODO: Perhaps we should update the returned data at this time
            return(nancyModule.Response.AsRedirect("~/account/identity"));
        }
コード例 #2
0
        public static Response SignIn(this INancyModule module, IEnumerable <Claim> claims, bool isPersistent = false)
        {
            var env         = module.Context.GetOwinEnvironment();
            var owinContext = new OwinContext(env);

            var identity    = new ClaimsIdentity(claims, TheBenchConstants.TheBenchAuthType, TheBenchClaimTypes.Name, TheBenchClaimTypes.Role);
            var authOptions = new AuthenticationProperties {
                IsPersistent = isPersistent
            };

            owinContext.Authentication.SignIn(authOptions, identity);

            return(module.AsRedirectQueryStringOrDefault("~/dashboard"));
        }
コード例 #3
0
        /// <summary>
        /// Deal with an already known social identity
        /// </summary>
        private dynamic HandleKnownIdentity(UserIdentity userIdentity, INancyModule nancyModule, string returnUrl)
        {
            // Get the currently logged in user
            var loggedInUser = GetLoggedInUser(nancyModule);

            // If we aren't logged in, log ourselves in
            if (loggedInUser == null)
            {
                User user = null;//ReadStore.Users.FindAllByUserId(userIdentity.UserId).FirstOrDefault();
                if (user == null)
                {
                    // Something went wrong
                    //nancyModule.AddAlertMessage();
                    return nancyModule.AsRedirectQueryStringOrDefault("~/dashboard");
                }

                nancyModule.SignIn(user);

                return string.IsNullOrWhiteSpace(returnUrl)
                    ? nancyModule.AsRedirectQueryStringOrDefault("~/dashboard")
                    : nancyModule.Response.AsRedirect(returnUrl);
            }

            // If we are logged in, we are trying to link ourselves, check if we are allowed
            //if (loggedInUser.UserId != userIdentity.UserId)
            //{
            //    // You can't link an account that's already attached to another user
            //    // TODO: Implement
            //    //nancyModule.AddAlertMessage("error", string.Format("This {0} account has already been linked to another user.", providerName));
            //}

            // We are logged in, and are trying to link ourselves to something that has already been linked, just redirect
            // TODO: Perhaps we should update the returned data at this time
            return nancyModule.Response.AsRedirect("~/account/identity");
        }