コード例 #1
0
        public async Task<ActionResult> Register(RegisterDonorViewModel registration) {
            var userManager = HttpContext.GetOwinContext().GetUserManager<WishlistUserManager>();
            var user = await CreateDonor(registration, userManager);

            if (registration.DonorId.HasValue) {
                await AuthorizeDonorForUser(user, registration.DonorId.Value, userManager);
                await SendConfirmationEmail(user, userManager);
                await SignDonorIn(user, userManager);

                return RedirectToAction("Index", "Home");
            }

            var donor = new Donor();
            _db.Donors.Add(donor);

            var cart = new Cart {
                Donor = donor,
                ModifiedDate = DateTime.Now
            };
            _db.Carts.Add(cart);
            await _db.SaveChangesAsync();

            await AuthorizeDonorForUser(user, donor.Id, userManager);
            await SendConfirmationEmail(user, userManager);
            await SignDonorIn(user, userManager);
            return RedirectToAction("Index", "Home");
        }
コード例 #2
0
        public async Task<ActionResult> SignInAnonymously() {
            var donor = new Donor();
            _db.Donors.Add(donor);

            var cart = new Cart { Donor = donor, ModifiedDate = DateTime.Now };
            _db.Carts.Add(cart);

            await _db.SaveChangesAsync();

            var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
            var anonymousIdentifier = Guid.NewGuid().ToString();
            identity.AddClaim(new Claim("Donor", donor.Id.ToString()));
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, anonymousIdentifier));
            identity.AddClaim(new Claim(IdentityProviderClaimType, anonymousIdentifier));
            var authManager = HttpContext.GetOwinContext().Authentication;
            authManager.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);

            return RedirectToAction("Index", "Home");
        }