Example #1
0
File: try.py Project: mikejly/demo
def upload_post(cityid):
    file = request.files['file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    db = open_db()
    execute_sql(db, "UPDATE city SET picture = '"+filename+"'WHERE id = '"+cityid+"'",'update')
    close_db(db)
    return render_template('upload-process.html',cityid = cityid,filename = filename)
Example #2
0
def inject_book_mysql(today, dataPath, cursor, db):
    with open(dataPath, 'r') as fr:
        timeStamp = int(today)
        for line in fr.readlines():
            line = line.strip('\n')
            arr = line.split('\t')
            if len(arr) != 4:
                print('错误行: ' + line + '\n')
                continue
            msql = ''
            msql = get_inject_book_sql(arr, timeStamp)
            execute_sql(cursor, msql)
    commit_sql(db)
    print ('当天数据注入 MySQL 完成!!!')
    return
Example #3
0
File: try.py Project: mikejly/demo
def register():
    username = request.form['regUsername']
    password = request.form['regPassword']
    print(password)
    db = open_db()
    if len(username) <= 20 and 7 <= len(password) <= 20:
        execute_sql(db, "insert into user (username, password,root) values('"+ username + "', '" + password +"','0')", 'insert')
        uid = execute_sql(db, "select id from user where username = '******'", 'fetchone')
        close_db(db)
        session['username'] = username
        session['uid'] = uid[0]
        return "success"
    else:
        close_db(db)
        return "outOfRange"
Example #4
0
def forgot():
    json_msg = [
        {
            "msg_code": 201,
            "message": "请至邮箱查收密码信息,重新登录"
        }, {
            "msg_code": 301,
            "message": "用户名不可为空"
        }, {
            "msg_code": 401,
            "message": "该用户不存在"
        }

    ]
    name = request.form.get('name')
    if name is None or name == '':
        return json.dumps(json_msg[1])
    else:
        pick_sql = "select " \
                   "     `password`, " \
                   "     `email` " \
                   "from " \
                   "     `flask_user` " \
                   "where " \
                   "     `is_delete` = '0' and" \
                   "     `name` = '%s'" % name
        data = execute_sql(db="db_local_mac", sql=pick_sql)
        if not data:
            return json.dumps(json_msg[2])
        else:
            password = data[0]['password']
            email = data[0]['email']
            send_mail(name=name, mail=email, password=Secret.exsecret(password))
            return json.dumps(json_msg[0])
Example #5
0
def register():
    # 枚举
    json_msg = [
        {
            "msg_code": 0,
            "message": "注册成功,请重新登录"
        }, {
            "msg_code": 201,
            "message": "该用户已存在,请直接登录"
        }, {
            "msg_code": 301,
            "message": "注册失败"
        }, {
            "msg_code": 401,
            "message": "任意项不能为空"
        }
    ]
    name = request.form.get('name')
    email = request.form.get('email')
    password = request.form.get('password')
    if (name is None or not name != '') or (password is None or not '' != password) or (
            email is None or not '' != email):
        return json.dumps(json_msg[3])
    else:
        pick_sql = "select " \
                   "     `password` " \
                   "from " \
                   "     `flask_user` " \
                   "where " \
                   "     `is_delete` = '0' and" \
                   "     `name` = '%s'" % name
        data = execute_sql(db="db_local_mac", sql=pick_sql)
        if data:
            return json.dumps(json_msg[1])
        else:
            try:
                insert_sql = "insert into " \
                             "      `flask_user` " \
                             "values " \
                             "      ('0','%s','%s','%s',NOW(),NOW(),'0', NULL, NULL);" % (
                                 name, Secret.tosecret(password), email
                             )
                execute_sql(db="db_local_mac", sql=insert_sql)
                return json.dumps(json_msg[0])
            except Exception as err:
                print(err)
                return json.dumps(json_msg[2])
Example #6
0
File: try.py Project: mikejly/demo
def area(cityid):
    uid = if_signin(session)
    db = open_db()
    content = execute_sql(db, "select id,name,description,picture from city where id = '"+cityid+"'", 'fetchall')
    root = if_root(db,uid)
    cities = id_name_get(db)
    close_db(db)
    return render_template('area.html',cities = cities,username = session['username'],content = content,cityid = cityid,root = root[0],uid = uid)
Example #7
0
def save_profile():
    name = request.form.get('name')
    email = request.form.get('email')
    phone = request.form.get('phone')
    description = request.form.get('description')
    if not name:
        return redirect(url_for("profile"))
    else:
        save_sql = "update \n" \
                   "    `flask_user` \n" \
                   "set `email` = '%s', \n" \
                   "    `phone` = '%s', \n" \
                   "    `description` = '%s' \n" \
                   "WHERE \n" \
                   "    `name` = '%s';" % (email, phone, description, name)
        # print(save_sql)
        execute_sql(db="db_local_mac", sql=save_sql)
        return render_template("profile.html", name=name, email=email, phone=phone, description=description)
Example #8
0
def activity_bak():
    if session == {}:
        return render_template('login.html')
    else:
        user_name = '@' + session['name']
        # 歌词数据
        sql = 'select `title`,`pic_url`,`singer`,`lyric` from `music_newest`'
        data_list = execute_sql(db='db_local_mac', sql=sql)
        return render_template('activity_bak.html', userName=user_name, args=2, url_list=activity_url,
                               content_arr=data_list)
Example #9
0
File: try.py Project: mikejly/demo
def Signin():
    username = request.form['signUsername']
    password = request.form['signPassword']
    db = open_db()
    if len(username) <= 20 and 7 <=len(password) <= 20:
        data = execute_sql(db, "select id, username, password from user where username = '******'", 'fetchall')
        close_db(db)
        if data and password == data[0][2]:
            session['uid'] = data[0][0]
            session['username'] = data[0][1]
            return "success"
        return "fault"
    else:
        close_db(db)
        return "outOfRange"
Example #10
0
def login():
    # 枚举
    json_msg = [
        {
            "msg_code": 200,
            "message": "登录成功"
        }, {
            "msg_code": 201,
            "message": "用户名或密码错误"
        }, {
            "msg_code": 301,
            "message": "用户不存在请注册"
        }, {
            "msg_code": 302,
            "message": "用户名、密码不能为空"
        }]
    name = request.values.get('name')
    password = request.values.get('password')
    if name == 'admin' and password == '123456':
        session['name'] = name
        session['password'] = Secret.tosecret(password)
        print(session)
        return json.dumps(json_msg[0])
    else:

        if (name is None or not name != '') or (password is None or not '' != password):
            return json.dumps(json_msg[3])
        else:
            pick_sql = "select " \
                       "     `password` " \
                       "from " \
                       "     `flask_user` " \
                       "where " \
                       "     `is_delete` = '0' and" \
                       "     `name` = '%s'" % name
            data = execute_sql(db="db_local_mac", sql=pick_sql)
            if not data:
                return json.dumps(json_msg[2])
            elif password == Secret.exsecret(data[0]['password']):
                session['name'] = name
                session['password'] = Secret.tosecret(password)
                print(session)
                return json.dumps(json_msg[0])
            else:
                return json.dumps(json_msg[1])
Example #11
0
def profile():
    try:
        name = session['name']
        user_name = '@' + session['name']
        pick_sql = "select " \
                   "     `email`, " \
                   "     `phone`, " \
                   "     `description` " \
                   "from " \
                   "     `flask_user` " \
                   "where " \
                   "     `is_delete` = '0' and" \
                   "     `name` = '%s'" % name
        data = execute_sql(db="db_local_mac", sql=pick_sql)
        email = data[0]['email']
        phone = data[0]['phone']
        description = data[0]['description']
        return render_template("profile.html", userName=user_name, name=name, email=email, phone=phone,
                               description=description)
    except:
        return render_template("login.html")
Example #12
0
File: try.py Project: mikejly/demo
def modification(cityid):
    modification = request.form['description']
    db = open_db()
    execute_sql(db, "UPDATE city SET description = '"+modification+"'WHERE id = '"+cityid+"'", 'update')
    close_db(db)
    return "success"