-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update users migration, nickname unique * Update users nickname * Update UserResource * Fix UserController namespace * Create user language(localization) * Create User Update&Destroy 초안 작성 * Update user destroy, provider disconnect * Update user edit * Fix return type&comment
- Loading branch information
1 parent
c3907d3
commit a59dae0
Showing
13 changed files
with
160 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\MessageResource; | ||
use Exception; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class UserDestroyController extends Controller | ||
{ | ||
/** | ||
* 회원 탈퇴 | ||
*/ | ||
public function __invoke(Request $request): MessageResource | ||
{ | ||
$user = Auth::user(); | ||
if (! $user) { | ||
abort(401, __('user.unauthorized')); | ||
} | ||
|
||
try { | ||
DB::beginTransaction(); | ||
$this->revoke($user, $request->deleted_reason); | ||
DB::commit(); | ||
} catch (Exception $e) { | ||
DB::rollBack(); | ||
logger($e); | ||
abort($e->getCode(), __('user.destroy_denied')); | ||
} | ||
|
||
return new MessageResource([ | ||
'message' => __('user.destroy'), | ||
]); | ||
} | ||
|
||
/** | ||
* 소셜 로그인 탈퇴 처리 | ||
*/ | ||
private function revoke($user, $reason): void | ||
{ | ||
if ($user->provider === 'apple') { | ||
$user->apple->delete(); | ||
// @todo : Apple 로그인 탈퇴 처리 | ||
} elseif ($user->provider === 'kakao') { | ||
$user->kakao->delete(); | ||
/* | ||
Http::withHeaders(['Authorization' => 'KakaoAK '.config('services.kakao.admin_key')]) | ||
->asForm()->throw() | ||
->post('https://kapi.kakao.com/v1/user/unlink', [ | ||
'target_id_type' => 'user_id', | ||
'target_id' => $user->provider_id, | ||
]); | ||
*/ | ||
} else { | ||
$user->update(['password' => null]); | ||
} | ||
|
||
$user->update(['deleted_reason' => $reason]); | ||
$user->tokens()->delete(); | ||
$user->delete(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\MessageResource; | ||
use Exception; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class UserUpdateController extends Controller | ||
{ | ||
/** | ||
* 회원 정보 수정 | ||
*/ | ||
public function __invoke(Request $request): MessageResource | ||
{ | ||
$user = Auth::user(); | ||
if (! $user) { | ||
abort(401, __('user.unauthorized')); | ||
} | ||
|
||
try { | ||
DB::beginTransaction(); | ||
$user->update([ | ||
'name' => $request->name, | ||
'nickname' => $request->nickname, | ||
'email' => $request->email, | ||
// 'password' => $request->password ? Hash::make($request->password) : $user->password, | ||
]); | ||
DB::commit(); | ||
} catch (Exception $e) { | ||
DB::rollBack(); | ||
logger($e); | ||
abort($e->getCode(), __('user.update_denied')); | ||
} | ||
|
||
return new MessageResource([ | ||
'message' => __('user.update'), | ||
]); | ||
} | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'signup_denied' => '회원 가입 중 오류가 발생했습니다.', | ||
'signup_duplicate_email' => '이미 가입한 이메일 주소입니다.', | ||
'signin_denied' => '로그인 중 오류가 발생했습니다.', | ||
'update' => '회원 정보가 수정되었습니다.', | ||
'update_denied' => '회원 정보 수정 중 오류가 발생했습니다.', | ||
'destroy' => '회원 탈퇴가 완료되었습니다.', | ||
'destroy_denied' => '회원 탈퇴 처리 중 오류가 발생했습니다.', | ||
|
||
]; |
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