예제 #1
0
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use Repositories\UserRepository;
Route::bind('uuid', function ($uuid) {
    $userRepo = new UserRepository();
    return $userRepo->getUserBasedOnUuid($uuid);
});
Route::bind('email', function ($email) {
    $userRepo = new UserRepository();
    return $userRepo->getUserBasedOnEmail($email);
});
Route::bind('country_id', function ($country_id) {
    return $country_id;
});
Route::bind('partner_id', function ($partner_id) {
    return $partner_id;
});
//caa126a6-b0b8-440c-8512-9c506264bf61
//Route::pattern('uuid','/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/');
//TODO Needs Check
Route::post('api/users', 'UsersController@storePlusVox');
Route::post('api/users/{uuid}', 'UsersController@update');
Route::put('api/users/{uuid}', 'UsersController@update');
Route::post('api/users/{uuid}/presence', 'UsersController@changePresence');
Route::post('api/users/{uuid}/users/{email}/call', 'UsersController@logCall');
 /**
  * Get the image of the user
  *
  * @param  Request $request the username and password of the user
  * @return Response             the image download
  */
 public function getSession(Request $request)
 {
     //get the email and password from the input
     $email = "";
     $password = "";
     if ($request->get('email') && $request->get('password')) {
         $password = $request->get('password');
         if (Libraries\InputValidator::isEmailValid($request->get('email'))) {
             $email = $request->get('email');
         } else {
             \App::abort(400, 'The contract of the api was not met');
         }
     } else {
         \App::abort(400, 'The contract of the api was not met');
     }
     //get the user based on the email
     $userRepo = new UserRepository(new User());
     $user = $userRepo->getUserBasedOnEmail($email);
     //fill the information of the user
     //if the user didn't exist
     $userInfo = [];
     if (!isset($user->password)) {
         \App::abort(404, 'The user doesn\'t exist in the database');
     } else {
         if ($user->password != sha1($password)) {
             \App::abort(404, 'The user doesn\'t exist in the database');
         }
         //send the results back to the user
         return json_encode(["points" => $userRepo->getUserPoints(), "status" => ["level" => $userRepo->getUserLevel()->id, "user_id" => $user->uuid]]);
     }
     //send the results back to the user
     return json_encode($userInfo);
 }
 /**
  * Get the image of the user
  *
  * @param  Request $request the username and password of the user
  * @return Response             the image download
  */
 public function getSession(Request $request)
 {
     //get the email and password from the input
     $email = "";
     $password = "";
     if ($request->get('email') && $request->get('password')) {
         $password = $request->get('password');
         if (Libraries\InputValidator::isEmailValid($request->get('email'))) {
             $email = $request->get('email');
         } else {
             \App::abort(400, 'The contract of the api was not met');
         }
     } else {
         \App::abort(400, 'The contract of the api was not met');
     }
     //get the user based on the email
     $userRepo = new UserRepository(new User());
     $user = $userRepo->getUserBasedOnEmail($email);
     //fill the information of the user
     //if the user didn't exist
     $userInfo = [];
     if (!isset($user->password)) {
         \App::abort(404, 'The user doesn\'t exist in the database');
     } else {
         if ($user->password != sha1($password)) {
             \App::abort(404, 'The user doesn\'t exist in the database');
         }
         $imageUrl = \Request::getRequestUri() . $user->uuid . "/image";
         $userInfo = ["first_name" => $user->first_name, "last_name" => $user->last_name, "birth_date" => $user->date_of_birth, "gender" => $user->gender, "country_iso" => $user->country->iso_code, "profile_image" => $imageUrl, "user_id" => $user->uuid, "role" => $userRepo->getUserRole()->role, "email" => $user->email];
     }
     //send the results back to the user
     return json_encode($userInfo);
 }