Files
WrenchBoradWeb/www-api/app/Controllers/WrenchAuth.php
T
CHIEFSOFT\ameye f96232767b assign jobs
2024-07-08 10:18:10 -04:00

55 lines
2.0 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
class WrenchAuth extends BaseController
{
use ResponseTrait;
public function userLogin(){
// $in = $this->request->getPostGet();
$raw_json = file_get_contents('php://input');
$in = json_decode($raw_json, true);
$in["action"] = WRENCHBOARD_ACCOUNT_LOGIN;
if (!isset($in["login_mode"])){
$in["login_mode"] = MOBILE_LOGIN;
}
// make safe for redis
$outF["username"] = str_replace("@", "_", $in["username"]);
$outF["username"] = str_replace(".", "_", $outF["username"]);
$outF["original_username"] = $in["username"];
$outF["loc"] = $in["loc"];
$fail_endpoint = "LOGIN_FAILED-".$outF["username"]."-";
//===================REDIS DATA IN CASE OF FAIL
$out_redis = $this->getCache($fail_endpoint); // try find in cache
if (isset($out_redis["fail_count"]) && $out_redis["fail_count"] > 2){
// we need stop here
}else{
$outF["fail_count"] = isset( $out_redis["fail_count"] ) ? $out_redis["fail_count"]+1:1;
}
$out=[];
$ret = $this->wrenchboard->wrenchboard_api($in, $out);
$out['internal_return'] = $ret;
log_message('critical', "***** ***** WrenchAuth::userLogin Ret = ".$ret );
if ( $out['internal_return'] == 100 ){
$endpoint = "USER_SESSION-". str_pad($out["member_id"], 12, "0", STR_PAD_LEFT) ."-";
log_message('critical', "***** ***** WrenchAuth::userLogin USER_SESSION = ".$endpoint );
$this->saveCache($endpoint,$out,15000);
}else
{
log_message('critical', "***** ***** WrenchAuth::userLogin USER_SESSION = ".$fail_endpoint );
$this->saveCache($fail_endpoint,$outF,15000);
}
return $this->respond( $this->summaryReturnData($in,$out), 200);
}
}
// WrenchAuth::userLogin