Ejemplo n.º 1
0
 public function login($request)
 {
     $credentials['password'] = $request['idfacebook'];
     $credentials['email'] = $request['email'];
     $data['tokendevice'] = $request['tokendevice'];
     $data['typedevice'] = $request['typedevice'];
     if (!($token = JWTAuth::attempt($credentials))) {
         $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], array(), ControllerWS::MSG_CUSTOM_USER_PASS_FAIL);
     } else {
         $login = JWTAuth::toUser($token);
         $obj = User::find($login->id);
         //obteniendo las categorias del usuario//
         $UserCategory = new UserCategories();
         $categories = $UserCategory->UserCategories($login->id);
         $dataUser = $login;
         $dataUser['flagterms'] = $login->flagterms;
         $dataUser['categories'] = $categories->toArray();
         $obj->update($data);
         $modelhash = new UserHash();
         $modelhash->GetFriendFacebook($credentials['name'] . ' ' . $credentials['lastname'], $credentials['picture'], $credentials['password'], $login->id);
         $this->_responseWS->setDataResponse(Response::HTTP_OK, [$dataUser], array(), 'ok');
         $this->_responseWS->setHeader('_token', $token);
     }
     $this->_responseWS->response();
 }
Ejemplo n.º 2
0
 function index(Request $request)
 {
     $id = $this->_identity->id;
     try {
         $UserCategory = new UserCategories();
         $user = User::find($id);
         //            $user->picture = $request->root() . $user->picture;
         $categories = $UserCategory->UserCategories($id);
         $data = $user->toarray();
         $data['categories'] = $categories->toArray();
         if (isset($user)) {
             $this->_responseWS->setDataResponse(Response::HTTP_CREATED, [$data], array(), 'ok');
         } else {
             $this->_responseWS->setDataResponse(Response::HTTP_CREATED, [], array(), 'usuario inexistente');
         }
     } catch (\Exception $exc) {
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, array(), array(), '');
     }
     $this->_responseWS->response();
 }
Ejemplo n.º 3
0
 public function store(LoginRequest $request)
 {
     try {
         $credentials['password'] = $request->input('idfacebook');
         $credentials['email'] = $request->input('email');
         $data['tokendevice'] = $request->input('tokendevice');
         $data['typedevice'] = $request->input('typedevice');
         $datauser = User::whereEmail($credentials['email'])->get()->first();
         if (isset($datauser)) {
             switch ($datauser->flagactive) {
                 case User::STATE_USER_ACTIVE:
                     if (!($token = JWTAuth::attempt($credentials))) {
                         $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], array(), ControllerWS::MSG_CUSTOM_USER_PASS_FAIL);
                     } else {
                         $login = JWTAuth::toUser($token);
                         $obj = User::find($login->id);
                         $UserCategory = new UserCategories();
                         $categories = $UserCategory->UserCategories($login->id);
                         $dataUser = $login;
                         $dataUser['flagterms'] = $login->flagterms;
                         $dataUser['categories'] = $categories->toArray();
                         $modelhash = new UserHash();
                         $modelhash->GetFriendFacebook($data['tokendevice'], $data['typedevice'], $login->name . ' ' . $login->lastname, $login->picture, $credentials['password'], $login->id);
                         $obj->update($data);
                         $this->_responseWS->setDataResponse(Response::HTTP_OK, [$dataUser], array(), 'ok');
                         $this->_responseWS->setHeader('_token', $token);
                     }
                     break;
                 case User::STATE_USER_INACTIVE:
                     $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], 'usuario desactivado por el administrador');
                     break;
             }
         } else {
             $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], [], 'no existe el usuario');
         }
     } catch (\Exception $exc) {
         dd($exc->getMessage());
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], '');
     }
     $this->_responseWS->response();
 }
Ejemplo n.º 4
0
 public function update(RegisterUserCategoriesRequest $request, $id)
 {
     try {
         $idcategories = $request->input('categories_id');
         $idCategory = explode("-", $idcategories);
         UserCategories::whereUsersId($this->_identity->id)->delete();
         foreach ($idCategory as $value) {
             $data['users_id'] = (int) $this->_identity->id;
             $data['pu_categories_id'] = (int) $value;
             UserCategories::create($data);
         }
         $this->_responseWS->setDataResponse(Response::HTTP_OK, [], [], 'ok');
     } catch (\Exception $exc) {
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, array(), array(), '');
     }
     $this->_responseWS->response();
 }
Ejemplo n.º 5
0
 public function UserCategories($users_id)
 {
     $data = UserCategories::join('users', 'users.id', '=', 'users_pu_categories.users_id')->join('pu_categories as puc', 'puc.id', '=', 'users_pu_categories.pu_categories_id')->select('puc.id', DB::raw('CONCAT("' . asset('') . '", puc.picture) AS picture'), 'puc.name_category')->where('puc.flagactive', '=', 1)->where('users.id', '=', $users_id)->orderBy('puc.id', 'asc')->get();
     return $data;
 }