def IfLogin(): #fun.log(request.cookies.get('user_name')) if request.cookies.get('userid') == None: fun.log("未登陆,请先登录") return False else: return True
def RegisteredUsers(username,password,realname,studentnum,college,major,headimageurl,phonenum,classnum): arry = [] arry.append(-1) arry.append(-1) arry.append('') iskong = SendSQL("SELECT * FROM `ytuwind`.`yw_users` WHERE `username` = '"+username+"' ") fun.log(iskong) if str(iskong) != "()": arry[0] = 2 arry[2]="用户名重复" fun.log("用户名重复") return arry sql = \ "INSERT INTO `ytuwind`.`yw_users`(`username`, `password`, `realname`, `studentsnum`, `college`, `major`, `headimageurl`, `phonenum`, `classnum`, `QQnum`) " \ "VALUES ('"+username+"', '"+password+"', '"+realname+"', '"+studentnum+"', '"+college+"', '"+major+"', '"+headimageurl+"', '"+phonenum+"', '"+str(classnum)+"', '')" res = SendSQL(sql) if res == 1: fun.log("注册成功") if res == -1: arry[2]=("注册失败") fun.log("注册失败") return arry id = SendSQL("SELECT * FROM `ytuwind`.`yw_users` WHERE `username` = '" + username + "' ")[0][0] fun.log(id) arry[0]=(res) arry[1]=(id) arry[2]=("注册成功") return arry
def lostandfound(): if IfLogin() == False: return redirect(url_for('user_login')) else: userid = request.cookies.get('userid') title = "失物招领中心" lostandfoundtasts = SendSQL("SELECT * FROM `ytuwind`.`lostandfound`") fun.log(lostandfoundtasts) return render_template('lostandfoundtasts.html',**locals())
def lostandfoundtasts_id(id): if IfLogin() == False: return redirect(url_for('user_login')) else: userid=request.cookies.get('userid') res = SendSQL("SELECT * FROM `ytuwind`.`lostandfound` WHERE `id` = '"+id+"' ")[0] fun.log(res) title = "失物招领中心" if str(res)=="()": errortext = "未知错误" else: return render_template('lostandfound.html', **locals())
def UserId(): if request.method=='GET': userid=RFG('userid') if userid==None: userid = request.cookies.get('userid') fun.log(userid) title = "我的" user_data = GetUserDateByUserId(userid) fun.log(user_data) userid=user_data[0] username = user_data[1] return render_template('user.html',**locals())
def new(): if IfLogin() == False: return redirect(url_for('user_login')) userid = request.cookies.get('userid') fun.log(userid) user_data = GetUserDateByUserId(userid) username = user_data[1] title = "发布新帖子" if request.method == 'POST': data_title = RFG('title') data_content = RFG('content') data_phonenum = RFG('phonenum') data_qqnum = RFG('qqnum') data_url = url_for('static',filename='img/default_add.jpg') sql = "INSERT INTO `ytuwind`.`lostandfound`(`title`, `content`, `imageurls`,`phonenum`,`qqnum`,`userid`,`username`) VALUES ('"+data_title+"', '"+data_content+"', '"+data_url+"','"+data_phonenum+"','"+data_qqnum+"','"+userid+"','"+username+"')" res = SendSQL(sql) messagetext = "发布成功" return render_template('new.html',**locals())
def user_login(): if request.method=='POST': username = RFG('username') password = RFG('password') sql = "SELECT * FROM `ytuwind`.`yw_users` WHERE `username` = '"+username+"' AND `password` = '"+password+"'" res = SendSQL(sql) fun.log(res) if str(res)=="()": #登录失败 messagetext="账号或密码错误" fun.log("登录失败") return render_template('login.html',**locals()) else: userid= res[0][0] fun.log(userid) response = redirect(url_for('index')) response.set_cookie('username', username, max_age=2592000) response.set_cookie('userid', str(userid), max_age=2592000) return response else : userid = request.cookies.get("userid") if userid==None:#未登录 return render_template('login.html',**locals()) else:#已登录 title = "首页" return render_template('index.html',**locals())
import fun import local print ("Witaj w aplikacji librus") fun.log() ''' ADMINISTRATOR ''' if (fun.user_type() == "admin"): print("Dodawanie ucznia ") fun.add_student()
from flask import Flask,render_template,request,make_response,redirect,url_for,Response import pymysql import os import platform import datetime import json import fun app = Flask(__name__) # db = pymysql.connect("localhost", "ytuwind", "XC4djtPwCDjsfGZG", "ytuwind", charset='utf8' ) f = open('config.ini', 'r') config_text = f.read() f.close() config_json = json.loads(config_text) fun.log(config_json) # 打开数据库连接 db = pymysql.connect(config_json['db_host'], config_json['db_user'], config_json['db_pass'], config_json['db_name'], charset='utf8') #读取外部配置 app.debug = config_json['app_debug'] ''' 方法名:SendSQL() 功能:执行SQL语句并返回执行结果 ''' def SendSQL(sql): cursor = db.cursor() cursor.execute(sql)