Esempio n. 1
0
        public ActionResult EditProfile(UserAccountDetail uad)
        {
            // must change culture because decimal will not be correct for long/ lat
            string currentLang = Utilities.GetCurrentLanguageCode();
            if (currentLang == null) throw new ArgumentNullException("uad");

            Thread.CurrentThread.CurrentUICulture =
                CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());

            LoadCountries();
            InterestIdentityViewBags();

            if (_mu != null)
            {
                var uadCurrent = new UserAccountDetail {UserAccountID = Convert.ToInt32(_mu.ProviderUserKey)};
                uadCurrent.GetUserAccountDeailForUser(uadCurrent.UserAccountID);

                ViewBag.IsValid = true;
                ViewBag.ProfileUpdated = false;

                DateTime dt;

                if (DateTime.TryParse(Request.Form["birthyear"]
                                      + "-" + Request.Form["birthmonth"] + "-" + Request.Form["birthday"], out dt))
                {
                    uad.BirthDate = dt;
                }
                else
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError(string.Empty, Messages.Invalid + @": " + Messages.BirthDate);
                    return View(uad);
                }

                if (string.IsNullOrEmpty(uad.Country) || uad.Country == Messages.DashSelect)
                {
                    uad.Country = string.Empty;
                    ViewBag.IsValid = false;
                    ModelState.AddModelError(string.Empty, Messages.Invalid + @": " + Messages.Country);
                    return View(uad);
                }

                if (uad.YouAreID == null)
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError(string.Empty, Messages.Invalid + @": " + Messages.YouAre);
                    return View(uad);
                }

                if (uad.InterestedInID == null)
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError(string.Empty, Messages.Invalid + @": " + Messages.InterestedIn);
                    return View(uad);
                }

                if (!string.IsNullOrEmpty(uad.ExternalURL.Trim()) &&
                    !Uri.IsWellFormedUriString(uad.ExternalURL, UriKind.Absolute))
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError(string.Empty, Messages.Invalid + @": " + Messages.Website);
                    return View(uad);
                }

                bool isNewProfile = string.IsNullOrEmpty(uad.Country.Trim());

                uadCurrent.AboutDesc = uad.AboutDesc;
                uadCurrent.HardwareSoftware = uad.HardwareSoftware;
                uadCurrent.BirthDate = uad.BirthDate;
                uadCurrent.YouAreID = uad.YouAreID;
                uadCurrent.ExternalURL = uad.ExternalURL;
                uadCurrent.Country = uad.Country;
                uadCurrent.PostalCode = uad.PostalCode;
                uadCurrent.BandsSeen = uad.BandsSeen;
                uadCurrent.BandsToSee = uad.BandsToSee;
                uadCurrent.RelationshipStatusID = uad.RelationshipStatusID;
                uadCurrent.InterestedInID = uad.InterestedInID;
                uadCurrent.FirstName = uad.FirstName;
                uadCurrent.LastName = uad.LastName;

                if (!string.IsNullOrWhiteSpace(uad.Country) &&
                    !string.IsNullOrWhiteSpace(uad.PostalCode))
                {
                    SiteStructs.LatLong latlong = GeoData.GetLatLongForCountryPostal(uad.Country, uad.PostalCode);

            // ReSharper disable CompareOfFloatsByEqualityOperator
                    if (latlong.latitude != 0 && latlong.longitude != 0)
            // ReSharper restore CompareOfFloatsByEqualityOperator
                    {
                        uad.Latitude = Convert.ToDecimal(latlong.latitude);
                        uad.Longitude = Convert.ToDecimal(latlong.longitude);

                        uadCurrent.Latitude = uad.Latitude;
                        uadCurrent.Longitude = uad.Longitude;
                    }
                }

                if (uadCurrent.Set() > 0)
                {
                    ViewBag.ProfileUpdated = true;
                }
                else
                {
                    ModelState.AddModelError(string.Empty, Messages.Error);
                }

                if (isNewProfile)
                {
                    return RedirectToAction("EditPhoto");
                }
            }

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(currentLang);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(currentLang);

            return View(uad);
        }
Esempio n. 2
0
        public ActionResult Settings(NameValueCollection nvc)
        {
            ViewBag.IsValid = true;

            if (_mu != null) _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey));

            _uad = new UserAccountDetail();

            if (_mu != null) _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey));

            string enableProfileLogging = Request.Form["enableprofilelogging"];
            string emailmessages = Request.Form["emailmessages"];
            string showonmap = Request.Form["showonmap"];
            string displayAge = Request.Form["displayage"];
            string membersOnlyProfile = Request.Form["membersonlyprofile"];

            _uad.MembersOnlyProfile = !string.IsNullOrEmpty(membersOnlyProfile);
            _uad.EnableProfileLogging = !string.IsNullOrEmpty(enableProfileLogging);
            _uad.DisplayAge = !string.IsNullOrEmpty(displayAge);
            _uad.EmailMessages = !string.IsNullOrEmpty(emailmessages);
            _uad.ShowOnMap = !string.IsNullOrEmpty(showonmap);

            _uad.Set();

            string username = Request.Form["username"].Trim();
            bool isNewUserName = false;
            bool isValidName;

            try
            {
                isValidName = !Regex.IsMatch(@"[A-Za-z][A-Za-z0-9_]{3,14}", username);
            }
            catch
            {
                // bad name
                isValidName = false;
            }

            if (_mu.UserName != username && isValidName)
            {
                // TODO: PUT IN ALL THE SAME VALIDATION AS REGISTRATION
                isNewUserName = true;
                var newUsername = new UserAccount(username.Replace(":", string.Empty) /* still annoying errors */);

                if (newUsername.UserAccountID != 0)
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError("", Messages.AlreadyInUse + @": " + Messages.UserName);
                    _uad = new UserAccountDetail();
                    _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey));
                    ViewBag.UserAccountDetail = _uad;
                    ViewBag.Membership = _mu;
                    return View();
                }
                if (!Utilities.IsEmail(Request.Form["email"]))
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError("", Messages.Invalid + @": " + Messages.EMail);
                    return View();
                }
                if (Request.Form["email"].Trim() != _ua.EMail)
                {
                    _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey)) {EMail = Request.Form["email"]};
                    _ua.Update();
                }

                username = username.Replace(":", string.Empty);
                username = username.Replace(" ", string.Empty);
                username = username.Replace(".", string.Empty);
                _ua.UserName = username;
                _ua.Update();
                FormsAuthentication.SetAuthCookie(username, false);
                ViewBag.IsValid = true;
            }
            else if (!Utilities.IsEmail(Request.Form["email"]))
            {
                ViewBag.IsValid = false;
                ModelState.AddModelError("", Messages.Invalid + @": " + Messages.EMail);
                return View();
            }
            else if (Request.Form["email"].Trim() != _ua.EMail)
            {
                _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey)) {EMail = Request.Form["email"]};
                _ua.Update();
            }

            ViewBag.ProfileUpdated = true;

            _uad = new UserAccountDetail();

            _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey));

            ViewBag.UserAccountDetail = _uad;
            ViewBag.Membership = _mu;

            if (isNewUserName)
            {
                // new username
                Response.Redirect("~/account/settings/?updated=1");
            }

            return View();
        }
Esempio n. 3
0
        public ActionResult EditPhoto(HttpPostedFileBase file)
        {
            UserPhoto up1 = null;
            var currentUserId = Convert.ToInt32(_mu.ProviderUserKey);
            int swapID;
            const CannedAcl acl = CannedAcl.PublicRead;

            var s3 = new S3Service
            {
                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
            };

            if (Request.Form["new_default"] != null &&
                int.TryParse(Request.Form["new_default"], out swapID))
            {
                // swap the default with the new default
                up1 = SwapOutDefaultPhoto(currentUserId, swapID);

                return View(_uad);
            }

            const string photoOne = "photo_edit_1";
            const string photoTwo = "photo_edit_2";
            const string photoThree = "photo_edit_3";

            if (_mu != null) LoadCurrentImagesViewBag(currentUserId);

            _uad = new UserAccountDetail();

            if (_mu != null) _uad.GetUserAccountDeailForUser(currentUserId);

            if (file == null)
            {
                ViewBag.IsValid = false;
                ModelState.AddModelError(string.Empty, Messages.NoFile);
                return View(_uad);
            }

            string photoEdited = Request.Form["photo_edit"];
            string rawPhotoToDelete = string.Empty;
            string mainPhotoToDelete = string.Empty;
            string thumbPhotoToDelete = string.Empty;

            _ups = new UserPhotos();
            _ups.GetUserPhotos(_uad.UserAccountID);

            if (string.IsNullOrEmpty(_uad.ProfilePicURL) ||
                _ups.Count == 2 && photoEdited == photoOne)
            {
                rawPhotoToDelete = _uad.RawProfilePicUrl;
                mainPhotoToDelete = _uad.ProfilePicURL;
                thumbPhotoToDelete = _uad.ProfileThumbPicURL;
            }
            else
            {
                if (_ups.Count > 1 && photoEdited == photoTwo)
                {
                    up1 = new UserPhoto(_ups[0].UserPhotoID) { RankOrder = 1 };

                    rawPhotoToDelete = up1.RawPicUrl;
                    mainPhotoToDelete = up1.PicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }
                else if (_ups.Count > 1 && photoEdited == photoThree)
                {
                    up1 = new UserPhoto(_ups[1].UserPhotoID) { RankOrder = 2 };

                    rawPhotoToDelete = up1.RawPicUrl;
                    mainPhotoToDelete = up1.FullProfilePicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }
            }

            if (!string.IsNullOrEmpty(mainPhotoToDelete))
            {
                DeletePhotos(s3, rawPhotoToDelete, mainPhotoToDelete, thumbPhotoToDelete);
            }

            var photoBitmap = new Bitmap(file.InputStream);

            // 300x 300 and raw
            up1 = ProcessMainPhotoItem(file, up1, currentUserId, acl, s3, photoOne, photoTwo, photoThree, photoEdited, photoBitmap);

            // 75 x 75 (thumbnail)
            var thumbFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, true, 75, 75);

            if (string.IsNullOrEmpty(_uad.ProfileThumbPicURL) ||
                _ups.Count == 2 && photoEdited == photoOne)
            {
                _uad.ProfileThumbPicURL = thumbFileName;
                _uad.LastPhotoUpdate = DateTime.UtcNow;
                _uad.Set();
            }
            else
            {
                if (up1 != null)
                {
                    if (_mu != null) up1.UserAccountID = currentUserId;
                    up1.ThumbPicURL = thumbFileName;

                    if (
                        (_ups.Count == 0 && photoEdited == photoTwo) ||
                        (_ups.Count > 0 && photoEdited == photoTwo)
                        )
                    {
                        up1.RankOrder = 1;
                    }
                    else if
                        (
                        (_ups.Count == 0 && photoEdited == photoThree) ||
                        (_ups.Count > 1 && photoEdited == photoThree)
                        )
                    {
                        up1.RankOrder = 2;
                    }
                }
            }

            photoBitmap.Dispose();

            if (up1 != null && up1.UserPhotoID == 0)
            {
                if (_mu != null) up1.CreatedByUserID = currentUserId;
                up1.Create();
            }
            else if (up1 != null && up1.UserPhotoID > 0)
            {
                up1.UpdatedByUserID = currentUserId;
                up1.Update();
            }

            LoadCurrentImagesViewBag(currentUserId);

            return View(_uad);
        }
Esempio n. 4
0
        public ActionResult Register(RegisterModel model)
        {
            if (Utilities.IsSpamIP(Request.UserHostAddress))
            {
                ModelState.AddModelError("", Messages.Invalid + @": " + Messages.Account);
                return View(model);
            }

            if
                (
                Request.Browser.Type == "IE3" ||
                Request.Browser.Type == "IE4" ||
                Request.Browser.Type == "IE5" ||
                Request.Browser.Type == "IE6" ||
                Request.Browser.Type == "IE7" ||
                BlackIPs.IsIPBlocked(Request.UserHostAddress)
                )
            {
                Response.Redirect("http://browsehappy.com/");
                return View();
            }

            if (!GeneralConfigs.EnableSameIP && UserAccount.IsAccountIPTaken(Request.UserHostAddress) &&
                string.IsNullOrEmpty(model.RefUser))
            {
                ModelState.AddModelError("", Messages.Invalid + @": " + Messages.Account);
                return View(model);
            }

            TryUpdateModel(model);

            if (!ModelState.IsValid) return View(model);

            if (!Utilities.IsEmail(model.Email))
            {
                ModelState.AddModelError("", Messages.IncorrectFormat + @": " + Messages.EMail);
                return View();
            }
            if (
                model.UserName.Trim().Contains(" ") ||
                model.UserName.Trim().Contains("?") ||
                model.UserName.Trim().Contains("*") ||
                model.UserName.Trim().Contains(":") ||
                model.UserName.Trim().Contains("/") ||
                model.UserName.Trim().Contains(@"\"))
            {
                ModelState.AddModelError("", Messages.Invalid + @": " + Messages.UserName);
                return View();
            }
            if (model.YouAreID == null)
            {
                ModelState.AddModelError("", Messages.Invalid + @": " + Messages.YouAre);
                return View();
            }

            DateTime dt;

            if (!DateTime.TryParse(model.Year
                                   + "-" + model.Month + "-" + model.Day, out dt))
            {
                ModelState.AddModelError("", Messages.Invalid + @": " + Messages.BirthDate);
                return View();
            }
            if (DateTime.TryParse(model.Year
                                  + "-" + model.Month + "-" + model.Day, out dt))
            {
                if (Utilities.CalculateAge(dt) < GeneralConfigs.MinimumAge)
                {
                    ModelState.AddModelError("", Messages.Invalid + @": " + Messages.BirthDate);
                    return View();
                }
            }

            model.UserName = model.UserName.Replace(":", string.Empty);
            model.UserName = model.UserName.Replace(" ", string.Empty);
            model.UserName = model.UserName.Replace(".", string.Empty);

            MembershipCreateStatus createStatus;

            Membership.CreateUser(model.UserName, model.NewPassword, model.Email, "Q", "A", true, out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                FormsAuthentication.RedirectFromLoginPage(model.UserName, true);

                var ua = new UserAccount(model.UserName);
                _uad = new UserAccountDetail
                {
                    UserAccountID = ua.UserAccountID,
                    BirthDate = dt,
                    YouAreID = model.YouAreID,
                    DisplayAge = true,
                    DefaultLanguage = Utilities.GetCurrentLanguageCode()
                };

                if (!string.IsNullOrEmpty(model.RefUser))
                {
                    var refUser = new UserAccount(model.RefUser);
                    _uad.ReferringUserID = refUser.UserAccountID;
                }

                _uad.Set();

                var sb = new StringBuilder(100);

                sb.Append(Messages.Hello);
                sb.Append(Environment.NewLine);
                sb.Append(Messages.YourNewAccountIsReadyForUse);
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.AppendFormat("{0}: ", Messages.UserName);
                sb.Append(ua.UserName);
                sb.Append(Environment.NewLine);
                sb.Append(GeneralConfigs.SiteDomain);

                _mail.SendMail(AmazonCloudConfigs.SendFromEmail, ua.EMail, Messages.YourNewAccountIsReadyForUse,
                    sb.ToString());

                // see if this is the 1st user
                var recentUsers = new UserAccounts();
                recentUsers.GetNewestUsers();

                if (recentUsers.Count == 1)
                {
                    var adminRole = new Role(SiteEnums.RoleTypes.admin.ToString());

                    UserAccountRole.AddUserToRole(ua.UserAccountID, adminRole.RoleID);
                }

                var dm = new DirectMessage {IsRead = false};
                var communityManager = new UserAccount(SiteDomain.GetSiteDomainValue(
                                                SiteEnums.SiteBrandType.GRTUR,
                                                Utilities.GetCurrentLanguageCode())
                                            .Trim());

                dm.FromUserAccountID = communityManager.UserAccountID;
                dm.ToUserAccountID = ua.UserAccountID;

                sb = new StringBuilder(100);

                sb.Append(SiteDomain.GetSiteDomainValue(
                    SiteEnums.SiteBrandType.GREET,
                    Utilities.GetCurrentLanguageCode()));

                dm.Message = sb.ToString();

                if (communityManager.UserAccountID != 0)
                {
                    dm.CreatedByUserID = communityManager.UserAccountID;
                }

                dm.Create();

                return RedirectToAction("Home", "Account");
            }
            ModelState.AddModelError(string.Empty, AccountValidation.ErrorCodeToString(createStatus));

            return View(model);
        }