Example #1
0
def update(uuid, name):
    engine, cursor = db.engine.get_engine()
    sql = "update station set name='%s' where uuid='%s'" % (name, uuid)
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #2
0
def drop_code(uuid):
    engine, cursor = db.engine.get_engine()
    sql = "delete from verify_code where uuid='%s'" % uuid
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #3
0
def drop_subway_line(uuid):
    engine, cursor = db.engine.get_engine()
    sql = "delete from subway_line where uuid=\"%s\"" % uuid
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #4
0
def unlock(uuid):
    engine, cursor = db.engine.get_engine()
    sql = "update user set status='active' where uuid='%s'" % uuid
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #5
0
def add_station(**kwargs):
    engine, cursor = db.engine.get_engine()
    sql = "insert into station(uuid, name) values(%s, %s)"
    val = (kwargs["uuid"], kwargs["name"])
    cursor.execute(sql, val)
    engine.commit()
    engine.close()
    return
Example #6
0
def update_subway_line(uuid, name):
    engine, cursor = db.engine.get_engine()
    sql = "update subway_line set name=\"%s\" where uuid=\"%s\"" % \
          (name, uuid)
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #7
0
def add_subway_line(uuid, name):
    engine, cursor = db.engine.get_engine()
    sql = "insert into subway_line(uuid, name) values(%s, %s)"
    val = (uuid, name)
    cursor.execute(sql, val)
    engine.commit()
    engine.close()
    return
Example #8
0
def update_photo(uuid, url):
    engine, cursor = db.engine.get_engine()
    sql = "update user set image='%s' where uuid='%s'" % \
          (url, uuid)
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #9
0
def add_code(uuid, code, operate, modify_time):
    engine, cursor = db.engine.get_engine()
    sql = "insert into verify_code values(%s, %s, %s, %s)"
    val = (uuid, code, operate, modify_time)
    cursor.execute(sql, val)
    engine.commit()
    engine.close()
    return
Example #10
0
def update_token(email, token):
    engine, cursor = db.engine.get_engine()
    sql = "update user set token='%s' where email='%s'" % \
          (token, email)
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #11
0
def add_relation(**kwargs):
    engine, cursor = db.engine.get_engine()
    sql = "insert into entity_relation(uuid, parent, child, relation) " \
          "values(%s, %s, %s, %s)"
    val = (kwargs["uuid"], kwargs["parent"], kwargs["child"],
           kwargs["relation"])
    cursor.execute(sql, val)
    engine.commit()
    engine.close()
    return
Example #12
0
def update(**params):
    engine, cursor = db.engine.get_engine()
    sql = "update user set email='%s', username='******', password='******' " \
          "where uuid='%s'" % (params["email"],
                               params["username"],
                               params["password"],
                               params["uuid"]
                               )
    cursor.execute(sql)
    engine.commit()
    engine.close()
    return
Example #13
0
def add_user(**kwargs):
    engine, cursor = db.engine.get_engine()
    username = kwargs["username"]
    password = kwargs["password"]
    create_time = kwargs["register_time"]
    token = kwargs["token"]
    uuid = kwargs["uuid"]
    email = kwargs["email"]
    user_type = kwargs["user_type"]
    image = "/root/image/localhost/default.jpeg"
    sql = "insert into user values(%s, %s, %s, %s, %s, %s, %s, default, %s)"
    val = (uuid, email, username, password, token, user_type, create_time,
           image)
    cursor.execute(sql, val)
    engine.commit()
    engine.close()
    return
Example #14
0
def init_user():
    engine, cursor = db.engine.get_engine()
    sql = """
        create table if not exists user(
        uuid        char(27) not null,
        email       varchar(30),
        username    varchar(24) default "subway user",
        password    varchar(18) not null,
        token       char(10) not null,
        user_type   enum("admin", "user") not null default "user",
        create_time datetime not null,
        status      enum("active", "down", "lock") not null default "active",
        image       varchar(100),
        primary key(email)
        ) charset utf8
        """
    cursor.execute(sql)
    logger.info("Setup user finished.")

    # add admin user
    conf_path = util.get_root_path() + "/conf/platform.conf"
    deploy_conf = ConfigParser()
    deploy_conf.read([conf_path])
    uuid = util.generate_uuid()
    admin_user = deploy_conf.get("deploy", "admin_user")
    admin_pwd = deploy_conf.get("deploy", "admin_pwd")
    email = deploy_conf.get("deploy", "admin_email")
    image = "/root/image/localhost/default.jpeg"
    try:
        get_user_detail(email)
    except DBError:
        now = util.get_time_string_format()
        token = util.general_token()
        user_type = "admin"
        sql = "insert into user " \
              "values(%s, %s, %s, %s, %s, %s, %s, default, %s)"
        val = (uuid, email, admin_user, admin_pwd, token, user_type, now,
               image)
        cursor.execute(sql, val)
        logger.info("Init default admin user success.")
    engine.commit()
    engine.close()
    return