예제 #1
0
        private ViewResult GarmentsListForExistingUser()
        {
            MembershipUser   mu   = Membership.GetUser();
            RegisteredUser   user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));
            GarmentsListData gld  = new GarmentsListData();

            //foreach (UserFlavor userFlavor in user.UserFlavors)
            //    gld.FashionFlavors.Add(userFlavor.Flavor);
            GetGarmentsListData(user, gld);
            return(View(gld));
        }
예제 #2
0
        private bool IsSameUser(int userId)
        {
            MembershipUser mu = Membership.GetUser();
            RegisteredUser user;

            if (mu != null)
            {
                user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));
                if (user != null)
                {
                    return(user.Id == userId);
                }
            }
            return(false);
        }
예제 #3
0
        private RegisteredUser GetUser()
        {
            MembershipUser mu = Membership.GetUser();

            if (mu != null)
            {
                ViewData["UserName"] = mu.UserName;
                return(registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey)));
            }
            return(null);
        }
예제 #4
0
        public ViewResult AddFriends(FormCollection values)
        {
            List <int>     selectedIndexs  = new List <int>();
            List <Friend>  selectedFriends = new List <Friend>();
            MembershipUser mu   = Membership.GetUser();
            RegisteredUser user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));

            foreach (var value in values)
            {
                object o = values[value.ToString()];
                if (o.ToString().Contains("true"))
                {
                    selectedIndexs.Add(Convert.ToInt32(value.ToString().Split('_')[1]));
                }
            }

            if (Session["GMailToken"] != null)
            {
                selectedFriends = GetGmailContacts(selectedIndexs);
            }

            user.AddFriends(selectedFriends);
            registeredUserRepository.SaveOrUpdate(user);

            return(View("FriendSelection", selectedFriends));
        }
        public ActionResult Validate(string userid, string code)
        {
            if (!string.IsNullOrEmpty(code) && !string.IsNullOrEmpty(userid))
            {
                int userId = Convert.ToInt32(userid);

                MembershipUser mu = Membership.GetUser(userId);
                if (mu != null)
                {
                    RegisteredUser ru = registeredUserRepository.GetByMembershipId(userId);

                    if (!mu.IsApproved)
                    {
                        // Make sure is using the valid code
                        if (ru != null && ru.RegistrationCode.Trim().ToLower() == code.Trim().ToLower())
                        {
                            // Approve on Membership
                            mu.IsApproved = true;
                            Membership.UpdateUser(mu);

                            // Approve on System
                            ru.Confirm();
                            ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset;
                            registeredUserRepository.SaveOrUpdate(ru);
                            // Send approval mail
                            messageSenderService.SendWithTemplate("approvedmail", ru, ru.UserName, ru.EmailAddress);
                            return(RedirectToAction("Index", "Login", new { validatedUser = true }));
                        }
                    }
                    else
                    {
                        if (ru != null && ru.RegistrationCode.Trim().ToLower() == code.Trim().ToLower())
                        {
                            ru.EmailAddress = ru.NewMail;
                            mu.Email        = ru.EmailAddress;
                            ru.NewMail      = string.Empty;
                            registeredUserRepository.SaveOrUpdate(ru);
                            Membership.UpdateUser(mu);
                            // Send approval mail
                            messageSenderService.SendWithTemplate("approvedmail", ru, ru.UserName, ru.EmailAddress);
                            return(RedirectToAction("Index", "Home", new { validatedUser = true }));
                        }
                    }
                }
            }

            return(RedirectToAction("Index", new { invalidCode = true, userid = userid }));
        }
예제 #6
0
        public ActionResult Index()
        {
            MembershipUser mu = Membership.GetUser();

            if (mu != null)
            {
                ViewData["UserName"] = mu.UserName;
            }

            RegisteredUser user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));

            LoadSeasons();

            IList <Category> categories = categoryRepository.GetAll();

            foreach (Category category in categories)
            {
                ViewData["Category" + category.Description] = category.Id;
            }

            IList <FashionFlavor> flavors = new List <FashionFlavor>();

            foreach (UserFlavor flavor in user.UserFlavors)
            {
                flavors.Add(flavor.Flavor);
            }
            ViewData["FashionFlavors"] = flavors;

            List <WebClosetGarment> webClosetGarments = closetRepository.GetWebClosetGarments(user);

            ViewData["pants_jeans"] = webClosetGarments.FindAll(delegate(WebClosetGarment record)
            {
                if (record.CatId == (int)ViewData["CategoryPants"] || record.CatId == (int)ViewData["CategoryJeans"])
                {
                    return(true);
                }
                return(false);
            });

            ViewData["skirts_shorts"] = webClosetGarments.FindAll(delegate(WebClosetGarment record)
            {
                if (record.CatId == (int)ViewData["CategoryShorts"] || record.CatId == (int)ViewData["CategorySkirts"])
                {
                    return(true);
                }
                return(false);
            });

            ViewData["dresses"] = webClosetGarments.FindAll(delegate(WebClosetGarment record)
            {
                if (record.CatId == (int)ViewData["CategoryDresses"])
                {
                    return(true);
                }
                return(false);
            });

            ViewData["jackets"] = webClosetGarments.FindAll(delegate(WebClosetGarment record)
            {
                if (record.CatId == (int)ViewData["CategoryJackets"])
                {
                    return(true);
                }
                return(false);
            });

            ViewData["tops"] = webClosetGarments.FindAll(delegate(WebClosetGarment record)
            {
                if (record.CatId == (int)ViewData["CategoryCoats"] || record.CatId == (int)ViewData["CategoryCardigan"] || record.CatId == (int)ViewData["CategoryShirts"])
                {
                    return(true);
                }
                return(false);
            });

            ViewData["accesories"] = webClosetGarments.FindAll(delegate(WebClosetGarment record)
            {
                if (record.CatId == (int)ViewData["CategoryJewelry"] || record.CatId == (int)ViewData["CategoryBelts"] || record.CatId == (int)ViewData["CategoryShoes"] || record.CatId == (int)ViewData["CategoryBags"])
                {
                    return(true);
                }
                return(false);
            });

            return(View());
        }
예제 #7
0
        private UserFull GetAccountData(UserFull userModification)
        {
            MembershipUser        mu = Membership.GetUser();
            List <SelectListItem> securityQuestionList = new List <SelectListItem>();
            List <SelectListItem> userSizeList         = new List <SelectListItem>();
            List <SelectListItem> privacyList          = new List <SelectListItem>();

            if (mu != null)
            {
                RegisteredUser   ru = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));
                SecurityQuestion securityQuestion = securityQuestionRepository.GetByDescription(mu.PasswordQuestion);
                userModification = new UserFull(ru, securityQuestion.Id, userModification.Alert, userModification.Tab);

                IList <SecurityQuestion> questions = securityQuestionRepository.GetAll();
                foreach (SecurityQuestion question in questions)
                {
                    SelectListItem sl = new SelectListItem();
                    sl.Text  = question.Description;
                    sl.Value = question.Id.ToString();
                    if (question.Description == securityQuestion.Description)
                    {
                        sl.Selected = true;
                    }
                    securityQuestionList.Add(sl);
                }

                IList <UserSize> userSizes = userSizeRepository.GetAll();
                foreach (UserSize userSize in userSizes)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Text  = userSize.Description;
                    sli.Value = userSize.Id.ToString();
                    if (userSize.Id == ru.Size.Id)
                    {
                        sli.Selected = true;
                    }
                    userSizeList.Add(sli);
                }

                SelectListItem pvy = new SelectListItem();
                pvy.Text  = "My Closet can be viewed by me only";
                pvy.Value = PrivacyLevel.Private.ToString();
                if (ru.Closet.PrivacyLevel == PrivacyLevel.Private)
                {
                    pvy.Selected = true;
                }
                privacyList.Add(pvy);
                pvy       = new SelectListItem();
                pvy.Text  = "My Closet can be viewed by me and my friends";
                pvy.Value = PrivacyLevel.Friends.ToString();
                if (ru.Closet.PrivacyLevel == PrivacyLevel.Friends)
                {
                    pvy.Selected = true;
                }
                privacyList.Add(pvy);
                pvy       = new SelectListItem();
                pvy.Text  = "Only my Signature Outfit can be viewed by anyone";
                pvy.Value = PrivacyLevel.FavoriteOutfit.ToString();
                if (ru.Closet.PrivacyLevel == PrivacyLevel.FavoriteOutfit)
                {
                    pvy.Selected = true;
                }
                privacyList.Add(pvy);
                pvy       = new SelectListItem();
                pvy.Text  = "My Entire Closet can be viewed by anyone";
                pvy.Value = PrivacyLevel.FullCloset.ToString();
                if (ru.Closet.PrivacyLevel == PrivacyLevel.FullCloset)
                {
                    pvy.Selected = true;
                }
                privacyList.Add(pvy);
            }

            ViewData["SecurityQuestions"] = securityQuestionList;
            ViewData["UserSizes"]         = userSizeList;
            ViewData["PrivacyStatus"]     = privacyList;
            if (mu != null)
            {
                ViewData["UserName"] = mu.UserName;
            }

            return(userModification);
        }
예제 #8
0
        public ActionResult Register(UserRegistration userRegistration)
        {
            if (ModelState.IsValid)
            {
                IList <UserFlavor> userFlavors    = ClosetState.UserFlavors as List <UserFlavor>;
                IList <EventType>  eventTypes     = ClosetState.EventTypes as List <EventType>;
                IList <Garment>    mygarments     = garmentRepository.GetByIds(ClosetState.AddGarments) as List <Garment>;
                IList <Garment>    mywishlist     = garmentRepository.GetByIds(ClosetState.WishGarments) as List <Garment>;
                string             channel        = ClosetState.Channel;
                string             invitationCode = ClosetState.InvitationCode;

                SecurityQuestion sq = securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion));

                // Create Membership User
                MembershipCreateStatus status;
                MembershipUser         mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, sq.Description, userRegistration.SecurityAnswer, false, out status);
                if (status != MembershipCreateStatus.Success)
                {
                    ViewData["Errors"] = new string[] { status.ToString() }
                }
                ;

                try
                {
                    bool mustConfirmMail = registerMemberService.RegisterMember(userRegistration.Email,
                                                                                userRegistration.UserName, userRegistration.FirstName, userRegistration.LastName,
                                                                                userRegistration.Password,
                                                                                new UserSize(Convert.ToInt32(userRegistration.UserSize)),
                                                                                Convert.ToInt32(mu.ProviderUserKey),
                                                                                userRegistration.ZipCode,
                                                                                userFlavors,
                                                                                eventTypes,
                                                                                mygarments,
                                                                                mywishlist,
                                                                                Url.Action("Validate", "EmailConfirmation"),
                                                                                channel,
                                                                                invitationCode);

                    // Assign User Role
                    Roles.AddUserToRole(mu.UserName, "User");

                    if (mustConfirmMail)
                    {
                        ClosetState.Clear();
                        return(RedirectToAction("Index", "EmailConfirmation", new { userid = mu.ProviderUserKey }));
                    }

                    //The user already confirmed his email, so we need to approve him and go to the login
                    // Approve on Membership
                    mu.IsApproved = true;
                    Membership.UpdateUser(mu);

                    RegisteredUser ru =
                        registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));

                    // Approve on System
                    ru.Confirm();
                    ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset;
                    registeredUserRepository.SaveOrUpdate(ru);

                    ClosetState.Clear();
                    return(RedirectToAction("Index", "Login", new { validatedUser = true }));
                }
                catch (Exception ex)
                {
                    // Try to delete the incomplete created user because something went wrong.
                    try { Membership.DeleteUser(userRegistration.UserName); }
                    catch { }

                    if (ex is InvalidInvitationCodeException)
                    {
                        ModelState.AddModelError("InvitationCode", "The code is not valid or already used.");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                if (new List <ModelState>(ModelState.Values).Find(e => e.Value == null).Errors[0].ErrorMessage.StartsWith("Email"))
                {
                    ModelState.AddModelError("Email", "Email does not match.");
                }
                else
                {
                    ModelState.AddModelError("Password", "Password does not match.");
                }
            }

            GetRegistrationInfo(userRegistration);
            return(View("Index", userRegistration));
        }