Пример #1
0
def sign_by_face():
    mysql = SQLUtil()
    if request.method == 'POST':
        data = request.form.get('face-info')
        username = request.form.get('username')
        face_info = data.split('base64,')[1]
        aip = tylt_AipFace()
        try:
            sql = "SELECT face_info FROM user WHERE name='%s'" % username
            face_info_from_db = mysql.getOne(sql)  # 获取数据库中的人脸信息
            mysql.dispose()
            if not face_info_from_db['face_info']:
                return 'no_face_info'  # 数据库中没有人脸信息
            else:
                aip.face_constrast_img1 = face_info_from_db['face_info']
                aip.face_constrast_img2 = face_info
                contrast_result = aip.face_contrast()
                if contrast_result['error_code'] == 0 and contrast_result[
                        'result']['score'] >= 80:
                    session['un'] = username
                    return 'success'

        except Exception as e:
            print(e)
            return '<h1>服务器发生未知错误,请稍后重试</h1>'
    return render_template('sign_in_by_face.html')
Пример #2
0
def username_check():
    if request.method == "GET":
        username = request.args["username"]
        mysql = SQLUtil()
        sql_user = "******" % username
        user_result = mysql.getOne(sql_user)

        if user_result['COUNT(name)'] == 0:
            print(jsonify({"user_exits": False}))
            return jsonify({"user_exits": False})
        else:
            print(jsonify({"user_exits": True}))
            return jsonify({"user_exits": True})

    else:
        return render_template("register_by_face.html")
Пример #3
0
def username_check():
    if request.method == "GET":
        username = request.args["username"]
        mysql = SQLUtil()
        sql_user = "******" % username
        user_result = mysql.getOne(sql_user)

        if user_result['COUNT(name)'] == 0:
            print(jsonify({"user_exits": False}))

            return jsonify({"user_exits": False})
        else:
            resp = make_response(redirect(url_for('home')))
            resp.set_cookie('userID', username)
            print(jsonify({"user_exits": True}))
            return jsonify({"user_exits": True})

    else:
        return render_template("register_by_face.html")