def post(self): uname = self.get_argument("uname", "") cell = self.get_argument("cell", "") upass = self.get_argument("upass", "") upass2 = self.get_argument("upass2", "") # if upass2 is not upass: if upass2 != upass: self.write({'code': 'error', 'reason': 'pass2'}) return salt = random_string(16) authcode = random_number(6) password = hashlib.sha1((upass + salt).encode('ascii')).hexdigest() info = {} user = User( username=uname, password=password, status=0, type=2, salt=salt, reg_date=datetime_str(), courses='', info=info) self.db.add(user) self.db.commit() if user.id: self.set_secure_cookie("userinfo", json.dumps({ 'type': user.type, 'name': user.username, 'id': user.id}) ) # TODO: 发短信 jobq.enqueue("job_send_sms_auth.tpl_send_sms", "#code#=%s" % authcode, cell) self.write({'code': 'ok', 'id': user.id}) else: self.write({'code': 'error'})
def post(self): uid = self.get_argument("uid") user = self.db.query(User).get(uid) if not user: self.write({'code': 'error'}) return if user.cell: # 发短信验证 jobq.enqueue("job_send_sms_auth.tpl_send_sms", "#code#=%s" % user.authcode, user.cell) else: # 发邮箱验证 jobq.enqueue("job_send_email.send_email", user.email, u'zhitu99.com 注册验证', u""" 你好,%s, 感谢你注册zhitu99.com,你的验证码是 %s 。 中科知图 """ % (user.username, user.authcode)) self.write({'code': 'ok'})