Skip to content

Commit

Permalink
Change backend response
Browse files Browse the repository at this point in the history
  • Loading branch information
burakcakirel committed Jun 18, 2021
1 parent edb1075 commit 6b88ae1
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions app/Http/Controllers/Auth/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,63 @@ protected function resetPassword($user, $password)
* Get the response for a successful password reset.
*
* @param string $response
* @return \Illuminate\Http\RedirectResponse
*
* @return \Illuminate\Http\JsonResponse
*/
protected function sendResetResponse($response)
{
flash(trans($response))->success();
$user = user();

$company = $user::withoutEvents(function () use ($user) {
return $user->companies()->enabled()->first();
});

// Logout if no company assigned
if (!$company) {
$this->guard()->logout();

return redirect($this->redirectTo);
return response()->json([
'status' => null,
'success' => false,
'error' => true,
'message' => trans('auth.error.no_company'),
'data' => null,
'redirect' => null,
]);
}

// Redirect to portal if is customer
if ($user->can('read-client-portal')) {
$this->redirectTo = route('portal.dashboard', ['company_id' => $company->id]);
}

return response()->json([
'status' => null,
'success' => true,
'error' => false,
'message' => null,
'data' => null,
'redirect' => url($this->redirectTo),
]);
}

/**
* Get the response for a failed password reset.
*
* @param \Illuminate\Http\Request
* @param string $response
* @return \Illuminate\Http\RedirectResponse
*
* @return \Illuminate\Http\JsonResponse
*/
protected function sendResetFailedResponse(Request $request, $response)
{
return redirect()->back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
return response()->json([
'status' => null,
'success' => false,
'error' => true,
'message' => trans($response),
'data' => null,
'redirect' => null,
]);
}
}

0 comments on commit 6b88ae1

Please sign in to comment.