Browse Source

update method sendEmail

pull/1/head
wahyun 9 months ago
parent
commit
cc8b2cf1f7
  1. 25
      app/Http/Controllers/AuthController.php

25
app/Http/Controllers/AuthController.php

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

Loading…
Cancel
Save