<![CDATA[ creating a web user from a script - My Forums]]> https://forums.modx.com/thread/?thread=34828 <![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190778 trying to add some validation to make sure all forms are filled out and i am runing into snag. it is still allowing registration even though all fields arent filled out.

can anyone lend a hand?


Hi,

See the WebSignup snippet found in the Tech Preview]]>
xwisdom Apr 21, 2005, 08:25 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190778
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190777
can anyone lend a hand?

here is the code:

  // add user
if($action=='addUser')
{
   $username = $_POST['uname'];
   $password = $_POST['pwd'];
   $password2 = $_POST['pwd2'];
   $company = $_POST['company'];
   $fullname = $_POST['fullname'];
   $email = $_POST['email'];
   $city = $_POST['city'];
   $state = $_POST['state'];
   $phone = $_POST['phone'];
   $referredby = $_POST['referredby'];

   if(!isset($_POST['uname']) || !isset($_POST['pwd']) || !isset($_POST['company']) || !isset($_POST['fullname']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['state']) || !isset($_POST['phone']) || !isset($_POST['referredby']))
   { 

      header("Location: index.php?id=92&p=yo"); 

   } 

      if($username!='')
      {
         if($password==$password2)
         {
            $conn = mysql_connect("$dbhost","$dbuser","$dbpass") or die ("Cant connect to Database");
            $db = mysql_select_db("$dbname") or die ("database gone.");
            $sql1 = "INSERT INTO etomite_web_users (id, username, password) VALUES ('NULL', '$username', MD5('$password'))";
            $result1 = mysql_query($sql1) or die ("SQL1 not working, couldn't insert user into db");
            if($result1)
            {     
               $id = mysql_insert_id();
               $sql3 = "INSERT INTO etomite_web_user_attributes (id, internalKey, company, fullname, email, city, state, phone, referredby) VALUES ('NULL', '$id', '$company', '$fullname', '$email', '$city', '$state', '$phone', '$referredby')";
               $result3 = mysql_query($sql3) or die ("SQL3 not working, unable to add user attributes");
               if($result3)
               {
                  $sql4 = "INSERT INTO etomite_web_groups (id, webgroup, webuser) VALUES ('NULL', '1', '$id')";
                  $result4 = mysql_query($sql4) or die ("SQL4 not working, unable to add group attributes");
                  if($result4)
                  {
                     $sql5 = "INSERT INTO etomite_web_user_settings (webuser, setting_name, setting_value) VALUES ('$id', 'login_home', '81')";
                     $result5 = mysql_query($sql5) or die ("SQL5 not working, unable to add user settings");
                     if($result4)
                     {
                        $sender = '[email protected]';
                        $emailto = '[email protected]';
                        $sub = 'New xxxx User Created';
                        $sub2 = 'Your xxxx Login Credentials';
                        $message = $fullname." has just signed up to xxx xxx The new users information is listed below."."\n\n"."Username = $username"."\n\n"."Company Name = $company"."\n\n"."Full Name = $fullname"."\n\n"."Email Address = $email"."\n\n"."City = $city"."\n\n"."State = $state"."\n\n"."Phone Number = $phone"."\n\n"."Referred By = $referredby"."\n\n";
                        $message2 = "Welcome ".$fullname.". Thank you for signing up to xxx xxx Your login information is listed below."."\n\n"."Username = $username"."\n\n"."Password = $password"."\n\n"."HOME PAGE: http://www.xxx.com/"."\n\n";
                        $header = "From: ".$sender."\n";
                        $header .= "Reply-To: ".$sender."\n";
                        mail($emailto, $sub, $message, $header);
                        mail($email, $sub2, $message2, $header);
                        header("Location: index.php?id=74");
                     }
                  }
               }
            }
         }
         else
         {
            header("Location: index.php?id=80");
         }
      }
      else
      {
         header("Location: index.php?id=92");
      }
   
}
]]>
indica Apr 21, 2005, 07:34 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190777
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190776
oh and i will add the finished file to the download posted above.

todd]]>
indica Apr 10, 2005, 10:25 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190776
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190775
  // add user 
if($action=='addUser')
{ 
   $username = $_POST['username']; 
   $password = $_POST['password']; 
   $password2 = $_POST['password2']; 
   $company = $_POST['company']; 
   $fullname = $_POST['fullname']; 
   $email = $_POST['email']; 
   $city = $_POST['city']; 
   $state = $_POST['state']; 
   $phone = $_POST['phone']; 

   if($password==$password2)
   { 
      $conn = mysql_connect("$dbhost","$dbuser","$dbpass") or die ("Cant connect to Database"); 

      $db = mysql_select_db("$dbname") or die ("database gone."); 

      $sql1 = "INSERT INTO etomite_web_users (id, username, password) VALUES ('NULL', '$username', MD5('$password'))"; 
      $result1 = mysql_query($sql1) or die ("SQL1 not working, couldn't insert user into db"); 
      if($result1)
      { 
      		// NOTE: this is how you get the new id		
      		$id = mysql_insert_id(); 
      		
            $sql3 = "INSERT INTO etomite_web_user_attributes (id, internalKey, company, fullname, email, city, state, phone) VALUES ('NULL', '$id', '$company', '$fullname', '$email', '$city', '$state', '$phone')"; 
            $result3 = mysql_query($sql3) or die ("SQL3 not working, unable to add user attributes"); 
            if($result3)
            { 
            	header("Location: index.php?id=74"); 
            } 
 	  } 
	}
}
]]>
xwisdom Apr 10, 2005, 02:13 AM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190775
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190774
do you see anything that would be causing this in the code?

  // add user
if($action=='addUser') 

	{ 
	$username = $_POST['username'];
	$password = $_POST['password'];
	$password2 = $_POST['password2'];
	$company = $_POST['company'];
	$fullname = $_POST['fullname'];
	$email = $_POST['email'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$phone = $_POST['phone'];

	if($password==$password2)
		{
		$conn = mysql_connect("$dbhost","$dbuser","$dbpass") or die ("Cant connect to Database");

		$db = mysql_select_db("$dbname") or die ("database gone.");


		$sql1 = "INSERT INTO etomite_web_users (id, username, password) VALUES ('NULL', '$username', MD5('$password'))";
		$result1 = mysql_query($sql1) or die ("SQL1 not working, couldn't insert user into db");
		if($result1) 

			{
			$sql2 = "SELECT id FROM etomite_web_users WHERE username = '$username'";
			$result2 = mysql_query($sql2) or die ("SQL2 not working, unable to retrieve 'internalKey' from db");
			if($result2)
				{			
				$sql3 = "INSERT INTO etomite_web_user_attributes (id, internalKey, company, fullname, email, city, state, phone) VALUES ('NULL', '$result2', '$company', '$fullname', '$email', '$city', '$state', '$phone')";
				$result3 = mysql_query($sql3) or die ("SQL3 not working, unable to add user attributes");
				if($result3) 

					{
					header("Location: index.php?id=74");

					}
				} 

			}
		}
	}


Thanks again!!

todd]]>
indica Apr 10, 2005, 12:29 AM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190774
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190773 ok awesome so i am almost done, just one last little problem. The internalKey is not a auto-incrementing key nor can it be since the id column is already. i need to figure out how to increment this to match the id column, or to copy the id key into the internalKey column. i know there is a way to count the rows and turn that into a variable, just not sure how to do it yet.


You must first insert a record into web_users then use the new id value from the web_users to insert a record into the internalkey inside the web_user_attributes table.]]>
xwisdom Apr 09, 2005, 08:46 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script?page=2#dis-post-190773
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190772
  // add user
if($action=='addUser') 

	{ 


	$username = $_POST['username'];
	$password = $_POST['password'];
	$password2 = $_POST['password2'];
	$company = $_POST['company'];
	$fullname = $_POST['fullname'];
	$email = $_POST['email'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$phone = $_POST['phone'];
//this needs to be fixed, it has to be the same as the id field of that same row since it is autogenerated.
	$internalKey = '***THIS MUST MATCH ID FIELD IN SAME ROW***';

	if($password==$password2)
		{
		$conn = mysql_connect("$dbhost","$dbuser","$dbpass") or die ("Cant connect to Database");

		$db = mysql_select_db("$dbname") or die ("database gone."); 

		$sql = "INSERT INTO `etomite_web_user_attributes` (id, internalKey, company, fullname, email, city, state, phone) VALUES ('NULL', '$internalKey', '$company', '$fullname', '$email', '$city', '$state', '$phone')";
		$sql2 = "INSERT INTO `etomite_web_users` (`id`, `username`, `password`) VALUES ('NULL', '$username', '$password')";
		$result = mysql_query($sql) or die ("SQL1 Not working try again"); 

		$result2 = mysql_query($sql2) or die ("SQL2 Not working try again"); 

		if($result) 

			{ 

			header("Location: index.php?id=74");

			} 

		
		}
	}


here are the files as promised, and warning this is a quick hack. I know it could have been done much cleaner and probably will be but i hope this can help out someone else out there.

usrProf.php - main php file
config_inc.php - db config info
addUser.chunk
updateProfile.chunk
chgPasswd.chunk
viewProfile.chunk
TemplateVariables.txt
getUserID.snippet
getLoginName.snippet

there is not much, if any, validation being done. but it does work, well except for the above stated issue. but i am looking for some old code i had that did something like what i need done. maybe someone here can help out, either way it will be done by monday morning for sure!

Thanks,

Todd



http://greymatterhosting.com/downloads/modX2_web_usr_reg.tar.gz]]>
indica Apr 09, 2005, 08:27 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190772
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190771 bad news just talked with my client and they 'would like' to see the site up monday so I need to get something together before this weekend.

does anyone know which tables do need to be updated in order to properly create a user via an external script?

one other thing, I am trying to figure out how the password is encrypted so I can update the fields for that as well.

Thanks,

Todd
password is md5 encription

should be somthing like this SQL command
INSERT INTO `{PREFIX}web_users` VALUES (2, 'USERNAME', MD5('USERPASS'));]]>
Dimmy Apr 09, 2005, 12:45 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190771
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190770 bad news just talked with my client and they 'would like' to see the site up monday so I need to get something together before this weekend.

does anyone know which tables do need to be updated in order to properly create a user via an external script?

one other thing, I am trying to figure out how the password is encrypted so I can update the fields for that as well.

Thanks,

Todd
These tables should do the trick:

web_users
web_user_attributes]]>
xwisdom Apr 08, 2005, 12:13 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190770
<![CDATA[creating a web user from a script]]> https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190769
does anyone know which tables do need to be updated in order to properly create a user via an external script?

one other thing, I am trying to figure out how the password is encrypted so I can update the fields for that as well.

Thanks,

Todd]]>
indica Apr 07, 2005, 11:16 PM https://forums.modx.com/thread/34828/creating-a-web-user-from-a-script#dis-post-190769