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);
        }
 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);
 }
 // 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);
       }
 }
 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)
     {
     }
 }
 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);
 }
        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;
            }
              }
        }
 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);
 }
 public void ClearCart(User user)
 {
     ClearCart(user.Id);
 }
 public IQueryable<ShoppingCartItem> UserCart(User user)
 {
     return UserCart(user.Id);
 }
 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);
 }
 public GiftOrder LastOrderForUser(User user)
 {
     return _giftCardOrderRepository.FindBy(o => o.UserId == user.Id && o.BillingAddressId != null)
                          .OrderByDescending(o => o.CreatedAt)
                          .FirstOrDefault();
 }
 private void LogLogin(User user)
 {
     user.LastLoginAt = DateTime.UtcNow;
       _userService.UpdateUser(user);
 }
 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;
 }
 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;
 }