コード例 #1
0
ファイル: userdata.go プロジェクト: chogaths/robin
func (self *oprUserDataCom) Start(peer netfw.IPeer) {

	m := peer.(martinihttp.IMartiniAcceptor).GetInterface()

	m.Get("/userdata", func(r render.Render) {

		var zonesInfo []zoneInfo

		dbopr.IterateShowDB(func(name, showName string) {

			zone := zoneInfo{
				Name:     name,
				ShowName: showName,
			}

			res, err := dbopr.ExecuteSQL(name, &dbZone{}, "select $FIELD_NAME$ from tb_area")
			if err != nil {
				log.Println(err)
			}

			for _, b := range res {
				area := b.(dbZone)
				zone.AreaID = append(zone.AreaID, area.Area_id)
			}

			if len(zone.AreaID) > 0 {
				zonesInfo = append(zonesInfo, zone)
			}

		})

		r.HTML(200, "index", nil)
		r.HTML(200, "userdata", zonesInfo)
	})

	m.Post("/queryuserdata", binding.Bind(queryByZone{}), func(msg queryByZone, r render.Render) {

		table := fmt.Sprintf("tb_rank_%d", msg.Service)

		if !dbopr.IsTableExist(msg.Zone, table) {
			r.Data(200, []byte(fmt.Sprintf("zone(%s) is not exist!", table)))
			return
		}

		maxpage := dbopr.GetRecordPageCount(msg.Zone, table)

		var err error
		var res []interface{}

		if msg.Zone == "db_td2ios" {
			if msg.ID != 0 {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select %s.t_sid, %s.t_imei, %s.t_nickname, %s.t_victory, %s.t_yuxi_value, tb_user.t_password from %s, tb_user where %s.t_sid=tb_user.t_sid and %s.t_sid=%d", table, table, table, table, table, table, table, table, msg.ID)
			} else if msg.IMEI != "" {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select %s.t_sid, %s.t_imei, %s.t_nickname, %s.t_victory, %s.t_yuxi_value, tb_user.t_password from %s, tb_user where %s.t_sid=tb_user.t_sid and %s.t_imei='%s'", table, table, table, table, table, table, table, table, msg.IMEI)
			} else {
				if msg.Page <= 0 {
					msg.Page = 1
				} else if msg.Page > maxpage {
					msg.Page = maxpage
				}
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select %s.t_sid, %s.t_imei, %s.t_nickname, %s.t_victory, %s.t_yuxi_value, tb_user.t_password from %s, tb_user where %s.t_sid=tb_user.t_sid limit %d,%d", table, table, table, table, table, table, table, (msg.Page-1)*100, 100)
			}
		} else {
			if msg.ID != 0 {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select $FIELD_NAME$ from %s where t_sid=%d", table, msg.ID)
			} else if msg.IMEI != "" {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select $FIELD_NAME$ from where t_imei='%s'", table, msg.IMEI)
			} else {
				if msg.Page <= 0 {
					msg.Page = 1
				} else if msg.Page > maxpage {
					msg.Page = maxpage
				}
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select $FIELD_NAME$ from %s limit %d,%d", table, (msg.Page-1)*100, 100)
			}
		}

		if err != nil {
			r.Data(200, []byte(err.Error()))
			return
		}

		info := dataInfo{
			Zone:    msg.Zone,
			Service: msg.Service,
			Page:    msg.Page,
			MaxPage: maxpage,
		}

		for _, v := range res {
			user := v.(dbUserData)
			info.Data = append(info.Data, user)
		}

		r.JSON(200, info)

	})

	m.Post("/userdata", binding.Bind(dbUserData{}), func(msg dbUserData, r render.Render) {

		table := fmt.Sprintf("tb_rank_%d", msg.Service)

		if !dbopr.IsTableExist(msg.Zone, table) {
			r.Data(200, []byte(fmt.Sprintf("zone(%s) is not exist!", table)))
			return
		}

		_, err := dbopr.ExecuteSQL(msg.Zone, &msg, "update %s set $FIELD_EQUN$ where t_sid=%d", table, msg.T_sid)
		if err != nil {
			log.Println(err)
			r.Data(200, []byte(err.Error()))
			return
		}

		if msg.T_password != "" {

			hash := md5.New()
			_, err = hash.Write([]byte(msg.T_password))
			if err != nil {
				r.JSON(200, []byte(err.Error()))
				return
			}

			msg.T_password = hex.EncodeToString(hash.Sum(nil))

			log.Println("update user password:"******"update tb_user set t_password='******' where t_sid=%d", msg.T_password, msg.T_sid)
			if err != nil {
				log.Println(err)
				r.JSON(200, []byte(err.Error()))
				return
			} else {
				r.JSON(200, msg)
				return
			}

		}

		r.JSON(200, "execute success")

	})

	m.Post("/deleteuser", binding.Bind(dbUserData{}), func(msg dbUserData, r render.Render) {

		table := fmt.Sprintf("tb_rank_%d", msg.Service)

		if !dbopr.IsTableExist(msg.Zone, table) {
			r.Data(200, []byte(fmt.Sprintf("zone(%s) is not exist!", table)))
			return
		}

		_, err := dbopr.ExecuteSQL(msg.Zone, nil, "delete from %s where t_sid=%d", table, msg.T_sid)
		if err != nil {
			log.Println(err)
			r.Data(200, []byte(err.Error()))
			return
		}

		_, err = dbopr.ExecuteSQL(msg.Zone, nil, "delete from tb_user where t_sid=%d", msg.T_sid)
		if err != nil {
			log.Println(err)
			r.Data(200, []byte(err.Error()))
			return
		}

		r.JSON(200, "execute success")

	})

}
コード例 #2
0
ファイル: icloud.go プロジェクト: chogaths/robin
func (self *oprIcloudCom) Start(peer netfw.IPeer) {

	m := peer.(martinihttp.IMartiniAcceptor).GetInterface()

	m.Get("/icloud", sessionauth.LoginRequired, func(r render.Render) {

		page := dbopr.GetRecordPageCount(dbName, "tb_td2_backup")

		r.HTML(200, "index", nil)
		r.HTML(200, "icloud", page)

	})

	m.Post("/queryicloud", binding.Bind(queryByZone{}), sessionauth.LoginRequired, func(msg queryByZone, r render.Render) {

		var res []interface{}
		var err error

		if msg.Id != 0 {
			res, err = dbopr.ExecuteSQL(dbName, &DBIcloudData{}, "select $FIELD_NAME$ from tb_td2_backup where id=%d", msg.Id)
		} else if msg.Imei != "" {
			res, err = dbopr.ExecuteSQL(dbName, &DBIcloudData{}, "select $FIELD_NAME$ from tb_td2_backup where imei='%s'", msg.Imei)
		} else if msg.Email != "" {
			res, err = dbopr.ExecuteSQL(dbName, &DBIcloudData{}, "select $FIELD_NAME$ from tb_td2_backup where email='%s'", msg.Email)
		} else {
			res, err = dbopr.ExecuteSQL(dbName, &DBIcloudData{}, "select $FIELD_NAME$ from tb_td2_backup limit %d,%d", msg.Page*dbopr.PageRecordCount, dbopr.PageRecordCount)
		}

		if err != nil {
			r.Data(200, []byte(err.Error()))
			return
		}

		r.JSON(200, res)

	})

	m.Post("/icloud", binding.Bind(DBIcloudData{}), func(msg DBIcloudData, r render.Render) {

		_, err := dbopr.ExecuteSQL(dbName, nil, "delete from tb_td2_backup where id=%d", msg.Id)
		if err != nil {
			r.Data(200, []byte(err.Error()))
			return
		}

		r.JSON(200, "execute success")

	})

	m.Post("/updateicloud", binding.Bind(DBIcloudData{}), func(msg DBIcloudData, r render.Render) {

		var err error

		if msg.Password != "" {

			hash := md5.New()
			_, err = hash.Write([]byte(msg.Password))
			if err != nil {
				r.JSON(200, map[string]string{"Result": err.Error()})
				return
			}

			msg.Password = hex.EncodeToString(hash.Sum(nil))

			_, err = dbopr.ExecuteSQL(dbName, &msg, "update tb_td2_backup set $FIELD_EQUN$ where id=%d", msg.Id)

		} else {

			_, err = dbopr.ExecuteSQL(dbName, nil, "update tb_td2_backup set remainder_restore_times=%d where id=%d", msg.Remainder_restore_times, msg.Id)

		}

		if err != nil {
			r.JSON(200, map[string]string{"Result": err.Error()})
			return
		}

		r.JSON(200, map[string]string{
			"Result":   "execute success",
			"Password": msg.Password,
		})
	})

}