def save(self, force_insert=False, force_update=False, using=None, update_fields=None): origin_obj = None origin_objs = list(Person.objects.filter(pk=self.pk)) if len(origin_objs) == 0 or origin_objs[0].passwd != self.passwd: #encrpt passwd encrypt_passwd = utils.encrypt_passwd(self.passwd) self.passwd = encrypt_passwd #super save super(Person,self).save()
def login(self, uid, passwd): self.params.update({"u":uid, "uin":uid}) # get the login signature keys = ("daid", "appid", "enable_qlogin", "s_url") payload = self._get_subdict(keys) r = self.s.get("https://ui.ptlogin2.qq.com/cgi-bin/login", params = payload) pattern = re.compile("g_login_sig=.*?\"(.*?)\"") self.params["login_sig"] = pattern.search(r.text).group(1) print self.params["login_sig"] # check whether we need input validation code keys = ("uin", "appid", "js_ver", "js_type", "login_sig", "u1") payload = self._get_subdict(keys) r = self.s.get("https://ssl.ptlogin2.qq.com/check", params = payload) print r.text pattern = re.compile(".*?'(.*?)'.*?'(.*?)'.*?'(.*?)'") m = pattern.search(r.text) vcode = m.group(2) if m.group(1) == '1': # well, need input validation code print 'Need validation code' url = 'https://ssl.captcha.qq.com/getimage?aid=1003903&r=0.9296404102351516&uin={0}'.format(uid) print url vcode = raw_input('Input validation code: ') self.params["u1"] += "?login2qq={0}&webqq_type={1}".format(self.params["login2qq"], self.params["webqq_type"]) self.params.update({"verifycode":vcode, "p":encrypt_passwd(passwd, vcode, m.group(3))}) # login stage 1 keys = ("u", "p", "verifycode", "webqq_type", "remember_uin", "login2qq", "aid", "u1", "h", "ptredirect", "ptlang", "daid", "from_ui", "pttype", "dumy", "fp", "action", "mibao_css", "t", "g", "js_type", "js_ver", "login_sig") payload = self._get_subdict(keys) r = self.s.get("https://ssl.ptlogin2.qq.com/login", params = payload) print r.text pattern = re.compile(".*?,.*?,.*?'(.*?)'") self.s.headers['referer'] = 'http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2' r = self.s.get(pattern.search(r.text).group(1)) # login stage 2 payload = {"clientid":self.params["clientid"], "psessionid":"null"} r_value = payload.copy() r_value.update({"status":"online", "ptwebqq":self.s.cookies["ptwebqq"], "passwd_sig":""}) payload["r"] = json.dumps(r_value) r = self.s.post("http://d.web2.qq.com/channel/login2", data = payload) ret = json.loads(r.text) print ret self.params.update(ret['result']) return ret['retcode']
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): origin_obj = None origin_objs = list(Person.objects.filter(pk=self.pk)) if len(origin_objs) == 0 or origin_objs[0].passwd != self.passwd: #encrpt passwd encrypt_passwd = utils.encrypt_passwd(self.passwd) self.passwd = encrypt_passwd #super save super(Person, self).save()
def login(request): if request.method == 'POST': #check post data login username = request.POST.get("username", default = None) passwd = request.POST.get("passwd", default = None) #check parameters in if username is None or passwd is None: return Http404('parameters wrong') person = list(Person.objects.filter(username = username, passwd = utils.encrypt_passwd(passwd))) if len(person) == 0: #validation wrong so relogin return HttpResponseRedirect('/gobang/login') else: person = person[0] #set session request.session['pk'] = person.pk request.session['username'] = person.username request.session['login'] = True return HttpResponseRedirect('/gobang/index') else: return httputils.render_html(request,'gobang/login.html', {})
def login(request): if request.method == 'POST': #check post data login username = request.POST.get("username", default=None) passwd = request.POST.get("passwd", default=None) #check parameters in if username is None or passwd is None: return Http404('parameters wrong') person = list( Person.objects.filter(username=username, passwd=utils.encrypt_passwd(passwd))) if len(person) == 0: #validation wrong so relogin return HttpResponseRedirect('/gobang/login') else: person = person[0] #set session request.session['pk'] = person.pk request.session['username'] = person.username request.session['login'] = True return HttpResponseRedirect('/gobang/index') else: return httputils.render_html(request, 'gobang/login.html', {})
def login(self, uid, passwd): self.params.update({"u": uid, "uin": uid}) # get the login signature keys = ("daid", "appid", "enable_qlogin", "s_url") payload = self._get_subdict(keys) r = self.s.get("https://ui.ptlogin2.qq.com/cgi-bin/login", params=payload) pattern = re.compile("g_login_sig=.*?\"(.*?)\"") self.params["login_sig"] = pattern.search(r.text).group(1) print self.params["login_sig"] # check whether we need input validation code keys = ("uin", "appid", "js_ver", "js_type", "login_sig", "u1") payload = self._get_subdict(keys) r = self.s.get("https://ssl.ptlogin2.qq.com/check", params=payload) print r.text pattern = re.compile(".*?'(.*?)'.*?'(.*?)'.*?'(.*?)'") m = pattern.search(r.text) vcode = m.group(2) if m.group(1) == '1': # well, need input validation code print 'Need validation code' url = 'https://ssl.captcha.qq.com/getimage?aid=1003903&r=0.9296404102351516&uin={0}'.format( uid) print url vcode = raw_input('Input validation code: ') self.params["u1"] += "?login2qq={0}&webqq_type={1}".format( self.params["login2qq"], self.params["webqq_type"]) self.params.update({ "verifycode": vcode, "p": encrypt_passwd(passwd, vcode, m.group(3)) }) # login stage 1 keys = ("u", "p", "verifycode", "webqq_type", "remember_uin", "login2qq", "aid", "u1", "h", "ptredirect", "ptlang", "daid", "from_ui", "pttype", "dumy", "fp", "action", "mibao_css", "t", "g", "js_type", "js_ver", "login_sig") payload = self._get_subdict(keys) r = self.s.get("https://ssl.ptlogin2.qq.com/login", params=payload) print r.text pattern = re.compile(".*?,.*?,.*?'(.*?)'") self.s.headers[ 'referer'] = 'http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2' r = self.s.get(pattern.search(r.text).group(1)) # login stage 2 payload = {"clientid": self.params["clientid"], "psessionid": "null"} r_value = payload.copy() r_value.update({ "status": "online", "ptwebqq": self.s.cookies["ptwebqq"], "passwd_sig": "" }) payload["r"] = json.dumps(r_value) r = self.s.post("http://d.web2.qq.com/channel/login2", data=payload) ret = json.loads(r.text) print ret self.params.update(ret['result']) return ret['retcode']