|
|
@ -13,7 +13,7 @@ use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Support\Facades\Password; |
|
|
|
use Illuminate\Support\Facades\Password; |
|
|
|
use Illuminate\Validation\ValidationException; |
|
|
|
use Illuminate\Validation\ValidationException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; |
|
|
|
class AuthController extends Controller |
|
|
|
class AuthController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
public function __construct() |
|
|
|
public function __construct() |
|
|
@ -108,4 +108,67 @@ class AuthController extends Controller |
|
|
|
return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); |
|
|
|
return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function sendEmail(Request $request) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$hashed = Str::random(15); |
|
|
|
|
|
|
|
$email = $request->email; |
|
|
|
|
|
|
|
$user = User::select('email', 'name')->where('email', $email)->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$user) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$this->reqHttpCurl($email, $hashed, $user->username, $user->name); |
|
|
|
|
|
|
|
// $updateUser = User::where('email', $email)->update(['password'=> $hashed]); |
|
|
|
|
|
|
|
if (User::where('email', $email)->update(['password' => md5($hashed)])) |
|
|
|
|
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function reqHttpCurl($email, $password, $username, $name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$postData = [ |
|
|
|
|
|
|
|
"to" => $email, |
|
|
|
|
|
|
|
"username" => $name, |
|
|
|
|
|
|
|
"username" => $username, |
|
|
|
|
|
|
|
"password" => $password, |
|
|
|
|
|
|
|
"from" => "app.integrasia@integrasiautama.com", |
|
|
|
|
|
|
|
"alias_from" => "OSPRO", |
|
|
|
|
|
|
|
"subject" => "Registration OSPRO", |
|
|
|
|
|
|
|
"body" => "registration-ospro" |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$curl = curl_init(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
curl_setopt_array($curl, array( |
|
|
|
|
|
|
|
CURLOPT_URL => URL_EMAIL, // your preferred url |
|
|
|
|
|
|
|
CURLOPT_RETURNTRANSFER => true, |
|
|
|
|
|
|
|
CURLOPT_ENCODING => "", |
|
|
|
|
|
|
|
CURLOPT_MAXREDIRS => 10, |
|
|
|
|
|
|
|
CURLOPT_TIMEOUT => 30000, |
|
|
|
|
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
|
|
|
|
|
|
CURLOPT_CUSTOMREQUEST => "POST", |
|
|
|
|
|
|
|
CURLOPT_POSTFIELDS => json_encode($postData), |
|
|
|
|
|
|
|
CURLOPT_HTTPHEADER => array( |
|
|
|
|
|
|
|
// Set here requred headers |
|
|
|
|
|
|
|
"accept: */*", |
|
|
|
|
|
|
|
"accept-language: en-US,en;q=0.8", |
|
|
|
|
|
|
|
"content-type: application/json", |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($curl); |
|
|
|
|
|
|
|
$err = curl_error($curl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
curl_close($curl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($err) { |
|
|
|
|
|
|
|
echo "cURL Error #:" . $err; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
print_r(json_decode($response)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|