예제 #1
0
        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;
        }
예제 #2
0
        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\":\"\"}');");
            }
        }