def login(self):
     if not self.username and not self.password:
         return True # fall back to free account
     elif self.username and self.password and len(self.username)>0 and len(self.password)>0:
         self.info('Login user=%s, pass=*****' % self.username)
         # get salt
         headers,req = self._create_request('',{'username_or_email':self.username})
         data = util.post(self._url('api/salt/'),req,headers=headers)
         xml = ET.fromstring(data)
         if not xml.find('status').text == 'OK':
             self.error('Server returned error status, response: %s' % data)
             return False
         salt = xml.find('salt').text
         # create hashes
         password = hashlib.sha1(md5crypt(self.password, salt)).hexdigest()
         digest = hashlib.md5(self.username + ':Webshare:' + self.password).hexdigest()
         # login
         headers,req = self._create_request('',{'username_or_email':self.username,'password':password,'digest':digest,'keep_logged_in':1})
         data = util.post(self._url('api/login/'),req,headers=headers)
         xml = ET.fromstring(data)
         if not xml.find('status').text == 'OK':
             self.error('Server returned error status, response: %s' % data)
             return False
         self.token = xml.find('token').text
         self.info('Login successfull')
         return True
     return False
    def login(self):
        if not self.username or not self.password:
            self.logout()
            return True  # fall back to free account
        elif self.token is not None:
            if self.userData() is not False:
                return True
            self.token = None

        if self.username and self.password and len(self.username) > 0 and len(
                self.password) > 0:
            self.logout()
            util.info('[SC] Login user=%s, pass=*****' % self.username)

            try:
                # get salt
                headers, req = self._create_request(
                    '', {'username_or_email': self.username})
                data = post(self._url('api/salt/'), req, headers=headers)
                xml = ET.fromstring(data)
                if not xml.find('status').text == 'OK':
                    util.error(
                        '[SC] Server returned error status, response: %s' %
                        data)
                    return False
                salt = xml.find('salt').text
                # create hashes
                password = hashlib.sha1(
                    md5crypt(self.password.encode('utf-8'),
                             salt.encode('utf-8'))).hexdigest()
                digest = hashlib.md5(self.username + ':Webshare:' +
                                     self.password).hexdigest()
                # login
                headers, req = self._create_request(
                    '', {
                        'username_or_email': self.username,
                        'password': password,
                        'digest': digest,
                        'keep_logged_in': 1
                    })
                data = post(self._url('api/login/'), req, headers=headers)
                xml = ET.fromstring(data)
                if not xml.find('status').text == 'OK':
                    self.clearToken()
                    util.error(
                        '[SC] Server returned error status, response: %s' %
                        data)
                    return False
                self.saveToken(xml.find('token').text)
                try:
                    util.cache_cookies(None)
                except:
                    pass
                util.info('[SC] Login successfull')
                return True
            except Exception, e:
                util.info('[SC] Login error %s' % str(e))
    def login(self):
        util.debug('[SC] start login')
        if not self.username or not self.password:
            util.debug('[SC] idem sa odhlasit lebo nemam meno/heslo')
            self.logout()
            return True  # fall back to free account
        elif self.token is not None:
            userData = self.userData(True)
            if userData is not False:
                self.checkHTTPS(userData)
                return True
            self.clearToken()

        if self.username and self.password and len(self.username) > 0 and len(
                self.password) > 0:
            self.logout()
            util.info('[SC] Login user=%s, pass=***** (%d)' %
                      (self.username, len(self.password)))

            try:
                # get salt
                headers, req = self._create_request(
                    '', {'username_or_email': self.username})
                data = post(self._url('api/salt/'),
                            req,
                            headers=headers,
                            output="content")
                util.info('[SC] salt: %s' % str(data))
                xml = ET.fromstring(str(data))
                if not xml.find('status').text == 'OK':
                    util.error(
                        '[SC] Server returned error status, response: %s' %
                        data)
                    return False
                salt = xml.find('salt').text
                if salt is None:
                    salt = ''
                # create hashes
                password = hashlib.sha1(
                    md5crypt(self.password.encode('utf-8'),
                             salt.encode('utf-8'))).hexdigest()
                digest = hashlib.md5(
                    self.username.encode('utf-8') + ':Webshare:' +
                    self.password.encode('utf-8')).hexdigest()
                util.debug('[SC] pass: %s | [%s] digest: %s' %
                           (password,
                            str(
                                md5crypt(self.password.encode('utf-8'),
                                         salt.encode('utf-8'))), digest))
                # login
                headers, req = self._create_request(
                    '', {
                        'username_or_email': self.username,
                        'password': password,
                        'digest': digest,
                        'keep_logged_in': 1
                    })
                data = post(self._url('api/login/'),
                            req,
                            headers=headers,
                            output="content")
                xml = ET.fromstring(data)
                if not xml.find('status').text == 'OK':
                    self.clearToken()
                    util.error(
                        '[SC] Server returned error status, response: %s' %
                        data)
                    return False
                self.saveToken(xml.find('token').text)
                util.info('[SC] Login successfull')
                userData = self.userData(True)
                self.checkHTTPS(userData)
                return True
            except Exception as e:
                util.info('[SC] Login error %s' % str(e))
        self.clearToken()
        return False
    def login(self):
        util.debug('[SC] start login')
        if not self.username or not self.password:
            util.debug('[SC] idem sa odhlasit lebo nemam meno/heslo')
            self.logout()
            return True  # fall back to free account
        elif self.token is not None:
            userData = self.userData(True)
            if userData is not False:
                self.checkHTTPS(userData)
                return True
            self.clearToken()

        if self.username and self.password and len(self.username) > 0 and len(
                self.password) > 0:
            self.logout()
            util.info('[SC] Login user=%s, pass=***** (%d)' %
                      (self.username, len(self.password)))

            try:
                # get salt
                headers, req = self._create_request(
                    '', {'username_or_email': self.username})
                data = post(
                    self._url('api/salt/'),
                    req,
                    headers=headers,
                    output="content")
                util.info('[SC] salt: %s' % str(data))
                xml = ET.fromstring(str(data))
                if not xml.find('status').text == 'OK':
                    util.error(
                        '[SC] Server returned error status, response: %s' %
                        data)
                    return False
                salt = xml.find('salt').text
                if salt is None:
                    salt = ''
                # create hashes
                password = hashlib.sha1(
                    md5crypt(
                        self.password.encode('utf-8'),
                        salt.encode('utf-8'))).hexdigest()
                digest = hashlib.md5(
                    self.username.encode('utf-8') + ':Webshare:' +
                    self.password.encode('utf-8')).hexdigest()
                util.debug('[SC] pass: %s | [%s] digest: %s' %
                           (password,
                            str(
                                md5crypt(
                                    self.password.encode('utf-8'),
                                    salt.encode('utf-8'))), digest))
                # login
                headers, req = self._create_request(
                    '', {
                        'username_or_email': self.username,
                        'password': password,
                        'digest': digest,
                        'keep_logged_in': 1
                    })
                data = post(
                    self._url('api/login/'),
                    req,
                    headers=headers,
                    output="content")
                xml = ET.fromstring(data)
                if not xml.find('status').text == 'OK':
                    self.clearToken()
                    util.error(
                        '[SC] Server returned error status, response: %s' %
                        data)
                    return False
                self.saveToken(xml.find('token').text)
                util.info('[SC] Login successfull')
                userData = self.userData(True)
                self.checkHTTPS(userData)
                return True
            except Exception as e:
                util.info('[SC] Login error %s' % str(e))
        self.clearToken()
        return False