Пример #1
0
        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            if (CurrentUsername == null) return;
            if (CurrentUsername != "admin")
            {
                if (CurrentGroupMember == null)
                {
                    Global.Logger.LogError("Unauthorized attempt to transfer a group by member " +
                                           CurrentUsername + " with IP " + Request.UserHostAddress + " (not a member)");
                    return;
                }
                if (!CurrentGroupMember.Active || CurrentGroupMember.Type != GroupMember.eType.Admin)
                {
                    Global.Logger.LogError("Unauthorized attempt to transfer a group by member " +
                                           CurrentUsername + " with IP " + Request.UserHostAddress +
                                           " (not active or admin)");
                    return;
                }
            }

            if (ddGroupMembers.SelectedValue == "admin" && !GroupMember.IsMember("admin", CurrentGroup.ID))
            {
                var groupMember = new GroupMember(CurrentGroup.ID, "admin")
                                      {
                                          Active = true,
                                          Type = GroupMember.eType.Admin
                                      };
                groupMember.Save();
                CurrentGroup.ActiveMembers++;
            }

            CurrentGroup.Owner = ddGroupMembers.SelectedValue;
            CurrentGroup.Save();

            MiscTemplates.TransferGroupOwnerMessage transferGroupOwnershipTemplate = null;
            User recipient = null;
            try
            {
                recipient = User.Load(ddGroupMembers.SelectedValue);
                transferGroupOwnershipTemplate = new MiscTemplates.TransferGroupOwnerMessage(recipient.LanguageId);
            }
            catch (NotFoundException)
            {
                transferGroupOwnershipTemplate = new MiscTemplates.TransferGroupOwnerMessage(PageBase.GetLanguageId());
            }
            var msg = new Message(((PageBase) Page).CurrentUserSession.Username, 
                ddGroupMembers.SelectedValue);
            string message = transferGroupOwnershipTemplate.Message;
            message = message.Replace("%%GROUP%%", Parsers.ProcessGroupName(CurrentGroup.Name));
            msg.Body = message;
            msg.Send();

            lblError.Text = Lang.Trans("The ownership has been transferred successfully.");

            mvEditGroup.SetActiveView(viewMain);
        }
Пример #2
0
        protected void btnCreateGroup_Click(object sender, EventArgs e)
        {
            #region Check groups per member limit

            int memberOf = GroupMember.Fetch(CurrentUserSession.Username).Length;
            int maxGroupsPermitted = 0;// Config.Groups.MaxGroupsPerMember;
            if (CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value > maxGroupsPermitted)
                maxGroupsPermitted = CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value;
            if (CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.MaxGroupsPerMember > maxGroupsPermitted)
                maxGroupsPermitted = CurrentUserSession.Level.Restrictions.MaxGroupsPerMember;

            if (memberOf >= maxGroupsPermitted && !CurrentUserSession.IsAdmin())
            {
                lblError.Text = String.Format(Lang.Trans("You are already a member of {0} groups. Please leave one of them first."), maxGroupsPermitted);
                return;
            }

            #endregion

            #region Set fields

            string terms = Config.Misc.EnableBadWordsFilterGroups
                               ? Parsers.ProcessBadWords(txtTerms.Text.Trim())
                               : txtTerms.Text.Trim();
            string name = Config.Misc.EnableBadWordsFilterGroups
                              ? Parsers.ProcessBadWords(txtName.Text.Trim())
                              : txtName.Text.Trim();
            string description = Config.Misc.EnableBadWordsFilterGroups
                                     ? Parsers.ProcessBadWords(txtDescription.Text.Trim())
                                     : txtDescription.Text.Trim();
            string question = Config.Misc.EnableBadWordsFilterGroups
                                  ? Parsers.ProcessBadWords(txtQuestion.Text.Trim())
                                  : txtQuestion.Text.Trim();
            Group.eAccessLevel accessLevel = (Group.eAccessLevel) Convert.ToInt32(ddAccessLevel.SelectedValue);
            string owner = CurrentUserSession.Username;

            #endregion

            #region Validate fields

            #region Validate Group name

            if (name.Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter group name.");
                return;
            }

            if (Group.IsNameUsed(name))
            {
                lblError.Text = Lang.Trans("Group name already exists.");
                return;
            }

            #endregion

            #region Validate Categories

            List<int> lCategoriesIDs = new List<int>();

            foreach (ListItem item in lbCategories.Items)
            {
                if (item.Selected)
                {
                    lCategoriesIDs.Add(Convert.ToInt32(item.Value));
                }
            }

            if (lCategoriesIDs.Count == 0)
            {
                lblError.Text = Lang.Trans("Please select category.");
                return;
            }

            #endregion

            #region Validate Description

            if (description.Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter group description.");
                return;
            }

            #endregion

            #region Validate Group Icon

            Image image = null;

            if (fuGroupImage.PostedFile.FileName.Length == 0)
            {
                image = Image.FromFile(Server.MapPath("~/Images") + "/defaultgroupicon.jpg");
            }
            else
            {
                try
                {
                    image = Image.FromStream
                        (fuGroupImage.PostedFile.InputStream);
                }
                catch
                {
                    lblError.Text = Lang.Trans("Invalid image!");
                    return;
                }
            }

            #endregion

            #endregion

            if (Group.IsNameUsed(name))
            {
                StatusPageMessage = Lang.Trans("Group with such name already exists!");

                Response.Redirect("~/ShowStatus.aspx");                
            }

            Group group = new Group();
            group.JoinTerms = terms;
            group.Name = name;
            group.Description = description;
            if (ddAgeRestriction.SelectedValue != "-1") group.MinAge = Convert.ToInt32(ddAgeRestriction.SelectedValue);

            if (CurrentUserSession != null && CurrentUserSession.IsAdmin() || Config.Groups.AutoApproveGroups)
            {
                group.Approved = true;
            }

            if (cbAutomaticallyJoin.Checked)
            {
                group.Autojoin = true;
                group.AutojoinCountry = dropCountry.SelectedValue.Trim() != String.Empty ? dropCountry.SelectedValue.Trim() : null;
                group.AutojoinRegion = dropRegion.SelectedValue.Trim() != String.Empty ? dropRegion.SelectedValue.Trim() : null;
                group.AutojoinCity = dropCity.SelectedValue.Trim() != String.Empty ? dropCity.SelectedValue.Trim() : null;
            }
            
            group.AccessLevel = accessLevel;
            group.Owner = owner;
            if (accessLevel == Group.eAccessLevel.Moderated)
                group.JoinQuestion = question;
            group.ActiveMembers++;
            group.Save();
            group.SetCategories(lCategoriesIDs.ToArray());

            Group.SaveIcon(group.ID, image);

            GroupMember groupMember = new GroupMember(group.ID, CurrentUserSession.Username);
            groupMember.Active = true;
            groupMember.Type = GroupMember.eType.Admin;
            groupMember.Save();

            StatusPageMessage = Lang.Trans("Your group has been created successfully!");

            Response.Redirect("~/ShowStatus.aspx");
        }
Пример #3
0
        private void JoinGroup(string answer)
        {
            if (CurrentUserSession != null)
            {
                if (CurrentGroup != null)
                {
                    if (CurrentGroup.AccessLevel == Group.eAccessLevel.Private && !CurrentUserSession.IsAdmin())
                    {
                        ((PageBase) Page).StatusPageMessage =
                            Lang.Trans(
                                "This is a private group and only invited users are allowed to join. Please use 'Pending Invitations' link in the Group section to join.");

                        Response.Redirect("~/ShowStatus.aspx");
                        return;
                    }

                    string username = CurrentUserSession.Username;

                    if (GroupMember.IsBanned(username, GroupID))
                    {
                        ShowMessage(Misc.MessageType.Success, Lang.Trans("You are banned!"));
                        return;
                    }

                    int memberOf = GroupMember.Fetch(username).Length;
                    int maxGroupsPermitted = 0;// Config.Groups.MaxGroupsPerMember;
                    if (CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value > maxGroupsPermitted)
                        maxGroupsPermitted = CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value;
                    if (CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.MaxGroupsPerMember > maxGroupsPermitted)
                        maxGroupsPermitted = CurrentUserSession.Level.Restrictions.MaxGroupsPerMember;

                    if (memberOf >= maxGroupsPermitted)
                    {
                        ShowMessage(Misc.MessageType.Error,
                                    String.Format(
                                        Lang.Trans(
                                            "You are already a member of {0} groups. Please leave one of them first."),
                                        maxGroupsPermitted));
                        return;
                    }

                    GroupMember groupMember = new GroupMember(CurrentGroup.ID, username);

                    groupMember.Active = CurrentGroup.AccessLevel == Group.eAccessLevel.Public
                                         || CurrentUserSession.IsAdmin()
                                             ? true
                                             : false;
                    groupMember.Type = CurrentUserSession.IsAdmin()
                                           ? GroupMember.eType.Admin
                                           : GroupMember.eType.Member;
                    groupMember.JoinAnswer = answer;
                    groupMember.Save();

                    if (groupMember.Active)
                    {
                        #region Add Event

                        Event newEvent = new Event(CurrentUserSession.Username);

                        newEvent.Type = Event.eType.FriendJoinedGroup;
                        FriendJoinedGroup friendJoinedGroup = new FriendJoinedGroup();
                        friendJoinedGroup.GroupID = CurrentGroup.ID;
                        newEvent.DetailsXML = Misc.ToXml(friendJoinedGroup);

                        newEvent.Save();

                        string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                        foreach (string friendUsername in usernames)
                        {
                            if (Config.Users.NewEventNotification)
                            {
                                string text =
                                    String.Format("Your friend {0} has joined the {1} group".Translate(),
                                                  "<b>" + CurrentUserSession.Username + "</b>",
                                                  Server.HtmlEncode(CurrentGroup.Name));
                                int imageID = 0;
                                try
                                {
                                    imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                                }
                                catch (NotFoundException)
                                {
                                    imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                                }
                                string thumbnailUrl =
                                    ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                Classes.User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername,
                                                                         text, thumbnailUrl,
                                                                         UrlRewrite.CreateShowGroupUrl(
                                                                             CurrentGroup.ID.ToString()));
                            }
                        }

                        #endregion
                    }

                    CurrentGroupMember = groupMember;

                    if (groupMember.Active)
                    {
                        CurrentGroup.ActiveMembers++;
                        CurrentGroup.Save();
                    }

                    if (CurrentGroup.AccessLevel == Group.eAccessLevel.Moderated && !CurrentUserSession.IsAdmin())
                    {
                        ((PageBase) Page).StatusPageMessage = Lang.Trans("Your join request has been sent.");

                        Response.Redirect("~/ShowStatus.aspx");
                    }
                }

                mvViewGroup.SetActiveView(vGroupInfo);
                OnJoinPanelClose(new EventArgs());
            }
        }
Пример #4
0
        /// <summary>
        /// Mark user account as deleted
        /// </summary>
        /// <param name="username">the username of the user whose account is about to be deleted</param>
        /// <param name="reason">The reason.</param>
        public static void Delete(string username, string reason)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlHelper.GetDB().ExecuteNonQuery( "DeleteUser", username, reason);
            }

            if (Config.Ratings.EnablePhotoContests)
            {
                PhotoContestEntry.DeleteByUsername(username);
            }

            if (Config.Groups.EnableGroups)
            {
                Group[] groups = Group.FetchGroupsByUsername(username);

                foreach (Group group in groups)
                {
                    if (!group.Approved)
                    {
                        Group.Delete(group.ID);
                    }
                    else
                    {
                        if (group.Owner == username)
                        {
                            GroupMember[] admins = GroupMember.Fetch(group.ID, GroupMember.eType.Admin,
                                                                     GroupMember.eSortColumn.JoinDate);
                            if (admins.Length > 1)
                            {
                                List<GroupMember> lAdmins = new List<GroupMember>();
                                foreach (GroupMember admin in admins)
                                {
                                    lAdmins.Add(admin);
                                }
                                lAdmins.Reverse();
                                admins = lAdmins.ToArray();
                                group.Owner = admins[1].Username; // the oldest administrator except the current owner
                            }
                            else
                            {
                                GroupMember[] moderators = GroupMember.Fetch(group.ID, GroupMember.eType.Moderator,
                                                                     GroupMember.eSortColumn.JoinDate);
                                if (moderators.Length > 0)
                                {
                                    List<GroupMember> lModerators = new List<GroupMember>();
                                    foreach (GroupMember moderator in moderators)
                                    {
                                        lModerators.Add(moderator);
                                    }
                                    lModerators.Reverse();
                                    moderators = lModerators.ToArray();
                                    group.Owner = moderators[0].Username; // the oldest moderator
                                }
                                else
                                {
                                    if (!GroupMember.IsMember(Config.Users.SystemUsername, group.ID))
                                    {
                                        GroupMember groupMember = new GroupMember(group.ID, Config.Users.SystemUsername);
                                        groupMember.Active = true;
                                        groupMember.Type = GroupMember.eType.Admin;
                                        groupMember.Save();
                                        group.ActiveMembers++;
                                    }

                                    group.Owner = Config.Users.SystemUsername;
                                }
                            }

                            group.ActiveMembers--;
                            group.Save();
                        }
                    }
                }
            }

            if (IsOnline(username))
            {
                var notification = new AccountDeletedNotification
                                       {
                                           Recipient = username,
                                           Text = "Your account has been deleted (" + reason + ")!"
                                       };
                RealtimeNotification.SendNotification(notification);
            }
        }
Пример #5
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {

            if (!FacebookHelper.IsCurrentSessionConnected)
            {
                #region Validate username

                Global.GetSessionState()["IsRegistrationFormValidated"] = false;

                try
                {
                    if (txtUsername.Text.Length < 6)
                    {
                        ResponseEndWithErrorMessage("Please specify username, at list 6 alphanumeric characters!");
                        return;
                    }

                    if (Classes.User.IsUsernameTaken(txtUsername.Text))
                    {
                        ResponseEndWithErrorMessage("Username is already taken!");
                        return;
                    }

                    foreach (string reservedUsername in Config.Users.ReservedUsernames)
                    {
                        if (reservedUsername == txtUsername.Text.ToLower())
                        {
                            ResponseEndWithErrorMessage("Username is reserved!");
                            return;
                        }
                    }
                }
                catch (ArgumentException err) // Invalid username
                {
                    ResponseEndWithErrorMessage(err.Message);
                    return;
                }

                #endregion

                #region Validate passwords

                if (txtPassword.Text.Length < 6)
                {
                    ResponseEndWithErrorMessage("Please specify password, at leaset 6 alphanumeric characters!");
                    return;
                }
                if (txtPassword2.Text.Length == 0)
                {
                    ResponseEndWithErrorMessage("Please verify password!");
                    return;
                }
                if (txtPassword.Text != txtPassword2.Text)
                {
                    ResponseEndWithErrorMessage("Passwords do not match!");
                    return;
                }

                #endregion

                #region Validate captcha

                if (Config.Misc.EnableCaptcha &&
                        (Global.GetSessionState()["Captcha_RandomCode"] == null || (string)Global.GetSessionState()["Captcha_RandomCode"] != txtCaptcha.Text))
                {
                    Global.GetSessionState()["Captcha_RandomCode"] = null;
                    UpdatePanel4.Update();
                    ResponseEndWithErrorMessage("Invalid verification code!");
                    return;
                }

                #endregion
            }
            else
            {
                txtUsername.Text = FacebookHelper.CurrentSessionUserID.ToString();
            }
            #region Validate e-mail address

            try
            {
                if (txtEmail.Text.Length == 0)
                {
                    ResponseEndWithErrorMessage("Please specify e-mail address!");
                    return;
                }

                if (txtEmail.Text.ToLower().EndsWith("@mail.bg"))
                {
                    ResponseEndWithErrorMessage("E-mails from mail.bg are not accepted!");
                    return;
                }

                if (Config.Users.CheckForDuplicateEmails && Classes.User.IsEmailUsed(txtEmail.Text))
                {
                    ResponseEndWithErrorMessage("E-mail address is already used!");
                    return;
                }
            }
            catch (ArgumentException err) // Invalid e-mail address
            {
                ResponseEndWithErrorMessage(err.Message);
                return;
            }

            #endregion

            #region Validate name

            if (txtName.Text.Length == 0)
            {
                ResponseEndWithErrorMessage("Please enter your name!");
                return;
            }

            #endregion

            #region Validate gender

            if (dropGender.SelectedIndex < 0)
            {
                ResponseEndWithErrorMessage("Please select your gender!");
                return;
            }

            #endregion

            bool isSingleAccount = (rblAccountType.SelectedIndex > 0);
            if (isSingleAccount)
            {
                #region Validate InterestedIn

                if (Config.Users.InterestedInFieldEnabled)
                {
                    if (dropInterestedIn.SelectedIndex < 0)
                    {
                        ResponseEndWithErrorMessage("Please select who are you interested in!");
                        return;
                    }
                }

                #endregion

                #region Validate birthdate1

                //IFormatProvider culture = new CultureInfo("he-IL", true);
                //string dateFormat = "dd/MM/yyyy";
                //DateTime parsedDate;
                //if (DateTime.TryParseExact(txtDatePicker.Text, dateFormat, culture, DateTimeStyles.None, out parsedDate))
                //    datePicker1.SelectedDate = parsedDate;
                datePicker1.SelectedDate = BirthdayPicker1.SelectedDate;
                if (!datePicker1.ValidDateEntered)
                {
                    ResponseEndWithErrorMessage("Please select valid birthdate!");
                    return;
                }

                #endregion

                //#region Validate birthdate2
                //if((User.eGender)Convert.ToInt32(dropGender.SelectedValue) == Classes.User.eGender.Couple
                //        && !datePicker2.ValidDateEntered) 
                //{
                //    lblError.Text = Lang.Trans("Please select valid birthdate") + "!";
                //    return;
                //}
                //#endregion

                #region Validate location

                if (Config.Users.LocationPanelVisible)
                {
                    if (dropCountry != null && dropCountry.SelectedValue == String.Empty)
                    {
                        ResponseEndWithErrorMessage("Please select your country!");
                        return;
                    }
                    //if (txtZipCode != null && txtZipCode.Text == String.Empty)
                    //{
                    //    lblError.Text = Lang.Trans("Please enter your Zip/Postal Code");
                    //    return;
                    //}

                    //ifA B                                                                                                                                                                                                                                                          VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV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VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV(dropRegion.Items.Count >= 1 && dropRegion.SelectedValue == "") {
                    //    ResponseEndWithErrorMessage("Please select your state!");
                    //    return;
                    //}
                    //if(dropCity != null && dropCity.SelectedValue == "") {
                    //    ResponseEndWithErrorMessage("Please select your city!");
                    //    return;
                    //}
                }

                #endregion
            }

            #region Validate agreement

            if (!cbAgreement.Checked)
            {
                ResponseEndWithErrorMessage("You must accept the agreement to proceed!");
                return;
            }

            #endregion


            #region Validate Invitation Code
            if (Config.Users.InvitationCode != String.Empty)
            {
                if (Config.Users.InvitationCode != txtInvitationCode.Text)
                {
                    ResponseEndWithErrorMessage("Invalid Invitation Code!");
                    return;
                }
            }
            #endregion

            #region Validate IP address

            if (Properties.Settings.Default.BannedCountries.Count > 0)
            {
                foreach (string countryCode in Properties.Settings.Default.BannedCountries)
                {
                    if (IPToCountry.GetCountry(Request.UserHostAddress) == countryCode.Trim())
                    {
                        ResponseEndWithErrorMessage("Registration is not allowed for your country!");
                        return;
                    }
                }
            }

            #endregion

            Global.GetSessionState()["IsRegistrationFormValidated"] = true;

            var postRegistrationPopup = @"<div class='PostRegistrationPopupBg' >
                                        <table border='0' cellpadding='0' cellspacing='0' width='100%'>
                                            <tr style='height:40px;width:100%;'>
                                                <td></td>
                                            </tr>
                                            <tr style='height:30px;width:100%;'>
                                                <td></td>
                                            </tr>
                                            <tr style='height:55px;width:100%;'>
                                                <td>
                                                    <div class='fl' style='width:220px;height:50px;margin-left:40px;cursor:pointer;' 
                                                        onclick=""window.location='ManageProfile.aspx'""></div>
                                                    <div class='fl' style='width:200px;height:50px;margin-left:20px;cursor:pointer;'
                                                        onclick=""window.location='Home.aspx'""></div>
                                                </td>
                                            </tr>
                                            <tr style='height:30px;width:100%;'>
                                                <td></td>
                                            </tr>
                                        </table>
                                    </div>";
            //postRegistrationPopup = "";
            #region Validate Coupon Code
            var couponTxt = txtCouponCode.Text.Trim();
            bool useCoupon = false;
            Coupon coupon = null;

            if (couponTxt.IsNullOrEmpty())
                couponTxt = "FA7Z8X";

            //if (couponTxt.IsNotNullOrEmpty())
            {
                coupon = Coupon.Fetch(couponTxt);
                if (coupon == null)
                {
                    ResponseEndWithErrorMessage("Invalid Coupon Code!");
                    return;
                }
                else if (coupon.MaxUse > coupon.Used)
                {
                    useCoupon = true;
                    Coupon.UpdateUsedCounterByAddCount(couponTxt, 1);
                }
            }
            #endregion

            try
            {
                User newUser = new User(txtUsername.Text);

                newUser.Gender = (User.eGender)Convert.ToInt32(dropGender.SelectedValue);
                if (newUser.Gender == Classes.User.eGender.Couple)
                {
                    newUser.Birthdate2 = datePicker2.SelectedDate;
                }


                if (isSingleAccount)
                {
                    #region Save location

                    if (Config.Users.LocationPanelVisible)
                    {
                        if (dropCountry != null)
                        {
                            newUser.Country = dropCountry.SelectedValue;
                        }
                        if (dropRegion != null)
                        {
                            newUser.State = dropRegion.SelectedValue;
                        }
                        //if (txtZipCode != null)
                        //{
                        //    newUser.ZipCode = txtZipCode.Text;
                        //}
                        if (dropCity != null)
                        {
                            newUser.City = dropCity.SelectedValue;
                        }

                        Location loc = Config.Users.GetLocation(newUser.Country, newUser.State, newUser.City);

                        if (loc != null)
                        {
                            newUser.Longitude = loc.Longitude;
                            newUser.Latitude = loc.Latitude;
                        }
                    }

                    #endregion

                    if (Config.Users.InterestedInFieldEnabled)
                    {
                        newUser.InterestedIn = (User.eGender)Convert.ToInt32(dropInterestedIn.SelectedValue);
                    }
                    else
                    {
                        if (Config.Users.DisableGenderInformation)
                            newUser.InterestedIn = Classes.User.eGender.Male;
                        else
                            newUser.InterestedIn = newUser.Gender == Classes.User.eGender.Male
                                                     ? Classes.User.eGender.Female
                                                     : Classes.User.eGender.Male;
                    }

                }

                datePicker1.SelectedDate = BirthdayPicker1.SelectedDate;// DateTime.Parse(txtDatePicker.Text);
                newUser.Birthdate = datePicker1.SelectedDate;

                newUser.Email = txtEmail.Text;
                newUser.Name = txtName.Text;
                var pass = (-DateTime.Now.Ticks).ToString();
                if (pass.Length > 20) pass = pass.Substring(0, 20);
                newUser.Password = FacebookHelper.IsCurrentSessionConnected
                                        ? pass : txtPassword.Text;
                newUser.LanguageId = LanguageId;

                newUser.ReceiveEmails = Config.Users.EmailNotificationsDefault;
                if (ViewState["TokenUniqueId"] is string)
                    newUser.TokenUniqueId = (string)ViewState["TokenUniqueId"];

                #region Set and Delete invitedBy cookie

                if (Request.Cookies["invitedBy"] != null)
                {
                    newUser.InvitedBy = Server.HtmlEncode(Request.Cookies["invitedBy"].Value);

                    HttpCookie cookie = new HttpCookie("invitedBy");
                    cookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(cookie);
                }

                #endregion

                #region Set and Delete affiliateID cookie

                if (Request.Cookies["affiliateID"] != null)
                {
                    newUser.AffiliateID = Convert.ToInt32(Server.HtmlEncode(Request.Cookies["affiliateID"].Value));

                    HttpCookie cookie = new HttpCookie("affiliateID");
                    cookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(cookie);
                }

                #endregion

                if (Config.Misc.EnableMySpaceIntegration)
                    newUser.MySpaceID = MySpaceID;

                if (Config.Misc.EnableFacebookIntegration)
                    newUser.FacebookID = FacebookID;

                newUser.Create(Request.UserHostAddress);

                if (useCoupon)
                {
                    var username = newUser.Username;
                    Coupon.UpdateUsedCounterByAddCount(couponTxt, 1);

                    //give coupon gift to new user

                    var allBillingPlans = BillingPlan.Fetch();
                    BillingPlan plan = allBillingPlans.Where(p => p.Cycle == 1).FirstOrDefault();

                    var subId = Subscription.Create(username, plan.ID, "coupon = " + couponTxt);
                    var activeSubscription = Subscription.Fetch(subId);
                    activeSubscription.Activate(DateTime.Now);

                    if (coupon.CouponTypeId > (int)CouponType.eCouponType.PremiumMonth1)
                        activeSubscription.Renew(plan);

                    if (coupon.CouponTypeId > (int)CouponType.eCouponType.PremiumMonth2)
                        activeSubscription.Renew(plan);
                }
                else
                {
                    newUser.Credits = 181818;
                    newUser.Update();
                }

                if (Global.GetSessionState().ContainsKey("InvitedBy"))
                {
                    newUser.InvitedBy = Global.GetSessionState()["InvitedBy"] as string;
                    var byUser = Classes.User.Load(newUser.InvitedBy);
                    if (byUser != null)
                    {
                        byUser.InvitedByCount++;

                        if ((byUser.InvitedByCount % Config.UserScores.InvitedByCounter) == 0)
                        {
                            // Send Announcement Message + Assign a Gift
                            byUser.SendMessageInvitedByCounterTriggered("");
                        }
                        byUser.Update();
                    }
                    else
                    {
                        var invitations = HttpContext.Current.GetAppInvitationsForCurrentUser()
                                            .Where(i => i.CreatedTime > DateTime.Now.AddYears(-1))
                                            .OrderByDescending(i => i.CreatedTime)
                                            .Take(10).ToList(); //max 10 users in last year will be credited 

                        foreach (var inv in invitations)
                        {
                            var newInvitation = new FacebookInvitation(inv.RequestId, inv.SenderId, inv.RecipientId, inv.CreatedTime);
                            newInvitation.Save();
                        }
                    }
                }

                newUser.updateLastLogin(newUser.LastSessionID);

                StorePrimaryPhoto(newUser);
                if (File.Exists(LastAsyncFileUploadLocation))
                    File.Delete(LastAsyncFileUploadLocation);

                if (Config.Users.SmsConfirmationRequired)
                {
                    Response.Redirect("SmsConfirm.aspx?username="******"<b>Your account has been created successfully!</b><br>" +
                    //                                   "Please click on the link below to edit your profile.<br><br>");

                    //NameValueCollection link = new NameValueCollection();
                    //link.Add(Config.Urls.Home + "/ManageProfile.aspx", Config.Urls.Home + "/ManageProfile.aspx");
                    //StatusPageLink = link;
                    //((PageBase)Page).StatusPageLinkSkindId = "";
                    //((PageBase)Page).StatusPageLinkText = Config.Urls.Home + "/ManageProfile.aspx";
                    //((PageBase)Page).StatusPageLinkURL = Config.Urls.Home + "/ManageProfile.aspx";

                    UserSession userSession = null;
                    try
                    {
                        userSession = new UserSession(newUser.Username);
                        ((PageBase)Page).CurrentUserSession = userSession;
                        MatchmakerHelper.CurrentUsername = userSession.Username;
                        userSession.Authorize(Session.SessionID);

                        //if(Config.Misc.EnableMySpaceIntegration ||
                        if (Config.Misc.EnableFacebookIntegration)
                        {
                            FacebookHelper.AddFriends(newUser, 0, HttpContext.Current, null);
                        }


                        #region Autojoin to group

                        Group[] autojoinGroups = Group.Fetch(true);

                        if (autojoinGroups.Length > 0)
                        {
                            var groups =
                                    autojoinGroups.Where(
                                            g => g.Approved &&
                                            (g.AutojoinCountry == null || g.AutojoinCountry == userSession.Country) &&
                                            (g.AutojoinRegion == null || g.AutojoinRegion == userSession.State) &&
                                            (g.AutojoinCity == null || g.AutojoinCity == userSession.City));
                            foreach (Group group in groups)
                            {
                                GroupMember groupMember = new GroupMember(group.ID, userSession.Username);
                                groupMember.Active = true;
                                groupMember.Type = GroupMember.eType.Member;
                                groupMember.Save();
                                group.ActiveMembers++;
                                group.Save();
                            }
                        }

                        #endregion

                        //Response.Redirect("ManageProfile.aspx");
                        //multiViewButtons.ActiveViewIndex = 1;
                        //return;
                        StatusPageMessage = Lang.Trans("<b>Your account has been created successfully!</b><br><br>")
                                            + postRegistrationPopup;

                    }
                    catch (Exception err)
                    {
                        StatusPageMessage = err.Message;
                    }
                }
                else
                {
                    newUser.Active = false;
                    newUser.Update();
                    StatusPageMessage = Lang.Trans
                                            ("<b>Your account has been created successfully!</b><br><br>"
                                             + "You will receive a confirmation e-mail shortly. In order "
                                             + "to finish your registration you'll have to click the "
                                             + "activation link in the e-mail.");
                    Email.SendTemplateEmail(typeof(EmailTemplates.RegistrationConfirmation), newUser.Email, true, newUser.LanguageId);
                }
                if (newUser.InterestedIn == Classes.User.eGender.Matchmaker)
                    Response.Redirect("Home_mm.aspx");
            }
            catch (System.Threading.ThreadAbortException) { }
            catch (ArgumentException err)
            {
                ResponseEndWithErrorMessage(err.Message);
                return;
            }
            catch (Exception err)
            {
                ResponseEndWithErrorMessage("Unknown error has occured while trying to create your account! Please try again later.");
                Log(err);
                return;
            }
            Response.Redirect("ShowStatus.aspx");
        }
Пример #6
0
        public static bool HasPermission(UserSession userSession, GroupMember groupMember, Group group, eGroupPermissionType permissionType)
        {
            bool hasNonMembersPermissions = false;
            bool hasMembersPermissions = false;
            bool hasVipMembersPermissions = false;

            switch(permissionType)
            {
                case eGroupPermissionType.ViewGroup:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewGroupNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewGroupMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewGroupVip);
                    break;
                case eGroupPermissionType.ViewMessageBoard:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewMessageBoardNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewMessageBoardMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewMessageBoardVip);
                    break;
                case eGroupPermissionType.ViewGallery:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewGalleryNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewGalleryMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewGalleryVip);
                    break;
                case eGroupPermissionType.ViewMembers:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewMembersNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewMembersMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewMembersVip);
                    break;
                case eGroupPermissionType.ViewEvents:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewEventsNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewEventsMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.ViewEventsVip);
                    break;
                case eGroupPermissionType.UploadPhoto:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.UploadPhotoNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.UploadPhotoMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.UploadPhotoVip);
                    break;
                case eGroupPermissionType.UseChat:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.UseChatNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.UseChatMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.UseChatVip);
                    break;
                case eGroupPermissionType.AddTopic:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddTopicNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddTopicMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddTopicVip);
                    break;
                case eGroupPermissionType.AddPost:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddPostNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddPostMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddPostVip);
                    break;
                case eGroupPermissionType.AddEvent:
                    hasNonMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddEventNonMembers);
                    hasMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddEventMembers);
                    hasVipMembersPermissions = group.IsPermissionEnabled(eGroupPermissions.AddEventVip);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("permissionType");
            }

            if (userSession != null)
            {
                if (groupMember == null && !hasNonMembersPermissions)
                {
                    return false;
                }
                else if (groupMember != null)
                {
                    if (!groupMember.Active)
                    {
                        if (!hasNonMembersPermissions)
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if ((groupMember.Type == eType.Member && !hasMembersPermissions) ||
                            (groupMember.Type == eType.VIP && !hasVipMembersPermissions))
                        {
                            return false;
                        }
                    }
                }
            }
            else // is not logged in
            {
                if (!hasNonMembersPermissions)
                {
                    return false;
                }
            }

            return true;
        }
Пример #7
0
 public static bool IsAuthorized(UserSession userSession, GroupMember groupMember, Group group)
 {
     if (userSession != null && userSession.IsAdmin())
     {
         return true;
     }
     else if (group == null || (groupMember == null && group.AccessLevel == Group.eAccessLevel.Private))
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Пример #8
0
        /// <summary>
        /// Fetches group members from DB by specified group ID, username, type or active status.
        /// If all arguments are null it returns all group members from DB.
        /// If it cannot find a record in DB by specified arguments it returns an empty array.
        /// </summary>
        /// <param name="groupID">The group ID.</param>
        /// <param name="username">The username.</param>
        /// <param name="type">The type.</param>
        /// <param name="active">The active.</param>
        /// <param name="joinDate">The join date.</param>
        /// <param name="invitedBy">The invited by.</param>
        /// <param name="numberOfMembers">The number of members.</param>
        /// <returns>Group members array or an empty array if no group members are found in DB.</returns>
        private static GroupMember[] Fetch(int? groupID, string username, eType? type, bool? active,
                                                DateTime? joinDate, string invitedBy,
                                                int? numberOfMembers, eSortColumn sortColumn)
        {
            //using (var conn = Config.DB.Open())
            {
                List<GroupMember> groupMembers = new List<GroupMember>();

                using (var reader = SqlHelper.GetDB().ExecuteReader("FetchGroupMembers",
                                                                    groupID, username, type, active, joinDate, invitedBy,
                                                                    numberOfMembers, sortColumn))
                {

                    while (reader.Read())
                    {
                        GroupMember groupMember = new GroupMember();

                        groupMember.groupID = (int) reader["GroupID"];
                        groupMember.username = (string) reader["Username"];
                        groupMember.type = (eType) reader["Type"];
                        groupMember.active = (bool) reader["Active"];
                        groupMember.joinDate = (DateTime) reader["JoinDate"];
                        groupMember.invitedBy = reader["InvitedBy"] != DBNull.Value
                                                    ? (string) reader["InvitedBy"]
                                                    : null;
                        groupMember.joinAnswer = (string) reader["JoinAnswer"];
                        groupMember.isWarned = (bool) reader["IsWarned"];
                        groupMember.warnReason = reader["WarnReason"] != DBNull.Value
                                                     ? (string) reader["WarnReason"]
                                                     : null;
                        groupMember.warnExpirationDate = reader["WarnExpirationDate"] != DBNull.Value
                                                             ? (DateTime?) reader["WarnExpirationDate"]
                                                             : null;

                        groupMembers.Add(groupMember);
                    }
                    reader.Close();
                }
                return groupMembers.ToArray();
            }
        }
Пример #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Put user code to initialize the page here
            if (!Page.IsPostBack)
            {
                string username = Request.Params["username"];
                string guid = Request.Params["guid"];

                if (username != null)
                {
                    User user;
                    try
                    {
                        user = Classes.User.Load(username);
                    }
                    catch (NotFoundException)
                    {
                        StatusPageMessage =
                            Lang.Trans(
                                "Your registration has expired! Please register and create your account again.<br><br>");
                        Response.Redirect("Registr.aspx");
                        return;
                    }
                    if (Classes.User.IsValidPendingGuid(username, guid))
                    {
                        user.Active = true;
                        user.Update();

                        if (Config.Users.SendWelcomeMessage)
                        {
                            Message.SendWelcomeMessage(user);
                        }

                        Classes.User.RemovePendingGuids(guid, username);

                        StatusPageMessage = Lang.Trans("<b>Your registration has been confirmed!</b><br>" +
                                                       "Please click on the link below to edit your profile.<br><br>");

                        //NameValueCollection link = new NameValueCollection();
                        //link.Add(Config.Urls.Home + "/ManageProfile.aspx", Config.Urls.Home + "/ManageProfile.aspx");
                        //StatusPageLink = link;
                        ((PageBase)Page).StatusPageLinkSkindId = "";
                        ((PageBase)Page).StatusPageLinkText = Config.Urls.Home + "/ManageProfile.aspx";
                        ((PageBase)Page).StatusPageLinkURL = Config.Urls.Home + "/ManageProfile.aspx";

                        UserSession userSession = null;
                        try
                        {
                            userSession = new UserSession(username);
                            userSession.Authorize(Session.SessionID);
                            ((PageBase)Page).CurrentUserSession = userSession;

                            #region Autojoin to group

                            Group[] autojoinGroups = Group.Fetch(true);

                            if (autojoinGroups.Length > 0)
                            {
                                var groups =
                                    autojoinGroups.Where(
                                        g => g.Approved &&
                                        (g.AutojoinCountry == null || g.AutojoinCountry == userSession.Country) &&
                                        (g.AutojoinRegion == null || g.AutojoinRegion == userSession.State) &&
                                        (g.AutojoinCity == null || g.AutojoinCity == userSession.City));
                                foreach (Group group in groups)
                                {
                                    GroupMember groupMember = new GroupMember(group.ID, userSession.Username);
                                    groupMember.Active = true;
                                    groupMember.Type = GroupMember.eType.Member;
                                    groupMember.Save();
                                    group.ActiveMembers++;
                                    group.Save();
                                }
                            }

                            #endregion
                        }
                        catch (Exception err)
                        {
                            StatusPageMessage = err.Message;
                        }

                        Response.Redirect("ShowStatus.aspx");
                    }
                    else
                    {
                        StatusPageMessage =
                            Lang.Trans(
                                "<b>Your account is already confirmed or the provided confirmation URL is wrong</b><br><br>");
                        Response.Redirect("ShowStatus.aspx");
                    }
                }
            }
        }
Пример #10
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (txtFriend1.Text.Trim().Length == 0
                && txtFriend2.Text.Trim().Length == 0
                && txtFriend3.Text.Trim().Length == 0
                && txtFriend4.Text.Trim().Length == 0
                && txtFriend5.Text.Trim().Length == 0
                && txtFriend6.Text.Trim().Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter username!");
                return;
            }

            if (txtFriend1.Text.Trim().Length != 0 && txtFriend1.Text.Trim() == CurrentUserSession.Username
                || txtFriend2.Text.Trim().Length != 0 && txtFriend2.Text.Trim() == CurrentUserSession.Username
                || txtFriend3.Text.Trim().Length != 0 && txtFriend3.Text.Trim() == CurrentUserSession.Username
                || txtFriend4.Text.Trim().Length != 0 && txtFriend4.Text.Trim() == CurrentUserSession.Username
                || txtFriend5.Text.Trim().Length != 0 && txtFriend5.Text.Trim() == CurrentUserSession.Username
                || txtFriend6.Text.Trim().Length != 0 && txtFriend6.Text.Trim() == CurrentUserSession.Username)
            {
                lblError.Text = Lang.Trans("You are already a member for this group!");
                return;
            }

            List<string> invitedUsers = new List<string>();
            List<string> unexistedUsers = new List<string>();
            List<string> deletedUsers = new List<string>();
            List<string> inactiveUsers = new List<string>();
            List<string> alreadyMembers = new List<string>();
            List<string> exceededMembers = new List<string>();

            checkUser(txtFriend1, invitedUsers, unexistedUsers, deletedUsers, inactiveUsers, alreadyMembers, exceededMembers);
            checkUser(txtFriend2, invitedUsers, unexistedUsers, deletedUsers, inactiveUsers, alreadyMembers, exceededMembers);
            checkUser(txtFriend3, invitedUsers, unexistedUsers, deletedUsers, inactiveUsers, alreadyMembers, exceededMembers);
            checkUser(txtFriend4, invitedUsers, unexistedUsers, deletedUsers, inactiveUsers, alreadyMembers, exceededMembers);
            checkUser(txtFriend5, invitedUsers, unexistedUsers, deletedUsers, inactiveUsers, alreadyMembers, exceededMembers);
            checkUser(txtFriend6, invitedUsers, unexistedUsers, deletedUsers, inactiveUsers, alreadyMembers, exceededMembers);

            string[] strUnexistedUsers = unexistedUsers.ToArray();
            string[] strDeletedUsers = deletedUsers.ToArray();
            string[] strInactiveUsers = inactiveUsers.ToArray();
            string[] strAlreadyMembers = alreadyMembers.ToArray();
            string[] strExceededMembers = exceededMembers.ToArray();
            string strUnexisted = "";
            string strDeleted = "";
            string strInactive = "";
            string strAlready = "";
            string strExceeded = "";

            if (strUnexistedUsers.Length > 0)
            {
                strUnexisted = strUnexistedUsers.Length == 1 ? Lang.Trans("doesn't exist") : Lang.Trans("doesn't exists");    
            }

            if (strDeletedUsers.Length > 0)
            {
                strDeleted = strDeletedUsers.Length == 1 ? Lang.Trans("is deleted") : Lang.Trans("are deleted");
            }

            if (strInactiveUsers.Length > 0)
            {
                strInactive = strInactiveUsers.Length == 1 ? Lang.Trans("is not active") : Lang.Trans("are not active");
            }

            if (strAlreadyMembers.Length > 0)
            {
                strAlready = strAlreadyMembers.Length == 1 ? Lang.Trans("is already a member") : Lang.Trans("are already members");
            }

            if (strExceededMembers.Length > 0)
            {
                strExceeded = strExceededMembers.Length == 1 ? Lang.Trans("has reached his groups limit") : Lang.Trans("has reached their groups limit");
            }

            lblError.Text = String.Format("{0} {1} <br> {2} {3} <br> {4} {5} <br> {6} {7} <br> {8} {9}",
                String.Join(", ", strUnexistedUsers), strUnexisted,
                String.Join(", ", strDeletedUsers), strDeleted,
                String.Join(", ", strInactiveUsers), strInactive,
                String.Join(", ", strAlreadyMembers), strAlready,
                String.Join(", ", strExceededMembers), strExceeded);

            if (strUnexistedUsers.Length > 0 || strDeletedUsers.Length > 0
                || strInactiveUsers.Length > 0 || strAlreadyMembers.Length > 0 ||
                strExceededMembers.Length > 0)
            {
                return;
            }

            if (GroupMember.InvitationsCount(CurrentUserSession.Username, DateTime.Now.AddDays(-7)) >= Config.Groups.MaxInvitations)
            {
                lblError.Text = Lang.Trans("You have reached your invitations limit.");
                return;
            }

            MiscTemplates.InviteGroupMemberMessage inviteGroupMemberTemplate = null;

            foreach (string username in invitedUsers)
            {
                try
                {
                    User recipient  = User.Load(username);

                    GroupMember groupMember = new GroupMember(GroupID, username);
                    groupMember.InvitedBy = CurrentUserSession.Username;
                    groupMember.Save();

                    inviteGroupMemberTemplate = new MiscTemplates.InviteGroupMemberMessage(recipient.LanguageId);
                    Message msg = new Message(((PageBase)Page).CurrentUserSession.Username, username);
                    msg.Body = inviteGroupMemberTemplate.Message.Replace("%%SENDER%%", CurrentUserSession.Username);
                    msg.Body = msg.Body.Replace("%%GROUP%%", Parsers.ProcessGroupName(CurrentGroup.Name));
                    msg.Send();
                }
                catch (NotFoundException)
                {
                }
            }

            pnlInviteFriends.Visible = false;
            btnSend.Visible = false;

            lblError.CssClass = "message";
            lblError.Text = Lang.Trans("The invitation has been sent to your friends.");
        }