def register(): try: if request.method == "POST": formrole = request.form['form-role'] authcode = request.form['form-verify'] email = request.form['form-username'] password = genMd5(request.form['form-password']) name = request.form['form-name'] if session["auth_code"].upper() == authcode.upper(): print 'hello world' registerSuccess = resume().insert(username=email, password=password, realName=name, role='r' if formrole == 'resume' else 'h').execute() session.pop('auth_code') resu = resume().select("*").where(username=email).execute() CurrentSession.put("user", resu[0]) try: return jsonify({"status": 1, "msg": "hello", "nexturl": "setting"}) except: logger.warn("send verfiy email fails" + format_exc()) return jsonify({"status": 0, "msg": "邮件发送有问题"}) else: return jsonify({"status": 0, "msg": "验证码有问题"}) else: return render_template("register.html") except: logger.info(format_exc())
def logout(): try: CurrentSession.delete("user") return render_template("index.html") except: logger.info(format_exc()) return redirect("/")
def weixin_sendMsg(): try: text = request.data root = ElementTree.fromstring(text) print root.findall("ToUserName")[0].text print root.findall("FromUserName")[0].text print root.findall("CreateTime")[0].text print root.findall("MsgType")[0].text except: logger.info(format_exc())
def setting(): # 对自己的主页进行设置 user = CurrentSession.get("user") try: logger.info(user.realName, user.myDomain) return render_template("setting.html", name=user.realName, myDomain=user.myDomain, avatar=user.avatar) except: logger.info(format_exc()) return redirect("/")
def execute_sql(self, sql): con = self.pool.getConn() try: cur, res = con.cursor(), 0 res = cur.execute(sql) return res except: logger.info(format_exc()) return "" finally: self.pool.release(con)
def insert(self, **kwargs): self.__sqltype__ = "insert" columns, values = [], [] for key in kwargs.keys(): columns.append(key) if isinstance(getattr(self, key), INT): values.append(str(kwargs[key])) else: values.append("'{}'".format(kwargs[key])) logger.info("insert ==> {},{}".format(columns, values)) self.__sql__ = '''insert into {}({}) values({})'''. \ format(self.__tablename__, ','.join(columns), ','.join(values)) return self
def authCode(): try: img, auth_code = create_validata_code() destination = open('tmp', 'wb')#io.BytesIO() img.save(destination, "JPEG", quality=95, optimize=True, progressive=True) destination.close() destination = open('tmp', 'rb') resp = make_response(destination.read()) resp.headers['Content-Type'] = 'image/jpeg' session["auth_code"] = auth_code logger.info("session.auth_code {}".format(session["auth_code"])) destination.close() return resp except: logger.info(format_exc())
def uploadPortrait(): try: user = CurrentSession.get('user') src = request.form['avatar_src'] # 后期要进行剪裁会用到这个data data = request.form['avatar_data'] imgFile = request.files['avatar_file'] imgurl = '{}{}'.format(conf['uploader'] if conf['uploader'].endswith('/') else conf['uploader'] + '/', user.username) imgFile.save(imgurl) imgurl = "/assets/userUploader/{}".format(user.username) resume().update(avatar=imgurl).where(username=user.username) CurrentSession.update('user', avatar="/assets/userUploader/{}".format(user.username)) return jsonify({'state': 200, 'message': imgurl, 'result': imgurl}) except: logger.info(format_exc())
def weixin_verify(): try: signature = request.args.get('signature') timestamp = request.args.get('timestamp') nonce = request.args.get('nonce') echostr = request.args.get('echostr','') text = request.data print signature, timestamp, echostr if valid(signature, timestamp, nonce): root = ElementTree.fromstring(text) myName = root.findall("ToUserName")[0].text userName = root.findall("FromUserName")[0].text return """ <xml> <ToUserName><![CDATA[{}]]></ToUserName> <FromUserName><![CDATA[{}]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[你好]]></Content> </xml> """.format(userName, myName) except: logger.info(format_exc())
def execute(self): sql = self.__sql__ + self.__where__ + self.__other__ logger.info("形成的sql语句:{}".format(sql)) con = self.pool.getConn() try: cur, res = con.cursor(), 0 res = cur.execute(sql) if self.__sqltype__ == "select": ress = cur.fetchall() resumes = list() for res in ress: tmp = self.__class__() for i, column in enumerate(self.__columns__): setattr(tmp, column, res[i]) resumes.append(tmp) return resumes else: con.commit() return res except: logger.info(format_exc()) finally: self.pool.release(con)