-
-
Save inuvalogic/bd0208b49ab2f2c9262c8a7fc6ec63f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tambah ini ke file .env | |
MAIL_DRIVER=mailgun | |
MAIL_HOST=smtp.mailgun.org | |
MAIL_PORT=587 | |
MAIL_ENCRYPTION=tls | |
[email protected] | |
MAIL_FROM_NAME="KSP" | |
MAILGUN_DOMAIN=domain.com | |
MAILGUN_SECRET=key-dari-mailgun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\Mail; | |
use Illuminate\Support\Str; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
use App\Model\User; | |
use App\Mail\ForgotPasswordEmail; | |
class AuthController extends Controller | |
{ | |
public function forgot(Request $request) | |
{ | |
$token = ''; | |
$user = User::where('email', $request->input('email'))->first(); | |
if ($user!=false){ | |
$token = Str::random(32); | |
$user->email_token = $token; | |
$user->email_token_expire = date("Y-m-d H:i:s", strtotime("+3 hours")); | |
$user->save(); | |
$android = $request->input('android'); | |
Mail::to($user['email'])->send(new ForgotPasswordEmail($token, $android)); | |
} | |
return response()->json([ | |
'status' => true, | |
'message' => 'Silahkan cek email Anda dan ikuti petunjuk berikutnya', | |
'reset_token' => $token, | |
]); | |
} | |
/** | |
* Validate Reset password link | |
* | |
* @return \Illuminate\Http\JsonResponse | |
*/ | |
public function reset($token) | |
{ | |
$now = date("Y-m-d H:i:s"); | |
$user = User::where([ | |
['email_token', '=' , $token], | |
['email_token_expire', '>' , $now] | |
])->first(); | |
if (!$user){ | |
return response()->json([ | |
'status' => false, | |
'message' => 'Invalid Link', | |
]); | |
} | |
return response()->json([ | |
'status' => true, | |
'message' => 'Valid', | |
]); | |
} | |
/** | |
* Do reset password | |
* | |
* @return \Illuminate\Http\JsonResponse | |
*/ | |
public function doreset(Request $request, $token) | |
{ | |
$now = date("Y-m-d H:i:s"); | |
$user = User::where([ | |
['email_token', '=' , $token], | |
['email_token_expire', '>' , $now] | |
])->first(); | |
if (!$user){ | |
return response()->json([ | |
'status' => false, | |
'message' => 'Invalid Link', | |
]); | |
} | |
$password1 = $request->input('password1'); | |
$password2 = $request->input('password2'); | |
if (empty($password1) || empty($password2)){ | |
return response()->json([ | |
'status' => false, | |
'message' => 'Password baru belum diisi', | |
], 422); | |
} | |
if ($password1 != $password2){ | |
return response()->json([ | |
'status' => false, | |
'message' => 'Password tidak sama', | |
], 422); | |
} | |
$user->password = password_hash($password1, PASSWORD_BCRYPT); | |
$user->email_token = null; | |
$user->email_token_expire = null; | |
$user->save(); | |
return response()->json([ | |
'status' => true, | |
'message' => 'Valid', | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('email.layout') | |
@section('content') | |
<h3 class="mail-heading">Reset Password Request</h3> | |
<p>Anda telah melakukan request untuk melakukan reset password akses website portal / aplikasi KSP.</p> | |
<p> Jika Anda tidak merasa melakukan request, jangan lakukan aksi apapun setelah menerima email ini.</p> | |
<p>Jika Anda yakin telah melakukan request, Silahkan klik tombol dibawah untuk mengubah password Anda</p> | |
<p><a href="{{ $reset_url }}" target="_blank" class="btn btn-primary">Reset Password</a></p> | |
<p>Jika tombol tidak berfungsi dengan baik. Anda bisa mengcopy-paste url berikut pada browser Anda.</p> | |
<p>{{ $reset_url }}</p> | |
<p>Link diatas berlaku selama 3 jam setelah Anda melakukan request, dan akan kadaluarsa secara otomatis, sehingga Anda harus melakukan request kembali melalui form Forgot Password pada website portal / aplikasi KSP.</p> | |
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Mail; | |
use Illuminate\Mail\Mailable; | |
class ForgotPasswordEmail extends Mailable | |
{ | |
public $token; | |
public $android; | |
public function __construct($token, $android) | |
{ | |
$this->token = $token; | |
$this->android = $android; | |
} | |
/** | |
* Build the message. | |
* | |
* @return $this | |
*/ | |
public function build() | |
{ | |
$reset_url = env('KSP_WEB_URL').'/user/reset/'.$this->token; | |
return $this->subject('[KSP] Reset Password Request')->view('email.forgot_password') | |
->with([ | |
'reset_url' => $reset_url | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700,800"> | |
<link rel="stylesheet" href="css/bootstrap.min.css"> | |
<link rel="stylesheet" href="css/email.css"> | |
<title>Mail Content</title> | |
</head> | |
<body> | |
<div class="mail-container"> | |
<header class="logo"> | |
Koperasi Simpan Pinjam | |
<hr class="line"> | |
</header> | |
<section class="mail-content"> | |
@yield('content') | |
</section> | |
<footer class="footer"> | |
<p class="small"> | |
ini adalah email otomatis. karena email Anda telah terdaftar pada KSP. | |
</p> | |
</footer> | |
</div> | |
<div class="copyright text-center"> | |
KSP 2020 © | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment