Beispiel #1
0
        public ActionResult EditPhoto(HttpPostedFileBase file)
        {
            mu = Membership.GetUser();
            UserPhoto up1 = null;
            int swapID = 0;

            var acl = CannedAcl.PublicRead;

            S3Service s3 = new S3Service();

            s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
            s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

            if (Request.Form["new_default"] != null &&
                int.TryParse(Request.Form["new_default"], out swapID))
            {
                // swap the default with the new default
                uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

                string currentDefaultMain = uad.ProfilePicURL;
                string currentDefaultMainThumb = uad.ProfileThumbPicURL;

                up1 = new UserPhoto(swapID);

                uad.ProfilePicURL = up1.PicURL;
                uad.ProfileThumbPicURL = up1.ThumbPicURL;
                uad.LastPhotoUpdate = DateTime.UtcNow;
                uad.Update();

                up1.PicURL = currentDefaultMain;
                up1.ThumbPicURL = currentDefaultMainThumb;
                up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                up1.Update();

                LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey));

                return View(uad);
            }

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

            LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey));

            uad = new UserAccountDetail();
            uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

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

            string photoEdited = Request.Form["photo_edit"];
            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)
            {
                mainPhotoToDelete = uad.ProfilePicURL;
                thumbPhotoToDelete = uad.ProfileThumbPicURL;
            }
            else
            {
                if (ups.Count > 1 && photoEdited == photoTwo)
                {
                    up1 = new UserPhoto(ups[0].UserPhotoID);
                    up1.RankOrder = 1;
                    mainPhotoToDelete = up1.PicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }
                else if (ups.Count > 1 && photoEdited == photoThree)
                {
                    up1 = new UserPhoto(ups[1].UserPhotoID);
                    up1.RankOrder = 2;
                    mainPhotoToDelete = ups[1].FullProfilePicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }

            }

            if (!string.IsNullOrEmpty(mainPhotoToDelete))
            {
                // delete the existing photos
                try
                {

                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete);
                    }

                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete);
                    }
                }
                catch
                {
                    // whatever
                }
            }

            Bitmap b = new Bitmap(file.InputStream);

            // full
            System.Drawing.Image fullPhoto = (System.Drawing.Image)b;

            fullPhoto = ImageResize.FixedSize(fullPhoto, 300, 300, System.Drawing.Color.Black);

            string fileNameFull = Utilities.CreateUniqueContentFilename(file);

            Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

            s3.AddObject(
                maker,
                maker.Length,
                AmazonCloudConfigs.AmazonBucketName,
                fileNameFull,
                file.ContentType,
                acl);

            if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) ||
                ups.Count == 2 && photoEdited == photoOne)
            {
                uad.ProfilePicURL = fileNameFull;
            }
            else
            {
                if (up1 == null)
                {
                    up1 = new UserPhoto();
                }

                up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                up1.PicURL = fileNameFull;

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

                if (ups.Count == 1 && ups[0].RankOrder == 2)
                {
                    ups[0].RankOrder = 1;
                    ups[0].Update();
                }
            }

            fullPhoto = (System.Drawing.Image)b;

            fullPhoto = ImageResize.FixedSize(fullPhoto, 75, 75, System.Drawing.Color.Black);

            fileNameFull = Utilities.CreateUniqueContentFilename(file);

            maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

            s3.AddObject(
                maker,
                maker.Length,
                AmazonCloudConfigs.AmazonBucketName,
                fileNameFull,
                file.ContentType,
                acl);

            //// thumb

            if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) ||
                ups.Count == 2 && photoEdited == photoOne)
            {
                uad.ProfileThumbPicURL = fileNameFull;
                uad.LastPhotoUpdate = DateTime.UtcNow;
                uad.Set();
            }
            else
            {
                up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                up1.ThumbPicURL = fileNameFull;

                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;
                }
            }

            b.Dispose();

            if (up1 != null && up1.UserPhotoID == 0)
            {
                up1.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                up1.Create();
            }
            else if (up1 != null && up1.UserPhotoID > 0)
            {
                up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                up1.Update();
            }

            LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey));

            return View(uad);
        }
Beispiel #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (Utilities.IsSpamIP(Request.UserHostAddress))
            {
                // they are a duplicate IP and are no being referred by an existing user
                ModelState.AddModelError("", BootBaronLib.Resources.Messages.Invalid + ": " + Messages.Account);
                return View(model);
            }

            // ignore old browsers and duplicate IPs
            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();
            }
            else if (!BootBaronLib.Configs.GeneralConfigs.EnableSameIP &&
                UserAccount.IsAccountIPTaken(Request.UserHostAddress) &&
                string.IsNullOrEmpty(model.RefUser))
            {
                // they are a duplicate IP and are no being referred by an existing user
                ModelState.AddModelError("", BootBaronLib.Resources.Messages.Invalid + ": " + Messages.Account);
                return View(model);
            }

            TryUpdateModel(model);

            if (ModelState.IsValid)
            {
                if (!Utilities.IsEmail(model.Email))
                {
                    ModelState.AddModelError("", BootBaronLib.Resources.Messages.IncorrectFormat + ": " + BootBaronLib.Resources.Messages.EMail);
                    return View();
                }
                else 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("", BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.UserName);
                    return View();
                }
                else if (model.YouAreID == null)
                {
                    ModelState.AddModelError("", BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.YouAre);
                    return View();
                }

                DateTime dt = new DateTime();

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

                model.UserName = model.UserName.Replace(" ", string.Empty).Replace(":", string.Empty) /* still annoying errors */;

                // Attempt to register the user
                MembershipCreateStatus createStatus;

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

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

                    UserAccount ua = new UserAccount(model.UserName);
                    uad = new UserAccountDetail();
                    uad.UserAccountID = ua.UserAccountID;

                    uad.BirthDate = dt;
                    uad.YouAreID = model.YouAreID;
                    uad.DisplayAge = true;
                    uad.DefaultLanguage = Utilities.GetCurrentLanguageCode();

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

                    uad.Set();

                    StringBuilder 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.Append(Messages.UserName + ": ");
                    sb.Append(ua.UserName);
                    sb.Append(Environment.NewLine);
                    sb.Append(Messages.Password + ": ");
                    sb.Append(model.NewPassword);
                    sb.Append(Environment.NewLine);
                    sb.Append(BootBaronLib.Configs.GeneralConfigs.SiteDomain);

                    Utilities.SendMail(ua.EMail, Messages.YourNewAccountIsReadyForUse, sb.ToString());

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

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

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

                    return RedirectToAction("editprofile", "Account");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            return View(model);
        }
Beispiel #3
0
        public ActionResult Settings(NameValueCollection nvc)
        {
            ViewBag.IsValid = true;

            mu = Membership.GetUser();
            ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey));

            uad = new UserAccountDetail();

            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"];

            if (!string.IsNullOrEmpty(membersOnlyProfile))
                uad.MembersOnlyProfile = true;
            else uad.MembersOnlyProfile = false;

            if (!string.IsNullOrEmpty(enableProfileLogging))
                uad.EnableProfileLogging = true;
            else uad.EnableProfileLogging = false;

            if (!string.IsNullOrEmpty(displayAge))
                uad.DisplayAge = true;
            else uad.DisplayAge = false;

            if (!string.IsNullOrEmpty(emailmessages))
                uad.EmailMessages = true;
            else uad.EmailMessages = false;

            if (!string.IsNullOrEmpty(showonmap))
                uad.ShowOnMap = true;
            else uad.ShowOnMap = false;

            uad.Set();

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

            try
            {
                isValidName = !System.Text.RegularExpressions.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;
                UserAccount newUsername = new UserAccount(username.Replace(":", string.Empty) /* still annoying errors */);

                if (newUsername.UserAccountID != 0)
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError("", BootBaronLib.Resources.Messages.AlreadyInUse + ": " + BootBaronLib.Resources.Messages.UserName);
                    uad = new UserAccountDetail();

                    uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));
                    mu = Membership.GetUser();

                    ViewBag.UserAccountDetail = uad;
                    ViewBag.Membership = mu;
                    return View();
                }
                else
                {
                    if (!Utilities.IsEmail(Request.Form["email"]))
                    {
                        ViewBag.IsValid = false;
                        ModelState.AddModelError("", BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.EMail);
                        return View();
                    }
                    else if (Request.Form["email"].Trim() != ua.EMail)
                    {
                        ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey));
                        ua.EMail = Request.Form["email"];
                        ua.Update();
                    }

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

            ViewBag.ProfileUpdated = true;

            uad = new UserAccountDetail();

            uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));
            mu = Membership.GetUser();

            ViewBag.UserAccountDetail = uad;
            ViewBag.Membership = mu;

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

            return View();
        }
Beispiel #4
0
        public ActionResult EditProfile(UserAccountDetail uad)
        {
            // must change culture because decimal will not be correct for long/ lat
            string currentLang = Utilities.GetCurrentLanguageCode();

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

            LoadCountries();
            InterestIdentityViewBags();

            mu = Membership.GetUser();

            UserAccountDetail uadCurrent = new UserAccountDetail();
            uadCurrent.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
            uadCurrent.GetUserAccountDeailForUser(uadCurrent.UserAccountID);

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

            DateTime dt = new DateTime();

            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, BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.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, BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.Country);
                return View(uad);
            }

            if (string.IsNullOrEmpty(uad.PostalCode))
            {
                ViewBag.IsValid = false;
                ModelState.AddModelError(string.Empty, BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.PostalCode);
                return View(uad);
            }

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

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

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

            bool isNewProfile = false;

            if (string.IsNullOrEmpty(uad.Country.Trim()))
            {
                isNewProfile = true;
            }

            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);

                if (latlong.latitude != 0 && latlong.longitude != 0)
                {
                    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, BootBaronLib.Resources.Messages.Error);
            }

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

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

            return View(uad);
        }