コード例 #1
0
        private void createUser(User user, string name, string status,
                                User.eGender gender, User.eGender interestedIn,
                                int ipIdx, int age, string img1, string img2)
        {
            var username = name.Replace(" ", "").Substring(0, 4) + age;
            var random = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
            int day = random.Next(1, 28);
            int month = random.Next(1, 12);
            int year = DateTime.Now.Year - age;

            if (!Classes.User.IsUsernameTaken(username))
            {
                user.Username = username;
                user.Password = username;
                user.Name = name;
                user.Gender = gender;
                user.InterestedIn = interestedIn;
                user.StatusText = status;
                user.Email = String.Format("{0}@ezFixUp.com", username);
                user.Birthdate = new DateTime(year, month, day);
                Classes.User.Create(user, String.Format("192.168.{0}.{1}", ipIdx / 255, ipIdx % 255));

                ProfileTopic[] topics = ProfileTopic.Fetch();
                foreach (ProfileTopic profileTopic in topics)
                {
                    ProfileQuestion[] questions = profileTopic.FetchQuestions();
                    foreach (ProfileQuestion profileQuestion in questions)
                    {
                        try
                        {
                            var existAnswer = ProfileAnswer.Fetch(username, profileQuestion.Id);
                            if (existAnswer != null) continue;
                        }
                        catch
                        {
                            ProfileChoice[] choices = profileQuestion.FetchChoices();
                            if (choices != null && choices.Length > 0)
                            {
                                var answer = new ProfileAnswer(username, profileQuestion.Id)
                                {
                                    Value = choices[random.Next(choices.Length - 1)].Value
                                };
                                try
                                {
                                    answer.Save();
                                }
                                catch (Exception ex) { }
                            }
                        }
                    }
                }
            }
            else
            {
                user = Classes.User.Load(username);
            }

            if (user != null && user.SignupIp.IsNotNullOrEmpty() && user.SignupIp.StartsWith("192.168."))
            {
                user.updateLastLogin(DateTime.Now.Ticks.ToString());

                var pathTemplate = Config.Directories.Home + @"\images\profiles\{0}.jpg";
                if (img1.Trim().IsNotNullOrEmpty())
                    StoreUserPhoto(user, String.Format(pathTemplate, img1), true);
                if (img2.IsNotNullOrEmpty())
                    StoreUserPhoto(user, String.Format(pathTemplate, img2), false);
            }
        }
コード例 #2
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                                                                                                                                                                                                                                                          VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV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VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV(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");
        }