コード例 #1
0
        private string GenerateEncryptedTicket(User user, string cookieName, bool persistent)
        {
            if (user == null) return null;

              var serializeModel = new CustomPrincipalSerializeModel
            {
              UserId = user.Id,
              OrganizationId = user.OrganizationId,
              IsConfirmed = user.IsConfirmed,
              Roles = _userService.GetRoles(user),
              DisplayName = user.FirstName
            };

              var serializer = new JavaScriptSerializer();
              var userData = serializer.Serialize(serializeModel);

              var authTicket = new FormsAuthenticationTicket(
            CookieVersion, // version
            cookieName, // name
            DateTime.UtcNow, //created
            DateTime.UtcNow.AddMinutes(60), // expires
            persistent, // persistent?
            userData // user data
            );

              return FormsAuthentication.Encrypt(authTicket);
        }
コード例 #2
0
 public EmailResult WelcomeEmail(Organization org, User user)
 {
     To.Add(user.Email);
       // TODO: from address should be configurable somewhere
       From = "*****@*****.**";
       Subject = "Your brite account with brite spokes";
       return Email("WelcomeEmail", user);
 }
コード例 #3
0
 // assumes user has authenticated in some way, i.e. via the confirmation
 // process. Call this method with care
 public void SetAuthenticated(User user, bool persistent = false)
 {
     if (user != null)
       {
     var cookieName = CookieName(user);
     var encryptedTicket = GenerateEncryptedTicket(user, cookieName, persistent);
     var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
     HttpContext.Current.Response.Cookies.Add(authCookie);
       }
 }
コード例 #4
0
 public User PromoteGuest(User guest, string email, string password)
 {
     guest.Email = email;
       SetCredentials(guest, password);
       guest.AddRole(_roleService.Customer());
       guest.RemoveRole(_roleService.Guest());
       _userService.UpdateUser(guest);
       _authService.Reauthenticate(guest);
       return guest;
 }
コード例 #5
0
 public void SendWelcomeEmail(Organization org, User user)
 {
     // TODO: Mails are sent synchronously
       // this probably still should be refactored to use a real bg process
     try
     {
     _userMailerController.WelcomeEmail(org, user).Deliver();
     _userService.ConfirmationEmailSent(user);
     }
     catch (Exception e)
     {
     }
 }
コード例 #6
0
 public User RegisterCustomer(Organization organization, User user, string password, string firstName, string lastName, string IATA, string affiliation)
 {
     // assumes an unsaved, in-memory user
       SetCredentials(user, password);
       user.FirstName = firstName;
       user.LastName = lastName;
       user.OrganizationId = organization.Id;
       user.IATA = IATA;
       user.Affiliation = affiliation;
       user.AddRole(_roleService.Customer());
       _userService.AddUser(user);
       _authService.Login(organization, user.Email, password, false);
       return user;
 }
コード例 #7
0
        public BillingDetails BuildBillingDetails(Order order, User user = null)
        {
            var billingOverview = BuildBillingOverview(order);

            var billingDetails = new BillingDetails
              {
                  OrderId = order.Id,
                  OrderNumber = order.OrderNumber,
                  DiscountCodes = DiscountCodesForOrder(order).Select(d => d.LowerCode).ToArray(),
                  UserId = order.UserId,
                  CountryId = 226, // TODO: hardcoded country for now
                  BillingOverview = billingOverview
              };

            if (user != null)
            {
                billingDetails.FirstName = user.FirstName;
                billingDetails.LastName = user.LastName;
                billingDetails.Email = user.Email;

                var lastOrder = LastOrderForUser(user);
                if (lastOrder != null)
                {
                    var billingAddress = lastOrder.BillingAddress;
                    if (billingAddress != null)
                    {
                        billingDetails.Address1 = billingAddress.Address1;
                        billingDetails.Address2 = billingAddress.Address2;
                        billingDetails.City = billingAddress.City;
                        billingDetails.StateOrProvince = billingAddress.StateOrProvince;
                        billingDetails.ZipCode = billingAddress.ZipCode;
                    }
                }
            }

            return billingDetails;
        }
コード例 #8
0
 public void ConfirmationEmailSent(User user)
 {
     user.ConfirmationSentAt = DateTime.UtcNow;
       _userRepo.Update(user);
 }
コード例 #9
0
        private void SetBillingAddressFromLastOrder(BillingDetails billingDetails, User user)
        {
            billingDetails.FirstName = user.FirstName;
              billingDetails.LastName = user.LastName;
              billingDetails.Email = user.Email;

              var lastOrder = _orderService.LastOrderForUser(user);
              if (lastOrder != null)
              {
            var billingAddress = lastOrder.BillingAddress;
            if (billingAddress != null)
            {
              billingDetails.Address1 = billingAddress.Address1;
              billingDetails.Address2 = billingAddress.Address2;
              billingDetails.City = billingAddress.City;
              billingDetails.StateOrProvince = billingAddress.StateOrProvince;
              billingDetails.ZipCode = billingAddress.ZipCode;
            }
              }
        }
コード例 #10
0
 public void Reauthenticate(User user, bool isPersistent = false)
 {
     var authCookie = FormsAuthentication.GetAuthCookie(user.Email, false);
       authCookie.Value = GenerateEncryptedTicket(user, user.Email, isPersistent);
       HttpContext.Current.Response.Cookies.Set(authCookie);
 }
コード例 #11
0
 public void ClearCart(User user)
 {
     ClearCart(user.Id);
 }
コード例 #12
0
 public IQueryable<ShoppingCartItem> UserCart(User user)
 {
     return UserCart(user.Id);
 }
コード例 #13
0
 private string CookieName(User user)
 {
     var name = user.Email ?? Guid.NewGuid().ToString();
       return string.Format("__BRITESPOKES_{0}", name);
 }
コード例 #14
0
 public void Delete(User user)
 {
     _userRepo.Delete(user);
 }
コード例 #15
0
 public GiftOrder LastOrderForUser(User user)
 {
     return _giftCardOrderRepository.FindBy(o => o.UserId == user.Id && o.BillingAddressId != null)
                          .OrderByDescending(o => o.CreatedAt)
                          .FirstOrDefault();
 }
コード例 #16
0
 private void LogLogin(User user)
 {
     user.LastLoginAt = DateTime.UtcNow;
       _userService.UpdateUser(user);
 }
コード例 #17
0
 public User RegisterGuest(Organization organization)
 {
     var guest = new User
     {
       IsActive = true,
       OrganizationId = organization.Id
     };
       guest.AddRole(_roleService.Guest());
       _userService.AddUser(guest);
       _authService.SetAuthenticated(guest);
       return guest;
 }
コード例 #18
0
 public User AddUser(User user)
 {
     _userRepo.Add(user);
       return user;
 }
コード例 #19
0
 public User UpdateUser(User user)
 {
     _userRepo.Update(user);
       return user;
 }
コード例 #20
0
 private void SetCredentials(User user, string password)
 {
     var hashedText = _encryptionService.ComputeHash(password);
       user.PasswordSalt = hashedText.Salt;
       user.Password = hashedText.Text;
       user.ConfirmationToken = Guid.NewGuid().ToString().ToLower().Replace("-", "");
 }
コード例 #21
0
 public string[] GetRoles(User user)
 {
     string[] roles = null;
       if (user.Roles != null)
     roles = user.Roles.Select(r => r.Name).ToArray();
       return roles;
 }