Exemplo n.º 1
0
 /**
  * Logs the user into the application
  *
  * @return Response
  */
 public function login(Request $request)
 {
     $email = $request->json()->get('email');
     $password = $request->json()->get('password');
     $id = $request->json()->get('id');
     // get site by its friendly id
     $site = Site::getById($id);
     if ($site != NULL) {
         // get the user from the credentials
         $user = User::getByEmailPassword($email, $password, $site->id);
         if ($user != NULL) {
             // get the photoURL
             $fullPhotoUrl = '';
             // set photo url
             if ($user->photo != '' && $user->photo != NULL) {
                 // set images URL
                 $imagesURL = $site->domain;
                 $fullPhotoUrl = $imagesURL . '/files/thumbs/' . $user->photo;
             }
             // return a subset of the user array
             $returned_user = array('email' => $user->email, 'firstName' => $user->firstName, 'lastName' => $user->lastName, 'photo' => $user->photo, 'fullPhotoUrl' => $fullPhotoUrl, 'language' => $user->language, 'siteId' => $site->id);
             // send token
             $params = array('user' => $returned_user, 'token' => Utilities::createJWTToken($user->email, $site->id));
             // return a json response
             return response()->json($params);
         } else {
             return response('Unauthorized', 401);
         }
     } else {
         return response('Unauthorized', 401);
     }
 }