102 lines
2.6 KiB
PHP
Executable File
102 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Auth\app\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('auth::index');
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('auth::create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return view('auth::show');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return view('auth::edit');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function updatePassword(Request $request)
|
|
{
|
|
//
|
|
$messages = array(
|
|
'email.required' => 'Email là bắt buộc.',
|
|
'email.email' => 'Email không đúng định dạng.',
|
|
'password.required' => 'Mật khẩu là bắt buộc.',
|
|
'current_password.required' => 'Mật khẩu là bắt buộc.',
|
|
'current_password.min' => 'Mật khẩu phải có ít nhất 6 ký tự.',
|
|
'password.min' => 'Mật khẩu phải có ít nhất 6 ký tự.',
|
|
'password.confirmed' => 'Mật khẩu không trùng khớp.',
|
|
'password_confirmation.required' => 'Mật khẩu xác thực là bắt buộc.',
|
|
);
|
|
|
|
$validateData = [
|
|
'email' => 'required|email',
|
|
'current_password' => 'required|min:6',
|
|
'password' => 'required|min:6|confirmed',
|
|
'password_confirmation' => 'required'
|
|
|
|
];
|
|
|
|
$request->validate($validateData, $messages);
|
|
|
|
$user = User::where('email', $request->email)->first();
|
|
|
|
if (Hash::check($request->current_password, $user->password) && $user !== null) {
|
|
$user->password = bcrypt($request->password);
|
|
$user->save();
|
|
return response()->json(['status' => true, 'mess' => 'Change password success!'], Response::HTTP_OK);
|
|
}else{
|
|
return response()->json(['status' => false, 'mess' => 'Current password incorrect'], Response::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|