public function bind() { if (($token = Input::get('token')) && ($platform = Input::get('platform')) && in_array($platform, array('android', 'ios', 'chrome', 'safari'))) { $device = $this->getDevice(); $pushToken = PushToken::find((int) $device->id); if (!$pushToken) { PushToken::where('device_id', $device->id)->delete(); $pushToken = new PushToken(); $pushToken->device_id = (int) $device->id; } $pushToken->token = $token; $pushToken->platform = $platform; $pushToken->save(); return $this->respondNoContent(); } else { return $this->respondWithError('Unset necessary parameters'); } }
public function changePassword() { $user = Auth::user(); $oldPassword = Input::get('oldPassword'); $newPassword = Input::get('newPassword'); if ($user->checkPasswordAttribute($oldPassword)) { $user->password = $newPassword; // Delete others devices auth $header = Request::header('Authorization'); $token = explode(' ', $header)[1]; if ($token) { $user->devices()->where('auth_token', '!=', $token)->get()->each(function ($token) { PushToken::where('device_id', $token->id)->delete(); $token->delete(); }); } if ($user->save()) { return $this->respondNoContent(); } } else { return $this->respondInsufficientPrivileges('user.wrong-old-pass'); } return $this->respondServerError(); }