Commit 76e0b3a5 authored by Viral Solani's avatar Viral Solani

- Refactor User Activation

parent fdd02f0d
...@@ -48,15 +48,24 @@ class AuthController extends APIController ...@@ -48,15 +48,24 @@ class AuthController extends APIController
]); ]);
} }
/**
* Check if user is authenticated or not.
*
* @return \Illuminate\Http\JsonResponse
*/
public function check() public function check()
{ {
try { try {
JWTAuth::parseToken()->authenticate(); JWTAuth::parseToken()->authenticate();
} catch (JWTException $e) { } catch (JWTException $e) {
return response(['authenticated' => false]); return $this->respond([
'authenticated' => false
]);
} }
return response(['authenticated' => true]); return $this->respond([
'authenticated' => true
]);
} }
/** /**
...@@ -126,27 +135,33 @@ class AuthController extends APIController ...@@ -126,27 +135,33 @@ class AuthController extends APIController
]); ]);
} }
/**
* Activate User
*
* @param $activation_token [description]
*
* @return \Illuminate\Http\JsonResponse
*/
public function activate($activation_token) public function activate($activation_token)
{ {
$user = User::whereActivationToken($activation_token)->first(); $user = User::whereConfirmationCode($activation_token)->first();
if (!$user) { if (!$user) {
return response()->json(['message' => 'Invalid activation token!'], 422); return $this->throwValidation('Invalid activation token!');
} }
if ($user->status == 'activated') { if ($user->status == 1) {
return response()->json(['message' => 'Your account has already been activated!'], 422); return $this->throwValidation('Your account has already been activated!');
} }
if ($user->status != 'pending_activation') { $user->confirmed = 1;
return response()->json(['message' => 'Invalid activation token!'], 422); $user->status = 1;
}
$user->status = 'activated';
$user->save(); $user->save();
$user->notify(new Activated($user)); $user->notify(new Activated($user));
return response()->json(['message' => 'Your account has been activated!']); return $this->respond([
'message' => 'Your account has been activated!'
]);
} }
public function password(Request $request) public function password(Request $request)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment