Commit 1e2d938d authored by Ehsan Fakhraie's avatar Ehsan Fakhraie

Database Created,

Sms Panel Added
parent f0a72211
# Datasource local storage ignored files
/dataSources.local.xml
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="MySQL - profile_manager@localhost" uuid="ff6f5916-b74c-4c38-a222-e2ee44da454c">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306/profile_manager</jdbc-url>
</data-source>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/libs/vendor/guzzlehttp/guzzle" />
<path value="$PROJECT_DIR$/libs/vendor/guzzlehttp/psr7" />
<path value="$PROJECT_DIR$/libs/vendor/guzzlehttp/promises" />
<path value="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders" />
<path value="$PROJECT_DIR$/libs/vendor/psr/http-message" />
<path value="$PROJECT_DIR$/libs/vendor/composer" />
</include_path>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/libs/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/libs/vendor/guzzlehttp/guzzle" />
<excludeFolder url="file://$MODULE_DIR$/libs/vendor/guzzlehttp/promises" />
<excludeFolder url="file://$MODULE_DIR$/libs/vendor/guzzlehttp/psr7" />
<excludeFolder url="file://$MODULE_DIR$/libs/vendor/psr/http-message" />
<excludeFolder url="file://$MODULE_DIR$/libs/vendor/ralouphie/getallheaders" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/database/db.php" dialect="GenericSQL" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -5,10 +5,164 @@ $password = "admin"; ...@@ -5,10 +5,164 @@ $password = "admin";
$dbname = "profile_manager"; $dbname = "profile_manager";
//classes
class User
{
public $id;
public $name;
public $email;
public $phone;
public $password;
public $nationalCode;
public $address;
public $movies;
public $registered;
}
class ValidationCode{
public $number;
public $date;
public $code;
}
$conn = new mysqli($servername, $username, $password, $dbname); $conn = new mysqli($servername, $username, $password, $dbname);
mysqli_set_charset($conn,"utf8"); mysqli_set_charset($conn, "utf8");
// Check connection // Check connection
if ($conn->connect_error) { if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); die("Connection failed: " . $conn->connect_error);
} else {
insertValidationCode("09392291379");
}
function getAllUsers()
{
global $conn;
$sql = "SELECT * From users";
$result = $conn->query($sql);
$userArray = new ArrayObject(array());
while ($row = $result->fetch_assoc()) {
$user = new User();
$user->id = $row["id"];
$user->name = $row["full_name"];
$user->email = $row["email"];
$user->phone = $row["phone"];
$user->password = $row["password"];
$user->nationalCode = $row["national_code"];
$user->address = $row["address"];
$user->movies = $row["movies"];
$userArray->append($user);
}
return $userArray;
}
function getUser($id)
{
global $conn;
$sql = "SELECT * From users where id=" . $id;
$result = $conn->query($sql);
$user = new User();
while ($row = $result->fetch_assoc()) {
$user->id = $row["id"];
$user->name = $row["full_name"];
$user->email = $row["email"];
$user->phone = $row["phone"];
$user->password = $row["password"];
$user->nationalCode = $row["national_code"];
$user->address = $row["address"];
$user->movies = $row["movies"];
}
return $user;
}
function deleteUser($id)
{
global $conn;
// sql to delete a record
$sql = "DELETE FROM users WHERE id=" . $id;
if ($conn->query($sql) === TRUE) {
return 1;
} else {
return 0;
}
}
function insertUser(User $user)
{
global $conn;
$sql = "INSERT INTO `users` (`registered`, `full_name`, `email`, `phone`, `password`, `national_code`, `address`, `movies`) VALUES ('".$user->registered."',
'".$user->name."', '".$user->email."', '".$user->phone."', '".$user->password."', '".$user->nationalCode."', '".$user->address."', '".$user->movies."')";
if ($conn->query($sql) === TRUE) {
return 1;
} else {
return "Error: " . $sql . "<br>" . $conn->error;
}
}
function insertUsersByJson($file)
{
$studentjsondata = file_get_contents($file);
$data = json_decode($studentjsondata, true);
$d = "";
foreach ($data as $d) {
echo $d["full_name"] . "<br/>";
$user=new User();
$user->registered=$d["registered"];
$user->name=$d["full_name"];
$user->email=$d["email"];
$user->phone=$d["phone"];
$user->password="";
$user->nationalCode=$d["national_code"];
$user->address=$d["address"];
$user->movies=$d["movies"];
insertUser($user);
}
}
function insertValidationCode($phone){
$code=generateRandomString(5);
global $conn;
$date=date("h:i:s Y/m/d");
$sql="select * from phone_verification where phone=".$phone;
$sql2="Insert into phone_verification (date,phone,vcode) values ('$date' ,'$phone','$code')";
$sql3="UPDATE `phone_verification` SET `date`='$date',`phone`='$phone',`vcode`='$code' WHERE phone = '$phone'";
$result=$conn->query($sql);
if($result->num_rows == 0) {
if($conn->query($sql2)){
return $code;
}else{
return "error";
}
} else {
if($conn->query($sql3)){
return $code;
}else{
return "error";
}
}
}
function generateRandomString($length) {
$characters = '0123456789';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
} }
{
"name": "ehsan/libs",
"authors": [
{
"name": "Ehsan Fakhraie",
"email": "9831092@ceit.local"
}
],
"require": { "guzzlehttp/guzzle": "~6.0",
"ext-curl": "*"
}
}
This diff is collapsed.
<?php
require "database/db.php";
$url = "RestfulSms.com/api/";
$UserApiKey = "d47a0cc110357aa5e57e003a";
$SecretKey = "it66)%#teBC!@*&03984";
$LineNumber = "3000782121";
sendCode("09392291379");
function sendCode($phone)
{
global $UserApiKey,$SecretKey,$LineNumber;
$code=insertValidationCode($phone);
try {
date_default_timezone_set("Asia/Tehran");
// your sms.ir panel configuration
$APIKey = $UserApiKey;
$LineNumber = "3000782121";
$APIURL = "https://ws.sms.ir/";
// your mobile numbers
$MobileNumbers = array($phone);
// your text messages
$Messages = array($code);
// sending date
@$SendDateTime = date("Y-m-d")."T".date("H:i:s");
$SmsIR_SendMessage = new SmsIR_SendMessage($APIKey, $SecretKey, $LineNumber, $APIURL);
$SendMessage = $SmsIR_SendMessage->sendMessage($MobileNumbers, $Messages, $SendDateTime);
var_dump($SendMessage);
} catch (Exeption $e) {
echo 'Error SendMessage : '.$e->getMessage();
}
}
function getTokenKey()
{
global $url, $UserApiKey, $SecretKey;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "$url/Token",
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{ 'UserApiKey':'$UserApiKey','SecretKey':'$SecretKey'}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, true);
return $data;
if ($data["IsSuccessful"]) {
return $data["TokenKey"];
} else {
return $data["Message"];
}
}
class SmsIR_SendMessage
{
/**
* Gets API Message Send Url.
*
* @return string Indicates the Url
*/
protected function getAPIMessageSendUrl()
{
return "api/MessageSend";
}
/**
* Gets Api Token Url.
*
* @return string Indicates the Url
*/
protected function getApiTokenUrl()
{
return "api/Token";
}
/**
* Gets config parameters for sending request.
*
* @param string $APIKey API Key
* @param string $SecretKey Secret Key
* @param string $LineNumber Line Number
* @param string $APIURL API URL
*
* @return void
*/
public function __construct($APIKey, $SecretKey, $LineNumber, $APIURL)
{
$this->APIKey = $APIKey;
$this->SecretKey = $SecretKey;
$this->LineNumber = $LineNumber;
$this->APIURL = $APIURL;
}
/**
* Send sms.
*
* @param MobileNumbers[] $MobileNumbers array structure of mobile numbers
* @param Messages[] $Messages array structure of messages
* @param string $SendDateTime Send Date Time
*
* @return string Indicates the sent sms result
*/
public function sendMessage($MobileNumbers, $Messages, $SendDateTime = '')
{
$token = $this->_getToken($this->APIKey, $this->SecretKey);
if ($token != false) {
$postData = array(
'Messages' => $Messages,
'MobileNumbers' => $MobileNumbers,
'LineNumber' => $this->LineNumber,
'SendDateTime' => $SendDateTime,
'CanContinueInCaseOfError' => 'false'
);
$url = $this->APIURL.$this->getAPIMessageSendUrl();
$SendMessage = $this->_execute($postData, $url, $token);
$object = json_decode($SendMessage);
$result = false;
if (is_object($object)) {
$result = $object->Message;
} else {
$result = false;
}
} else {
$result = false;
}
return $result;
}
/**
* Gets token key for all web service requests.
*
* @return string Indicates the token key
*/
private function _getToken()
{
$postData = array(
'UserApiKey' => $this->APIKey,
'SecretKey' => $this->SecretKey,
'System' => 'php_rest_v_2_0'
);
$postString = json_encode($postData);
$ch = curl_init($this->APIURL.$this->getApiTokenUrl());
curl_setopt(
$ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
)
);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result);
$resp = false;
$IsSuccessful = '';
$TokenKey = '';
if (is_object($response)) {
$IsSuccessful = $response->IsSuccessful;
if ($IsSuccessful == true) {
$TokenKey = $response->TokenKey;
$resp = $TokenKey;
} else {
$resp = false;
}
}
return $resp;
}
/**
* Executes the main method.
*
* @param postData[] $postData array of json data
* @param string $url url
* @param string $token token string
*
* @return string Indicates the curl execute result
*/
private function _execute($postData, $url, $token)
{
$postString = json_encode($postData);
$ch = curl_init($url);
curl_setopt(
$ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'x-sms-ir-secure-token: '.$token
)
);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment