57 lines
2.1 KiB
PHP
57 lines
2.1 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) && isset($out_redis["fail_count"]) && $out_redis["fail_count"] > 2 ){
|
|
// we need stop here
|
|
}
|
|
$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
|
|
{
|
|
$outF["fail_count"] = isset( $out_redis["fail_count"] ) ? $out_redis["fail_count"]+1:1;
|
|
log_message('critical', "***** ***** WrenchAuth::userLogin USER_SESSION = ".$fail_endpoint );
|
|
$this->saveCache($fail_endpoint,$outF,15000);
|
|
}
|
|
// }
|
|
|
|
return $this->respond( $this->summaryReturnData($in,$out), 200);
|
|
|
|
// return $this->summaryReturnData($in,$out); //json_encode( $final_out );
|
|
}
|
|
|
|
}
|
|
|
|
// WrenchAuth::userLogin
|