Exemplo n.º 1
0
        public bool Validate(string email, string uiPassword)
        {
            ValidationUtil.ValidateRequiredStringValue(email, "email");
            ValidationUtil.ValidateRequiredStringValue(uiPassword, "password");

            Customer customer = hopeLingerieEntities.Customers.SingleOrDefault(x => x.Email == email && x.Active);

            if (customer == null)
            {
                return(false);
            }

            string dbPassword = EncryptionService.Decrypt(customer.Password, KeyString);

            return(dbPassword == uiPassword);
        }
Exemplo n.º 2
0
        public MembershipCreationStatus Create(Customer customer)
        {
            try
            {
                string   decriptedPassword = customer.Password;
                Customer newCustomer       = hopeLingerieEntities.Customers.SingleOrDefault(x => x.Email == customer.Email && x.Active);

                if (newCustomer != null)
                {
                    return(MembershipCreationStatus.DuplicateEmail);
                }

                customer.Password  = EncryptionService.Encrypt(customer.Password, KeyString);
                customer.IsAdmin   = false;
                customer.AddedDate = DateTime.Now;
                hopeLingerieEntities.Customers.AddObject(customer);

                if (customer.NewsLetter)
                {
                    NewsLetter newsLetter = new NewsLetter();
                    newsLetter.AddedDate = DateTime.Now;
                    newsLetter.Email     = customer.Email;
                    newsLetter.Name      = customer.LastName + ", " + customer.FirstName;
                    hopeLingerieEntities.NewsLetters.AddObject(newsLetter);
                }

                hopeLingerieEntities.SaveChanges();

                Mail mail = hopeLingerieEntities.Mails.SingleOrDefault(a => a.Code == "NEWUSER");

                if (mail != null)
                {
                    MailService.Send(mail.From, customer.Email, mail.Subject, String.Format(mail.Body, customer.FirstName + " " + customer.LastName, customer.Email, EncryptionService.Decrypt(customer.Password, KeyString)));
                }

                return(MembershipCreationStatus.Success);
            }
            catch
            {
                return(MembershipCreationStatus.Fail);
            }
        }
Exemplo n.º 3
0
        public bool ChangePassword(string email, string oldPassword, string newPassword)
        {
            ValidationUtil.ValidateRequiredStringValue(email, "email");
            ValidationUtil.ValidateRequiredStringValue(oldPassword, "oldPassword");
            ValidationUtil.ValidateRequiredStringValue(newPassword, "newPassword");

            try
            {
                Customer customer = hopeLingerieEntities.Customers.SingleOrDefault(x => x.Email == email && x.Active);

                if (customer == null)
                {
                    return(false);
                }

                var dbPassword = EncryptionService.Decrypt(customer.Password, KeyString);

                if (dbPassword != oldPassword)
                {
                    return(false);
                }

                customer.Password = EncryptionService.Encrypt(newPassword, KeyString);
                hopeLingerieEntities.SaveChanges();

                Mail mail = hopeLingerieEntities.Mails.SingleOrDefault(a => a.Code == "CHANGEPWD");

                if (mail != null)
                {
                    MailService.Send(mail.From, email, mail.Subject, String.Format(mail.Body, customer.FirstName + " " + customer.LastName, email, newPassword));
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }