diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php
index 5d631fe..9bda249 100644
--- a/app/Http/Controllers/AjaxController.php
+++ b/app/Http/Controllers/AjaxController.php
@@ -11,25 +11,105 @@ use App\Models\Master\Sekolah;
use App\Models\Penilaian;
use App\Models\Kuesioner;
use App\Models\User;
+use Hash;
class AjaxController extends Controller
{
+ function authApi() {
+ $curl = curl_init();
+
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => 'http://10.50.50.74/api/login',
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => '',
+ CURLOPT_MAXREDIRS => 10,
+ CURLOPT_TIMEOUT => 0,
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_POSTFIELDS =>'{
+ "email" : "ilhamwara@gmail.com",
+ "password": "@Dinaslhdki123"
+ }',
+ CURLOPT_HTTPHEADER => array(
+ 'Content-Type: application/json'
+ ),
+ ));
+
+ $response = curl_exec($curl);
+
+ curl_close($curl);
+ return $response;
+ }
+ function sendEmail($to,$subject,$name,$kode,$token) {
+ $curl = curl_init();
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => 'http://10.50.50.74/api/email/send',
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => '',
+ CURLOPT_MAXREDIRS => 10,
+ CURLOPT_TIMEOUT => 0,
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_POSTFIELDS =>'{
+ "ApiKey" : "sk-25e88e0dfa73013ff5529d6c5e00462b",
+ "To" : "'.$to.'",
+ "Subject" : "'.$subject.'",
+ "Html": "
SIDIA JakartaHai '.@$name.',
Gunakan kode di bawah ini untuk mereset kata sandi akun Anda.
'.$kode.'
Kode ini akan kedaluwarsa dalam 15 menit.
Tidak meminta reset kata sandi ini? Abaikan email ini atau hubungi kami.
"
+ }',
+ CURLOPT_HTTPHEADER => array(
+ 'Content-Type: application/json',
+ 'Authorization: '.$token
+ ),
+ ));
+
+ $response = curl_exec($curl);
+
+ curl_close($curl);
+ }
function sendCode(Request $request) {
// $request->validate(['email' => 'required|email']);
- if($request->email){
- $user = User::where('email', $request->email)->first();
- if(@$user){
- $user->code_change_password = \Str::random(5);
- $user->save();
- return response()->json(['status' => true,'code' => true]);
- }else{
- return response()->json(['status' => false,'message' => 'Email Tidak Valid']);
- }
- }
-
+ if(@$request->email){
-
+ if(@$request->password){
+ $user = User::where('email', $request->email)->where('code_change_password', $request->kode)->first();
+ $user->password = Hash::make($request->password);
+ $user->save();
+
+ return response()->json(['status' => true,'code' => false,'password' => false,'redirect' => true]);
+
+ }elseif(@$request->kode){
+ $user = User::where('code_change_password', $request->kode)->first();
+ if(@$user){
+ return response()->json(['status' => true,'code' => false,'password' => true]);
+ }else{
+ return response()->json(['status' => false,'message' => 'Kode Tidak Valid']);
+ }
+ }else{
+ $user = User::where('email', $request->email)->first();
+ // dd();
+ if(@$user){
+ $response = json_decode($this->authApi());
+ // dd();
+
+ $user->code_change_password = \Str::random(5);
+ $user->save();
+
+ //send email
+ $this->sendEmail($user->email,'Lupa Password',$user->name,$user->code_change_password,$response->data->token);
+
+ return response()->json(['status' => true,'code' => true,'password' => false]);
+ }else{
+ return response()->json(['status' => false,'message' => 'Email Tidak Valid']);
+ }
+ }
+
+
+
+ }
}
+
function checkEmail(Request $request){
$request->validate(['email' => 'required|email']);
diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php
index 666b98b..ab0b287 100644
--- a/resources/views/auth/passwords/reset.blade.php
+++ b/resources/views/auth/passwords/reset.blade.php
@@ -52,9 +52,10 @@