/** * The register method is responsible for checking/validating * the given input (email and password) and either return an error code or * create a new user. * * @return mixed */ public function register() { $validateUser = $this->validateUser(); if ($validateUser->status == 'error') { return \Response::json($validateUser); } else { //All's good, create a new user $user = User::create(['name' => \Request::get('name'), 'email' => \Request::get('email'), 'password' => bcrypt(\Request::get('password'))]); if (!\Request::has('role')) { $role['role'] = 'mobile'; } else { $role['role'] = 'web'; } //assign role to user $role = Role::where('name', $role)->first(); $user->roles()->save($role); $device = $this->sanitizeDevice($user->id); $this->deviceService->store($user->id, $device); //Retrieve the JWT and send back to the Controller $token = \JWTAuth::fromUser($user); $response = new ApiResponse(); $response->status = 'success'; $response->message = ['token' => $token]; } return \Response::json($response); }
public function update($data) { $response = new ApiResponse(); $status = 200; $mission = Mission::find(\Request::get('id')); if ($mission == null) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'mission_not_found', 'description' => 'The mission was not found']; $status = 400; } else { $mission = $this->sanitize($data, $mission); try { $this->radicalIntegrationManager->updateMission($mission); } catch (RadicalApiException $e) { Log::error($e); //For now ingore, see [CIT-380] // $response->status = 'error'; // $response->message = $e->getMessage(); // $status = 500; } $mission->save(); $response->status = 'success'; $response->message = $mission->id; } return \Response::json($response, $status); }
public function rejectProject($id, array $input) { $project = Project::find($id); if ($project) { /* @var Project $project*/ if ($project->status->key == 'university') { $this->linkToFacultyStatus($project, $input); $this->linkToSuggestion($project, $input); } else { return \Response::json(["error" => "There is something wrong, Please contact administrator."], 400); } } }
public function store() { //TODO: maybe the name of the device is not needed -> retrieve it from jwt $responseObs = $this->validateObservation(); if ($responseObs->status == 'error') { return $responseObs; } else { $device = Device::where('device_uuid', \Request::get('device_uuid'))->first(); //first check if the device is registered for this mission to radical //for our db, that means that there's a row in devices_missions table if (!$this->deviceService->isRegistered(\Request::get('mission_id'), \Request::get('device_uuid'))) { if ($this->mission == null) { $this->mission = Mission::find(\Request::get('mission_id')); } if (!\Request::has('latitude') || \Request::get('latitude') == '') { $latitude = number_format(0, 6); } else { $latitude = number_format(\Request::get('latitude'), 6); } if (!\Request::has('longitude') || \Request::get('longitude') == '') { $longitude = number_format(0, 6); } else { $longitude = number_format(\Request::get('longitude'), 6); } //first create a row in devices_missions table $device->missions()->attach($this->mission->id, ['device_uuid' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'latitude' => $latitude, 'longitude' => $longitude, 'registration_date' => date('Y-m-d H:i:s')]); $this->mission->users()->attach(\Auth::user()->id); //then send data to radical api $tmp_device = ['Device_UUID' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'Model' => $device->model, 'Manufacturer' => $device->manufacturer, 'Latitude' => $latitude, 'Longitude' => $longitude, 'Type' => $device->type, 'Status' => intval($device->status), 'Registration_Date' => date('Y-m-d H:i:s')]; $this->deviceService->registerToRadical($tmp_device); } $responseMeas = $this->validateMeasurements(\Request::get('measurements')); if ($responseMeas->status == 'error') { return \Response::json($responseMeas); } if ($this->mission == null) { $this->mission = Mission::find(\Request::get('mission_id')); } $observation = new Observation(['device_uuid' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'latitude' => \Request::get('latitude'), 'longitude' => \Request::get('longitude'), 'observation_date' => \Request::get('observation_date'), 'device_id' => $device->id]); //save new observation to the db $observation->save(); $radicalMeasurements = $this->getMeasurements($observation->id); $radicalObservation = ['Device_UUID' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'Latitude' => \Request::get('latitude'), 'Longitude' => \Request::get('longitude'), 'Observation_Date' => \Request::get('observation_date'), 'Measurements' => $radicalMeasurements]; $this->radicalIntegrationManager->storeObservation($radicalObservation); return $observation; } }