diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 53d34f4..4f06657 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -113,18 +113,33 @@ class AuthController extends Controller public function sendEmail(Request $request) { - $hashed = Str::random(15); + if (empty($request->password)) { + $hashed = Str::random(15); + } else { + $hashed = $request->password; + } + $email = $request->email; $user = User::select('email', 'name', 'username')->where('email', $email)->first(); if (!$user || empty($email)) { - return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); + return response()->json(['status' => 'error', 'message' => 'e-mail not found'], 400); } else { - $this->reqHttpCurl($email, $hashed, $user->username, $user->name); - 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); + if($request->username) { + $username = $request->username; + $name = $request->username; + } else { + $username = $user->username; + $name = $user->name; + } + $this->reqHttpCurl($email, $hashed, $username, $name); + if(empty($request->password)) { + if (User::where('email', $email)->update(['password' => md5($hashed)])) { + return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200); + } + } else { + return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200); + } } } @@ -132,7 +147,7 @@ class AuthController extends Controller { $postData = [ "to" => $email, - "username" => $name, + "name" => $name, "username" => $username, "password" => $password, "from" => "app.integrasia@integrasiautama.com",