1 <?php
2
3 namespace Skimia\ApiFusion\Http\Controllers\Api;
4
5 use Input;
6 use Sentinel;
7 use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
8
9 class SentinelSessionsController extends ApiController
10 {
11 public function __construct()
12 {
13 $this->middleware('api.auth', ['only' => ['index', 'user']]);
14 }
15
16 public function index()
17 {
18 return Sentinel::getUser()->persistences;
19 }
20
21 public function user()
22 {
23 if ($user = Sentinel::getUser()) {
24 return $user;
25 }
26 }
27
28 public function store()
29 {
30 try {
31 if ($user = Sentinel::authenticate(
32 Input::only('email', 'password'),
33 Input::get('remember-me', 0))
34 ) {
35 return $user;
36 } else {
37 throw new UnauthorizedHttpException('Invalid Credentials');
38 }
39 } catch (\Exception $e) {
40
41 throw new UnauthorizedHttpException('Unauthorized', $e->getMessage());
42 }
43 }
44
45 public function storeToken()
46 {
47 try {
48 if ($user = Sentinel::stateless(Input::only('email', 'password'))) {
49 return \JWTAuth::fromUser($user);
50 } else {
51 throw new UnauthorizedHttpException('Invalid Credentials');
52 }
53 } catch (\Exception $e) {
54
55 throw new UnauthorizedHttpException('Unauthorized', $e->getMessage());
56 }
57 }
58 }
59