|
|
@ -6,9 +6,11 @@ use App\Http\Controllers\Controller; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
use App\Http\Controllers\Api\BaseAuthApiController as BaseAuthApiController; |
|
|
|
use App\Http\Controllers\Api\BaseAuthApiController as BaseAuthApiController; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Hash; |
|
|
|
|
|
|
|
|
|
|
|
class AuthApiController extends BaseAuthApiController |
|
|
|
class AuthApiController extends BaseAuthApiController |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
public $_default_usertype = 'agents'; |
|
|
|
// |
|
|
|
// |
|
|
|
public function login(Request $request) |
|
|
|
public function login(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -40,4 +42,59 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
return $this->sendResponse($data, 'User login successfully.'); |
|
|
|
return $this->sendResponse($data, 'User login successfully.'); |
|
|
|
// return response()->json($data, 200); |
|
|
|
// return response()->json($data, 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function register(Request $request) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), [ |
|
|
|
|
|
|
|
'email' => 'required|email', |
|
|
|
|
|
|
|
'fullname' => 'required' |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
if ($validator->fails()) { |
|
|
|
|
|
|
|
return $this->sendError('Validation Error.', $validator->errors()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$dataInsert = $this->transformRegisterData($request->all()); |
|
|
|
|
|
|
|
if (!empty($dataInsert)) { |
|
|
|
|
|
|
|
$user = \App\Models\User::insert($dataInsert); |
|
|
|
|
|
|
|
return response()->json(['status' => true, 'msg' => $this->getMessageReponse(1)]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function transformRegisterData($data) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$finalData = []; |
|
|
|
|
|
|
|
if (!empty($data['email'])) { |
|
|
|
|
|
|
|
$finalData['email'] = $data['email']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($data['address'])) { |
|
|
|
|
|
|
|
$finalData['address'] = $data['address']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($data['birthday'])) { |
|
|
|
|
|
|
|
$finalData['birthday'] = $data['birthday']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($data['fullname'])) { |
|
|
|
|
|
|
|
$finalData['name'] = $data['fullname']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($data['phone'])) { |
|
|
|
|
|
|
|
$finalData['phone'] = $data['phone']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$finalData['password'] = !empty($data['password']) ? Hash::make($data['password']) : Hash::make('1qaz2wsxA@'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($data['gender'])) { |
|
|
|
|
|
|
|
$finalData['gender'] = !empty($data['gender']) && $data['gender'] == 'male' ? 1 : 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$finalData['user_type'] = !empty($data['role']) ? $data['role'] : $this->_default_usertype; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $finalData; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function getMessageReponse($key) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$msg = [ |
|
|
|
|
|
|
|
1 => "Tạo tài khoản thành công.", |
|
|
|
|
|
|
|
2 => "Tạo tài khoản thất bại.", |
|
|
|
|
|
|
|
3 => "Email đã tồn tại.", |
|
|
|
|
|
|
|
4 => "Email không hợp lệ.", |
|
|
|
|
|
|
|
5 => "Mật khẩu phải có ít nhất 8 ký tự, bao gồm chữ cái và số.", |
|
|
|
|
|
|
|
6 => "Tên đăng nhập phải có ít nhất 6 ký" |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
return $msg[$key] ?? ''; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|