~ubuntu-branches/ubuntu/lucid/lastfm/lucid

« back to all changes in this revision

Viewing changes to src/libUnicorn/WebService/VerifyUserRequest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-31 09:49:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071231094954-ix1amvcsj9pk61ya
Tags: 1:1.4.1.57486.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #180254), remaining changes:
  - debian/rules;
    - Added dh_icons
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 - 2007 by                                          *
 
3
 *      Max Howell, Last.fm Ltd <max@last.fm>                              *
 
4
 *                                                                         *
 
5
 *   This program 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 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program 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 this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin Steet, Fifth Floor, Boston, MA  02110-1301, USA.          *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "UnicornCommon.h"
 
22
#include "logger.h"
 
23
#include "Request.h"
 
24
 
 
25
 
 
26
VerifyUserRequest::VerifyUserRequest()
 
27
        : Request( TypeVerifyUser, "VerifyUser" ),
 
28
          m_userAuthCode( AUTH_ERROR )
 
29
{
 
30
    setOverrideCursor();
 
31
}
 
32
 
 
33
 
 
34
void
 
35
VerifyUserRequest::start()
 
36
{
 
37
    time_t now; 
 
38
    time( &now );
 
39
    QString const time = QString::number( now );
 
40
 
 
41
    // Concatenate pw hash with time
 
42
    QString auth = m_passwordMd5 + time;
 
43
    QString authLower = m_passwordMd5Lower + time;
 
44
    
 
45
    // Hash the concatenated string to create auth code
 
46
    QString authMd5 = UnicornUtils::md5Digest( auth.toUtf8() );
 
47
    QString authMd5Lower = UnicornUtils::md5Digest( authLower.toUtf8() );
 
48
 
 
49
    QString const path = "/ass/pwcheck.php?"
 
50
                    "time=" + QString( QUrl::toPercentEncoding( time ) ) +
 
51
                    "&username=" + QString( QUrl::toPercentEncoding( m_username ) ) +
 
52
                    "&auth=" + authMd5 +
 
53
                    "&auth2=" + authMd5Lower +
 
54
                    "&defaultplayer="
 
55
                    #ifdef WIN32
 
56
                    + QString( QUrl::toPercentEncoding( UnicornUtils::findDefaultPlayer() ) )
 
57
                    #endif
 
58
                    ;
 
59
 
 
60
    get( path );
 
61
}
 
62
 
 
63
 
 
64
void
 
65
VerifyUserRequest::success( QByteArray data )
 
66
{
 
67
    QString response = data;
 
68
    response = response.trimmed();
 
69
 
 
70
    //TODO mxcl do in baseclass?
 
71
    LOG( 4, "Verify response: " << response << "\n" );
 
72
 
 
73
    m_bootStrapCode = response.contains( "BOOTSTRAP" ) 
 
74
                ? BOOTSTRAP_ALLOWED
 
75
                : BOOTSTRAP_DENIED;
 
76
 
 
77
    if (response.contains( "OK2" ))
 
78
        m_userAuthCode = AUTH_OK_LOWER;
 
79
    else if (response.contains( "OK" ))
 
80
        m_userAuthCode = AUTH_OK;
 
81
    else if (response.contains( "INVALIDUSER" ))
 
82
        m_userAuthCode = AUTH_BADUSER;
 
83
    else if (response.contains( "BADPASSWORD" ))
 
84
        m_userAuthCode = AUTH_BADPASS;
 
85
    else
 
86
        m_userAuthCode = AUTH_ERROR;
 
87
}