Help with inserting user

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Help with inserting user

Post by D Oliveira » 2020-04-13 04:01

Hi all, I was hoping I could get a piece of advice, I have two databases, 'Fitbook' and 'Fitsocial', now whenever my customer pays for the product, an event is fired to my server and activates the script bellow, as you can see it either inserts a new user or updates existing user in the membershipUsers table, it updates their expiration plan date, so far so good... but I decided to implement moosocial (https://moosocial.com/), but in order to register an user in the moonsocial system I need to insert the user in the 'Fitsocial' database, all the work in the script refers to 'Fitbook' database, so I would have to go about having a new connection with this new db and inserting the user using this API:
http://fitbookapp.net/fitbook/social/ap ... ister-post but I dont quite know how to set that up? can anyone shed some light? Is a simple new insert sql statement or something deeper? Thank you.

Code: Select all


<?php

	<?php

	$currDir = dirname(__FILE__);
	include("{$currDir}/language.php");
	include("{$currDir}/defaultLang.php");
	include("{$currDir}/lib.php");
	include_once("{$currDir}/header.php");
	 $adminConfig = config('adminConfig');

	print_r($_POST);

	 $name1 = makesafe($_POST["name"]);


	 $name = strtoupper($name1);


	 $price = makesafe($_POST["price"]);

	 $email = makesafe($_POST["email"]);

	 $statuss = makesafe($_POST["subscription_status"]);


	 print_r($data);

	 print($email . '  ' . $statuss);


	 		$date0 = new DateTime();
			$date1 = new DateTime();
			$date1->modify('+'.'34'.' day');
			$date2 = $date1->format('Y-m-d');

			$date3 = new DateTime();
			$date3->modify('+'.'365'.' day');
			$date4 = $date3->format('Y-m-d');



		
		$sql = "SELECT memberID FROM membership_users WHERE email = '{$email}'";

			$datos = sqlValue($sql);

				if ( $datos == "" ){

					$sql2 = "SELECT custom1 FROM membership_users WHERE custom1 = '{$name}'";

					$datos2 = sqlValue($sql2);

					if ( $datos2 == "" ){


						$sql2cx = "SELECT MAX(flags+1) FROM membership_users ";
						$datos2cx = sqlValue($sql2cx);

							if($price<20){

							sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);
							}else{
								sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date4}', comments=''", $eo);
							}
					}else{
						$h1 = rand(1000,100000);
						$name2 = $name.$h1;

						$sql2x = "SELECT custom1 FROM membership_users WHERE custom1 = '{$name2}'";

						$datos2x = sqlValue($sql2x);

						if ( $datos2x == "" ){

						$sql2cx = "SELECT MAX(flags+1) FROM membership_users ";
						$datos2cx = sqlValue($sql2cx);

						if($price<20){

						sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name2}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);
						}else{
							sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name2}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date4}', comments=''", $eo);
						}

						}else{

						$h2 = rand(1000,100000);
						$name3 = $name2.$h2;

						$sql2cx = "SELECT MAX(flags+1) FROM membership_users ";
						$datos2cx = sqlValue($sql2cx);

						if($price<20){

						sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name3}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);
						}else{
							sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name3}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date4}', comments=''", $eo);
							
						}



						}

							

					}

							
								$to = $email;
								$subject = $name." - Bem Vindo ao Fitbook";

								$message = "
								<html>
								<head>
								<title>Bem vindo ao Fitbook!</title>
								</head>
								<body>
								<div style='text-align: center'><img style='width: 250px' src='https://fitbookapp.net/fitbook/logon.png?c=9' /></div>
								<table align='center'>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
								<tr>
								<td align='center'> Olá ".$name.", bem vindo ao Fitbook App!</td>
								</tr>
								<p><br/></p>". "\n" . "
								<tr>
								<td align='center'> Seguem abaixo suas credenciais de acesso: </td>
								</tr>
								</table>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
								<table align='center'>
								<tr>
								<th align='center'>Usuário</th>
								</tr>
								<tr>
								<td align='center'>".$email."</td>
								</tr>
								<p> </p>
								</table>
								<table align='center'>
								<tr>
								<th align='center'>Senha</th>
								</tr>
								<tr>
								<td align='center'>fitbook</td>
								</tr>
								</table>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
								<table align='center'>
								<tr>
								<th align='center'>Acessar App</th>
								</tr>
								<tr>
								<td align='center'>https://fitbookapp.net/fitbook/</td>
								</tr>
								<p> </p>
								</table>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
								<table align='center'>
								<tr>
								<th align='center'>Contato</th>
								</tr>
								<tr>
								<td align='center'>[email protected]</td>
								</tr>
								</table>
								<p> </p>
								<div style='text-align: center'><img style='width: 25px' src='https://fitbookapp.net/fitbook/favicon.png?c=9' /></div>
								</body>
								</html>
								";

								// Always set content-type when sending HTML email
								$headers = "MIME-Version: 1.0" . "\r\n";
								$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

								// More headers
								$headers .= 'From: <[email protected]>' . "\r\n";

								mail($to,$subject,$message,$headers);



				}else{

					$sqldd = "SELECT groupID FROM membership_users WHERE email = '{$email}'";

					$datosdd = sqlValue($sqldd);

					if($datosdd == "7"){

						if($price<20){
						sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date2}' WHERE email = '{$email}'", $eo);
					}else{
						sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date4}' WHERE email = '{$email}'", $eo);
					}


					}else{


						if($price<20){
						sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date2}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "' WHERE email = '{$email}'", $eo);
					}else{
						sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date4}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "' WHERE email = '{$email}'", $eo);

					}



								$to = $email;
								$subject = $name." - Bem Vindo ao Fitbook";

								$message = "
								<html>
								<head>
								<title>Bem vindo ao Fitbook!</title>
								</head>
								<body>
								<div style='text-align: center'><img style='width: 250px' src='https://fitbookapp.net/fitbook/logon.png?c=9' /></div>
								<table align='center'>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
								<tr>
								<td align='center'> Olá ".$name.", bem vindo ao Fitbook App!</td>
								</tr>
								<p><br/></p>". "\n" . "
								<tr>
								<td align='center'> Seguem abaixo suas credenciais de acesso: </td>
								</tr>
								</table>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
								<table align='center'>
								<tr>
								<th align='center'>Usuário</th>
								</tr>
								<tr>
								<td align='center'>".$email."</td>
								</tr>
								<p> </p>
								</table>
								<table align='center'>
								<tr>
								<th align='center'>Senha</th>
								</tr>
								<tr>
								<td align='center'>fitbook</td>
								</tr>
								</table>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
								<table align='center'>
								<tr>
								<th align='center'>Acessar App</th>
								</tr>
								<tr>
								<td align='center'>https://fitbookapp.net/fitbook/</td>
								</tr>
								<p> </p>
								</table>
								<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
								<table align='center'>
								<tr>
								<th align='center'>Contato</th>
								</tr>
								<tr>
								<td align='center'>[email protected]</td>
								</tr>
								</table>
								<p> </p>
								<div style='text-align: center'><img style='width: 25px' src='https://fitbookapp.net/fitbook/favicon.png?c=9' /></div>
								</body>
								</html>
								";

								// Always set content-type when sending HTML email
								$headers = "MIME-Version: 1.0" . "\r\n";
								$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

								// More headers
								$headers .= 'From: <[email protected]>' . "\r\n";

								mail($to,$subject,$message,$headers);
								


					}
					


				}





?>

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Help with inserting user

Post by onoehring » 2020-04-13 10:53

Hi D Oliveira,

I am not sure what 'API' you mean, but I think it's so simply as you suggest: Assuming you can connect from both databases to the other one, just create a new connection to the fitsocial and update/insert that person there. Probably moosocial will do the rest - if I understood you correct.

Olaf

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Help with inserting user

Post by D Oliveira » 2020-04-13 21:11

onoehring wrote:
2020-04-13 10:53
Hi D Oliveira,

I am not sure what 'API' you mean, but I think it's so simply as you suggest: Assuming you can connect from both databases to the other one, just create a new connection to the fitsocial and update/insert that person there. Probably moosocial will do the rest - if I understood you correct.

Olaf
The API link I shared is the moosocial API (hosted on my server) that allows HTPPS POST/GET/PUT methods, but I never worked with setting that up, I could simply put a sql insert statement but appgini mechanism of hashing the password is different than moosocial's, thats why I think we need necessarily to use the 'sign up' user command in the API, but I wonder how to activate that function properly

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Help with inserting user

Post by onoehring » 2020-04-14 05:22

Hi D Oliveira,

AG can use MD5 passwords! You can create an MD5 password and the first time the user logs in, AG will update the password with a stronger hash. This allows you to insert users quite easily from an "external" application (see: viewtopic.php?f=4&t=3084 ).

Olaf

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Help with inserting user

Post by D Oliveira » 2020-04-14 06:18

onoehring wrote:
2020-04-14 05:22
Hi D Oliveira,

AG can use MD5 passwords! You can create an MD5 password and the first time the user logs in, AG will update the password with a stronger hash. This allows you to insert users quite easily from an "external" application (see: viewtopic.php?f=4&t=3084 ).

Olaf
yeah same hash method but different salts.. I have the raw string password (actual password) my script hashes and inserts in appgini system, but for moosocial eventhough it uses MD5 its has a different salt hash , using the API we can just insert the user without worrying about that, but Im not sure if I even need to go through the authentication phase or how to work with that, anyone done HTTPS api calls or work before?

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Help with inserting user

Post by D Oliveira » 2020-04-14 06:52

I FOUND A WAY! hehe

not perfect but... I changed admin password to 'fitbook' and looked at the db for the hashed code + salt, now a simple insert statement does the trick ;) it wouldnt work for dynamic password tho, this is strictly for people who want to enforce the same new password to every new account, thanks!

Post Reply