private bool RegisterGroup()
        {
            if (Page.IsValid)
            {
                // check required fields
                aqufitEntities entities = new aqufitEntities();
                Group test = entities.UserSettings.OfType<Group>().FirstOrDefault(g => g.UserName == atiGroupName.Text);
                // if a user is found with that username, error. this prevents you from adding a username with the same name as a superuser.
                if (test != null)
                {
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"We already have an entry for the Group Name.\"}');");
                    return false;
                }
                Affine.WebService.RegisterService regService = new WebService.RegisterService();

                string fname = string.Empty;
                string lname = string.Empty;
                string pass = Guid.NewGuid().ToString();

                Group us = new Data.Group();
                us.UserKey = 0;
                us.PortalKey = PortalId;
                us.UserEmail = atiTxtGroupEmail.Text;
                us.UserName = atiGroupName.Text;
                us.UserFirstName = atiGroupName.Text;
                us.UserLastName = "";
                us.DefaultMapLat = atiAddress.Lat;
                us.DefaultMapLng = atiAddress.Lng;
                us.LngHome = atiAddress.Lat;
                us.LngHome = atiAddress.Lng;
                int gtype = Convert.ToInt32(ddlGroupType.SelectedValue);
                us.GroupType = entities.GroupTypes.FirstOrDefault(gt => gt.Id == gtype);

                us.Places.Add(new Place()
                {
                    City = atiAddress.City,
                    Country = atiAddress.Country,
                    Email = atiTxtGroupEmail.Text,
                    Lat = atiAddress.Lat,
                    Lng = atiAddress.Lng,
                    Name = atiGroupName.Text,
                    Postal = atiAddress.Postal,
                    Region = atiAddress.Region,
                    Street = atiAddress.Street
                });
                entities.AddToUserSettings(us);
                entities.SaveChanges();
                // Now assign the creator of the group as an admin
                Group group = entities.UserSettings.OfType<Group>().First(g => g.UserName == us.UserName);
                UserFriends uToG = new UserFriends()
                {
                    SrcUserSettingKey = UserSettings.Id,
                    DestUserSettingKey = group.Id,
                    Relationship = (short)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER
                };
                entities.AddToUserFriends(uToG);
                entities.SaveChanges();
                Response.Redirect(ResolveUrl("~") + "group/" + group.UserName + "/settings", true);
            }
            else
            {
                RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"\"}');");
            }
            return true;
        }
        private bool Register()
        {
            //Try
            // Only attempt a save/update if all form fields on the page are valid
            if (Page.IsValid)
            {
                // check required fields
                int UID = -1;
                UserInfo objUserInfo = UserController.GetUserByName(PortalId, atiUserName.Text);
                // if a user is found with that username, error. this prevents you from adding a username with the same name as a superuser.
                if (objUserInfo != null)
                {
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"We already have an entry for the User Name.\"}');");
                    return false;
                }
                Affine.WebService.RegisterService regService = new WebService.RegisterService();
                double? timezone = null;
                if (!string.IsNullOrEmpty(atiSlimControl.LocLat))
                {
               //         timezone = regService.GetTimeZone(Convert.ToDouble(atiSlimControl.LocLat), Convert.ToDouble(atiSlimControl.LocLng));
                }
                UserInfo objNewUser = regService.InitialiseUser(PortalId);
                string fullname = atiSlimControl.FullName;
                string[] nameparts = fullname.Split(' ');
                string fname = string.Empty;
                string lname = string.Empty;
                if (nameparts.Length >= 2)
                {
                    fname = nameparts[0];
                    lname = nameparts[1];
                }

                regService.populateDnnUserInfo(PortalId, ref objNewUser, fname, lname, atiUserName.Text, atiSlimControl.Email, atiPassword.Password, atiSlimControl.Postal, atiSlimControl.Address, timezone);

                DotNetNuke.Security.Membership.UserCreateStatus userCreateStatus = UserController.CreateUser(ref objNewUser);
                if (userCreateStatus == DotNetNuke.Security.Membership.UserCreateStatus.Success)
                {
                    UID = objNewUser.UserID;
                    // DNN3 BUG
                    DotNetNuke.Services.Log.EventLog.EventLogController objEventLog = new DotNetNuke.Services.Log.EventLog.EventLogController();
                    objEventLog.AddLog(objNewUser, PortalSettings, objNewUser.UserID, atiSlimControl.Email, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.USER_CREATED);

                    // send notification to portal administrator of new user registration
            //            DotNetNuke.Services.Mail.Mail.SendMail(objNewUser, DotNetNuke.Services.Mail.MessageType.UserRegistrationAdmin, PortalSettings);
            //            DotNetNuke.Services.Mail.Mail.SendMail(objNewUser, DotNetNuke.Services.Mail.MessageType.UserRegistrationPublic, PortalSettings);
                    DataCache.ClearUserCache(PortalId, objNewUser.Username);
                    UserController.UserLogin(PortalId, objNewUser, PortalSettings.PortalName, DotNetNuke.Services.Authentication.AuthenticationLoginBase.GetIPAddress(), true);

                    User us = new Data.User();
                    us = (User)populateUserSettings(us, objNewUser);
                    if (atiBodyComp.BirthDateVisible)
                    {
                        us.BirthDate = atiBodyComp.BirthDate;
                    }
                    SiteSetting tutorial = new SiteSetting()
                    {
                        UserSetting = us,
                        Name = "SiteIntro",
                        Value = "1"
                    };
                    entities.AddToUserSettings(us);
                    entities.SaveChanges();

                    us = entities.UserSettings.OfType<User>().FirstOrDefault( u => u.UserKey == objNewUser.UserID && u.PortalKey == objNewUser.PortalID );

                    // TODO: should have a populate function for these
                    BodyComposition bc = new BodyComposition()
                    {
                        UserSetting = us
                    };
                    if (atiBodyComp.FitnessLevelVisible)
                    {
                        bc.FitnessLevel = atiBodyComp.FitnessLevel;
                    }

                    // need height and weight conversions
                    if (atiBodyComp.WeightVisible)
                    {
                        bc.Weight = atiBodyComp.UserWeightInSystemDefault;
                    }
                    if( atiBodyComp.HeightVisible )
                    {
                        bc.Height = atiBodyComp.UserHeightInSystemDefault;
                    }
                    entities.AddToBodyComposition(bc);
                    entities.SaveChanges();

                    string body = "User registration recorded\n\n";
                           body += "ID: " + objNewUser.UserID + "\n";
                           body += "User: "******"\n";
                           body += "First Name: " + objNewUser.FirstName + "\n";
                           body += "Last Name: " + objNewUser.LastName + "\n";
                           body += "Email: " + objNewUser.Email + "\n";
                           body += "Portal: " + objNewUser.PortalID + "\n";
                           body += "User-Agent: " + Request.UserAgent + "\n\n";
             //           DotNetNuke.Services.Mail.Mail.SendMail("*****@*****.**", "*****@*****.**", "", "NEW aqufit.com USER", body, "", "HTML", "", "", "", "");
                    Affine.Utils.GmailUtil gmail = new Utils.GmailUtil();
                    gmail.Send("*****@*****.**", "User Signup: " + objNewUser.Username, body);

                    // where they brought here by a group?
                    long gid = Convert.ToInt64(hiddenGroupKey.Value);
                    if (gid > 0)
                    {   // if so then we auto add them to the group.
                        Data.Managers.LINQ.DataManager.Instance.JoinGroup(us.Id, gid, Utils.ConstsUtil.Relationships.GROUP_MEMBER);
                    }

                    // See if this person was invited by anyone.
                    ContactInvite invite = entities.ContactInvites.Include("UserSetting").FirstOrDefault(i => i.Email == us.UserEmail);
                    if (invite != null)
                    {   // this person was invited by someone so lets make them friends....
                        string stat = Affine.Data.Managers.LINQ.DataManager.Instance.AcceptFriendRequests(invite.UserSetting.Id, us.Id);
                        // TODO: assume success send for now
                    }
                    // TODO: look through a list of stored contacts to get a sugested friends list...
                }
                else
                { // registration error
                    string body = "User Registration Form FAILED (Us\n\n";
                    body += "ID: " + objNewUser.UserID + "\n";
                    body += "User: "******"\n";
                    body += "First Name: " + objNewUser.FirstName + "\n";
                    body += "Last Name: " + objNewUser.LastName + "\n";
                    body += "Email: " + objNewUser.Email + "\n";
                    body += "REGISTRATION ERROR: " + userCreateStatus.ToString() + "\n";
                    //  string errStr = userCreateStatus.ToString() + "\n\n" + atiSlimControl.ToString();
                  //  DotNetNuke.Services.Mail.Mail.SendMail("*****@*****.**", "*****@*****.**", "", "FAILED REGISTRATION", lErrorText.Text + errStr, "", "HTML", "", "", "", "");
                    Affine.Utils.GmailUtil gmail = new Utils.GmailUtil();
                    gmail.Send("*****@*****.**", "**FAIL** REGISTRATION FORM: " + objNewUser.Username, body);

                    litStatus.Text = "REGISTRATION ERROR: " + userCreateStatus.ToString();
                    return false;
                }
            }
            return true;
        }
        protected void bUpdate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // Get the DNN user.
                try
                {
                    UserInfo ui = UserController.GetUserById(this.PortalId, this.UserId);
                    string fullname = atiSlimControl.FullName;
                    string[] nameparts = fullname.Split(' ');
                    string fname = string.Empty;
                    string lname = string.Empty;
                    if (nameparts.Length >= 2)
                    {
                        fname = nameparts[0];
                        lname = nameparts[1];
                    }
                    // TODO: we check if the user is trying to change their username
                    // Here is the query for it.  Right not we disable the UserName control
                    // update users set username='******' where username='******'
                    // update aspnet_Users set username='******' ,loweredusername='******' where username='******'
                    Affine.WebService.RegisterService regService = new WebService.RegisterService();

                    // TODO: need timezone control

                    regService.populateDnnUserInfo(PortalId, ref ui, fname, lname, atiUserName.Text, atiSlimControl.Email, atiPassword.Password, atiSlimControl.Postal, atiSlimControl.Address, null);
                    aqufitEntities entities = new aqufitEntities();
                    User us = entities.UserSettings.OfType<User>().Include("User2WorkoutType").Include("User2WorkoutType.WorkoutType").FirstOrDefault(s => s.UserKey == this.UserId && s.PortalKey == this.PortalId);
                    us = (User)populateUserSettings(us, ui);
                    if (!string.IsNullOrEmpty( hiddenIdentifier.Value ))
                    {
                        us.FBUid = Convert.ToInt64(hiddenIdentifier.Value);
                    }

                    // TODO: make this the same as the "GroupAdmin"
               //     UploadThemeBackground();
                    us.CssStyle = string.Empty;

                    if (!atiThemeEditor.BackgroundColor.IsEmpty)
                    {
                        us.CssStyle += "background-color: #" + atiThemeEditor.BackgroundColor.Name.Substring(2) + ";";
                    }
                    if (atiThemeEditor.IsTiled)
                    {
                        us.CssStyle += "background-repeat: repeat;";
                    }
                    else
                    {
                        us.CssStyle += "background-repeat:no-repeat; background-attachment:fixed;";
                    }
                    this.BackgroundImageUrl = ResolveUrl("~/DesktopModules/ATI_Base/services/images/profile.aspx") + "?u=" + us.UserKey + "&p=" + us.PortalKey + "&bg=1";
                  //  this.ProfileCSS = us.CssStyle;

                    foreach (CheckBox cb in atiWorkoutTypes.CheckBoxList)
                    {
                        if (!cb.Checked)
                        {
                            WorkoutType wt = entities.WorkoutType.First(w => w.Name == cb.Text);
                            User2WorkoutType u2wt = new User2WorkoutType() { WorkoutType = wt, UserSetting = us };
                            entities.AddToUser2WorkoutType(u2wt);
                        }
                        else
                        {
                            User2WorkoutType wt = us.User2WorkoutType.FirstOrDefault(w => w.WorkoutType.Name == cb.Text);
                            if (wt != null)
                            {
                                entities.DeleteObject(wt);
                            }
                        }
                    }
                    if (!cbAllowGroupEmails.Checked)
                    {
                        SiteSetting ss = new SiteSetting()
                        {
                            Name = "AllowHomeGroupEmail",
                            Value = "true",
                            UserSetting = entities.UserSettings.FirstOrDefault( u => u.Id == UserSettings.Id )
                        };
                        entities.AddToSiteSettings(ss);
                    }else{
                        // delete it if it exists
                        SiteSetting ss = entities.SiteSettings.FirstOrDefault(s => s.UserSetting.Id == UserSettings.Id && s.Name == "AllowHomeGroupEmail");
                        if (ss != null)
                        {
                            entities.DeleteObject(ss);
                        }
                    }
                    UserController.UpdateUser(this.PortalId, ui);
                    entities.SaveChanges();
                    litStatus.Text = "Your Changes have been saved.";
                  //  RadAjaxManager1.ResponseScripts.Add("alert('Your Changes have been saved');");
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.SuccessDialog.open('{\"html\":\"Your Changes have been saved.\"}');");
                }
                catch (Exception ex)
                {
                    RadAjaxManager1.ResponseScripts.Add("alert('" + ex.InnerException.Message.Replace("'", "").Replace("\"", "").Replace("\n", "") + "');");
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"" + ex.Message + "\"}');");
                }
            }
            else
            {
                RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\" Page Not Valid \"}');");
            }
        }
        protected void bUserSetup_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int UID = -1;
                UserInfo objUserInfo = UserController.GetUserByName(PortalId, atiUserNameSetup.Text);
                // if a user is found with that username, error. this prevents you from adding a username with the same name as a superuser.
                if (objUserInfo != null)
                {
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"We already have an entry for the User Name.\"}');");
                    return;
                }
                else if (string.IsNullOrWhiteSpace(atiSlimFBSetup.Postal))
                {
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"Postal/Zip is required to give you accurate gym, route, and user information, in your location.\"}');");
                    return;
                }
                else if (atiPasswordSetup.Password != atiPasswordSetup.Confirm)
                {
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"Password and Confirmation do not match.\"}');");
                    return;
                }
                Affine.WebService.RegisterService regService = new WebService.RegisterService();
                UserInfo objNewUser = regService.InitialiseUser(PortalId); // TODO: this method

                // TODO: need a TimeZone control

                string fname = hiddenGivenName.Value;
                string lname = hiddenFamilyName.Value;
                string fullname = fname + " " + lname;
                //string uuid = Guid.NewGuid().ToString().Substring(0, 15);
                string pass = atiPasswordSetup.Password;
                string email = hiddenEmail.Value;
                regService.populateDnnUserInfo(PortalId, ref objNewUser, fname, lname, atiUserNameSetup.Text, email, pass, atiSlimFBSetup.Postal, atiSlimFBSetup.Address, null);

                DotNetNuke.Security.Membership.UserCreateStatus userCreateStatus = UserController.CreateUser(ref objNewUser);
                if (userCreateStatus == DotNetNuke.Security.Membership.UserCreateStatus.Success)
                {
                    UID = objNewUser.UserID;
                    // DNN3 BUG
                    DotNetNuke.Services.Log.EventLog.EventLogController objEventLog = new DotNetNuke.Services.Log.EventLog.EventLogController();
                    objEventLog.AddLog(objNewUser, PortalSettings, objNewUser.UserID, atiSlimControl.Email, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.USER_CREATED);

                    // send notification to portal administrator of new user registration
                    //            DotNetNuke.Services.Mail.Mail.SendMail(objNewUser, DotNetNuke.Services.Mail.MessageType.UserRegistrationAdmin, PortalSettings);
                    //            DotNetNuke.Services.Mail.Mail.SendMail(objNewUser, DotNetNuke.Services.Mail.MessageType.UserRegistrationPublic, PortalSettings);
                    DataCache.ClearUserCache(PortalId, objNewUser.Username);
                    UserController.UserLogin(PortalId, objNewUser, PortalSettings.PortalName, DotNetNuke.Services.Authentication.AuthenticationLoginBase.GetIPAddress(), true);

                    User us = new Data.User();
                    us = (User)populateUserSettings(us, objNewUser);
                    try
                    {
                        us.FBUid = Convert.ToInt64(hiddenIdentifier.Value);
                    }
                    catch (Exception) { }
                    entities.AddToUserSettings(us);
                    entities.SaveChanges();

                    // TODO: should have a populate function for these
                    BodyComposition bc = new BodyComposition()
                    {
                        UserSetting = us
                    };
                    if (atiBodyComp.Visible && atiBodyComp.FitnessLevelVisible)
                    {
                        bc.FitnessLevel = atiBodyComp.FitnessLevel;
                    }

                    // need height and weight conversions
                    if (atiBodyComp.Visible && atiBodyComp.WeightVisible)
                    {
                        bc.Weight = atiBodyComp.UserWeightInSystemDefault;
                    }
                    if (atiBodyComp.Visible && atiBodyComp.HeightVisible)
                    {
                        bc.Height = atiBodyComp.UserHeightInSystemDefault;
                    }
                    entities.AddToBodyComposition(bc);
                    entities.SaveChanges();

                    string body = "User registration recorded\n\n";
                    body += "ID: " + objNewUser.UserID + "\n";
                    body += "User: "******"\n";
                    body += "First Name: " + objNewUser.FirstName + "\n";
                    body += "Last Name: " + objNewUser.LastName + "\n";
                    body += "Email: " + objNewUser.Email + "\n";
                    body += "Portal: " + objNewUser.PortalID + "\n";
                    //           DotNetNuke.Services.Mail.Mail.SendMail("*****@*****.**", "*****@*****.**", "", "NEW aqufit.com USER", body, "", "HTML", "", "", "", "");
                    Affine.Utils.GmailUtil gmail = new Utils.GmailUtil();
                    gmail.Send("*****@*****.**", "User Signup: " + objNewUser.Username, body);

                    // See if this person was invited by anyone.
                    ContactInvite invite = entities.ContactInvites.Include("UserSetting").FirstOrDefault(i => i.Email == us.UserEmail);
                    if (invite != null)
                    {   // this person was invited by someone so lets make them friends....
                        string stat = Affine.Data.Managers.LINQ.DataManager.Instance.AcceptFriendRequests(invite.UserSetting.Id, us.Id);
                        // TODO: assume success send for now
                    }
                    Response.Redirect(Convert.ToString(Settings["LandingPage"]), true);
                }
                else
                { // registration error
                    string body = "User registration FAILED \n\n";
                    body += "ID: " + objNewUser.UserID + "\n";
                    body += "User: "******"\n";
                    body += "First Name: " + fname + "\n";
                    body += "Last Name: " + lname + "\n";
                    body += "Email: " + email + "\n";
                    body += "Status: " + userCreateStatus.ToString();
                    //  string errStr = userCreateStatus.ToString() + "\n\n" + atiSlimControl.ToString();
                    //  DotNetNuke.Services.Mail.Mail.SendMail("*****@*****.**", "*****@*****.**", "", "FAILED REGISTRATION", lErrorText.Text + errStr, "", "HTML", "", "", "", "");
                    Affine.Utils.GmailUtil gmail = new Utils.GmailUtil();
                    gmail.Send("*****@*****.**", "**FAIL** RPX User Signup: " + objNewUser.Username, body);
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"" + userCreateStatus.ToString() + "\"}');");
                }
            }
            else
            {
                RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"\"}');");
            }
        }
Example #5
0
        private bool RegisterGroup()
        {
            if (Page.IsValid)
            {
                // check required fields
                aqufitEntities entities = new aqufitEntities();
                Group          test     = entities.UserSettings.OfType <Group>().FirstOrDefault(g => g.UserName == atiGroupName.Text);
                // if a user is found with that username, error. this prevents you from adding a username with the same name as a superuser.
                if (test != null)
                {
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"We already have an entry for the Group Name.\"}');");
                    return(false);
                }
                Affine.WebService.RegisterService regService = new WebService.RegisterService();

                string fname = string.Empty;
                string lname = string.Empty;
                string pass  = Guid.NewGuid().ToString();

                Group us = new Data.Group();
                us.UserKey       = 0;
                us.PortalKey     = PortalId;
                us.UserEmail     = atiTxtGroupEmail.Text;
                us.UserName      = atiGroupName.Text;
                us.UserFirstName = atiGroupName.Text;
                us.UserLastName  = "";
                us.DefaultMapLat = atiAddress.Lat;
                us.DefaultMapLng = atiAddress.Lng;
                us.LngHome       = atiAddress.Lat;
                us.LngHome       = atiAddress.Lng;
                int gtype = Convert.ToInt32(ddlGroupType.SelectedValue);
                us.GroupType = entities.GroupTypes.FirstOrDefault(gt => gt.Id == gtype);

                us.Places.Add(new Place()
                {
                    City    = atiAddress.City,
                    Country = atiAddress.Country,
                    Email   = atiTxtGroupEmail.Text,
                    Lat     = atiAddress.Lat,
                    Lng     = atiAddress.Lng,
                    Name    = atiGroupName.Text,
                    Postal  = atiAddress.Postal,
                    Region  = atiAddress.Region,
                    Street  = atiAddress.Street
                });
                entities.AddToUserSettings(us);
                entities.SaveChanges();
                // Now assign the creator of the group as an admin
                Group       group = entities.UserSettings.OfType <Group>().First(g => g.UserName == us.UserName);
                UserFriends uToG  = new UserFriends()
                {
                    SrcUserSettingKey  = UserSettings.Id,
                    DestUserSettingKey = group.Id,
                    Relationship       = (short)Affine.Utils.ConstsUtil.Relationships.GROUP_OWNER
                };
                entities.AddToUserFriends(uToG);
                entities.SaveChanges();
                Response.Redirect(ResolveUrl("~") + "group/" + group.UserName + "/settings", true);
            }
            else
            {
                RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.ErrorDialog.open('{\"html\":\"\"}');");
            }
            return(true);
        }