Skip to content

Commit

Permalink
Fix core for soport unix systems
Browse files Browse the repository at this point in the history
  • Loading branch information
arcan31 committed Mar 7, 2024
1 parent 7f85430 commit 79fba7a
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rmdir /s /q sao\.git

En sistemas Unix o Linux (incluyendo macOS), usa el comando `rm`:
```sh
rm -rf sao/.git
rm -rf Sao/.git
```

Ahora solo necesitas cambiar el nombre de la carpeta `Sao` al nombre de tu proyecto. Utiliza el comando:
Expand All @@ -38,7 +38,7 @@ ren sao nombre_de_tu_app

En Unix, Linux o macOS:
```sh
mv sao nombre_de_tu_app
mv Sao nombre_de_tu_app
```

Ahora puedes ingresar a tu proyecto ejecutando:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion core/Auth/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function getPayLoadTokenClient(string $tokenRequest, string $key,
}
}

public static function getPayLoadTokenAll(string $tokenRequest, string $key) {
public static function getPayLoadTokenAll(string $tokenRequest, string $key, string $input = '') {
try {
$tokenRequest = urldecode($tokenRequest);
$encrypt = import('Encrypt/encrypt.php', true, '/core');
Expand Down
118 changes: 118 additions & 0 deletions core/Auth/authold.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class SauthOLD {
private static $data;
public static $token = '';
public static $time;
public static $nameSesion = 'session';

public static function token(Array $payload, string $key, $encrypter = true, $algori = 'HS256'){
$jwt = JWT::encode($payload, $key, $algori);
if($encrypter){
$jwt = core('Encrypt/encrypt.php')->encrypt($jwt, $key);
}
return $jwt;
}

public static function decode(string $token, string $key, $encrypter = true, $algori='HS256'){
if($encrypter){

$tokent = core('Encrypt/encrypt.php')->decrypt($token, $key);
echo "<br>================================================ <br>";
var_dump($token);
echo "<br>================================================ <br>";
}
try {
$token = JWT::decode($token, new Key($key, $algori));
echo "<br>================================================ <br>";
var_dump($token);
echo "<br>================================================ <br>";
} catch (\Throwable $th) {
$token = false;
}
/* Sauth::$data = $jwt; */
return $token;
}


public static function start(string $token, string $key){
try{
$token = Sauth::decode($token, $key);

}catch(Exception $e){
return false;
}
Sauth::$data = $token;
return true;
}

public static function data(string $key = ''){
if(empty($key)){
return Sauth::$data->data;
}
if(isset(Sauth::$data->data->$key)){
return Sauth::$data->data->$key;
}else{
throw new Exception("El indice $key no existe");
}
}

public static function set(Array $userData, string $key, int $timeInDays = 7, $encrypter = true,$algori = 'HS256'){
self::$time = time() + (86400 * $timeInDays);
self::$token = self::token([
'iat' => time(), // Tiempo que inició el token
'exp' => self::$time, // Tiempo que expirará el token 7 días
'data' => $userData
], $key, $encrypter, $algori);
return self::$token;
}


public static function loginClient() {
try {
setcookie(self::$nameSesion, self::$token, self::$time, '/'); // La cookie expirará en 7 días
} catch (\Throwable $th) {
throw new Exception("Error interno", 1);
}

}

public static function loginServer(string $table, string $colum, int $id, $idColumName = 'id'){
import('DataBase/ORM/orm.php', false, '/core');
$db = new DataBase;
$db->prepare();
$db->select([$colum])->from($table)->where($idColumName, $id);
if(!$db->execute()->exists()){
throw new Exception("The user with id ".$id." dont exist", 1);
}
$db->prepare();
$db->update($table, [
$colum => self::$token
])->where($idColumName, $id);
$db->execute();
}


public static function middleware($key){
var_dump(Request::$cookies);
return isset(Request::$cookies[self::$nameSesion]) && self::start(Request::$cookies[self::$nameSesion], $key) ?
true : false;
}

public static function getToken(){
return isset(Request::$cookies[self::$nameSesion]) && self::start(Request::$cookies[self::$nameSesion], $_ENV['APP_KEY']) ?
Request::$cookies[self::$nameSesion] : null;
}


}








6 changes: 5 additions & 1 deletion core/Controller/baseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setFileAndHostWithRedirectionAndUpload(array $file, string $redi


public function host(){
return $_ENV['APP_ADDRESS'].":".$_ENV['APP_PORT'];
return $_ENV['APP_SERVER_CROQUETTE_HOST'].":".$_ENV['APP_SERVER_CROQUETTE_PORT'];
}

public function setInputs($request){
Expand Down Expand Up @@ -101,6 +101,10 @@ public function clientAuth($cookie = 'session', $key = null) {
$key ?? $_ENV['APP_KEY']
);
}






}
1 change: 1 addition & 0 deletions core/Helpers/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function deleteFormat($file){


function getFilesByDirectory($dir){
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
$dirs = array();
if ($handler = opendir($dir)) {
while (false !== ($file = readdir($handler))) {
Expand Down
2 changes: 1 addition & 1 deletion core/Helpers/sao/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


function controller($controller, $function, $data = 'nulldata'){
$controller = import('controllers/'.$controller.'.php');
$controller = import('Controllers/'.$controller.'.php');
if($data == 'nulldata'){
try{
return $controller->{$function}();
Expand Down
2 changes: 1 addition & 1 deletion core/Model/baseModel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

//import('/Database/ORM/orm.php', false, '/core');
core('Database/ORM/orm.php', false);
core('DataBase/ORM/orm.php', false);
class BaseModel extends DataBase{


Expand Down

0 comments on commit 79fba7a

Please sign in to comment.