Source

VPlayer / login.py

Full commit
import urllib, urllib2

import Cookie

from PyQt4 import QtCore


class Login(QtCore.QThread):
    def run(self):
        self.emit(QtCore.SIGNAL('status'), 'start')
        settings = QtCore.QSettings()
        email = unicode(settings.value('login/email').toString())
        passw = unicode(settings.value('login/password').toString())
        post_data = {'email': email,
                     'expire': 0,
                     'op': 'a_login_attempt',
                     'pass': passw}
        post = urllib.urlencode(post_data)
        req = urllib2.Request('http://vkontakte.ru/login.php', post)
        try:
            ans = urllib2.urlopen(req)
            state = ans.read()
        except:
            self.emit(QtCore.SIGNAL('status'), 'error')
            return
        if state[:4] != 'good':
            self.emit(QtCore.SIGNAL('status'), 'wronglogin')
            return
        try:
            cookies_raw = ans.headers['set-cookie']
        except:
            self.emit(QtCore.SIGNAL('status'), 'error')
            return
        c = Cookie.BaseCookie()
        c.load(cookies_raw)
        cookies = 'remixchk=%s; remixemail=%s; remixid=%s; remixpass=%s; remixsid=%s'
        cookies = cookies % (c['remixchk'].value, c['remixemail'].value,
                             c['remixmid'].value, c['remixpass'].value,
                             c['remixsid'].value)
        settings.setValue('cookies', QtCore.QVariant(cookies))
        self.emit(QtCore.SIGNAL('status'), 'ok')