/src/libtomahawk/database/DatabaseCommand_ClientAuthValid.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 61 lines · 35 code · 9 blank · 17 comment · 2 complexity · d92ce7177f5239291808ab2ec0a5569b MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "DatabaseCommand_ClientAuthValid.h"
  19. #include "DatabaseImpl.h"
  20. #include "TomahawkSqlQuery.h"
  21. #include "utils/Logger.h"
  22. #include "Source.h"
  23. namespace Tomahawk
  24. {
  25. DatabaseCommand_ClientAuthValid::DatabaseCommand_ClientAuthValid( const QString& clientToken, QObject* parent )
  26. : DatabaseCommand( parent )
  27. , m_clientToken( clientToken )
  28. {
  29. }
  30. void DatabaseCommand_ClientAuthValid::exec( DatabaseImpl* lib )
  31. {
  32. TomahawkSqlQuery q = lib->newquery();
  33. q.prepare( "SELECT name FROM http_client_auth WHERE token = ?" );
  34. q.addBindValue( m_clientToken );
  35. if ( q.exec() )
  36. {
  37. if ( q.next() )
  38. {
  39. QString name = q.value( 0 ).toString();
  40. emit authValid( m_clientToken, name, true );
  41. }
  42. else
  43. {
  44. emit authValid( m_clientToken, QString(), false );
  45. }
  46. }
  47. else
  48. {
  49. qWarning() << "Failed to query http auth table for client:" << m_clientToken;
  50. }
  51. }
  52. }