//修改资源状态
func UpdateResStatus(status int, resId int) bool {
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error")
		return false
	}
	defer common.FreeDB(mydb)

	sqlStr := "update resource_tab set status=? where res_id=?"
	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
		return false
	}
	stmt, err := tx.Prepare(sqlStr)
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer stmt.Close()

	_, err = stmt.Exec(status, resId)

	if err != nil {
		fmt.Println(err)
		return false
	}
	tx.Commit()
	return true
}
Beispiel #2
0
func RegisterInsert(strACName, strPassword, strID string, nSource int, strSourceID string) (ok bool) {
	mydb := common.GetDB()
	if mydb == nil {
		return false
	}
	defer common.FreeDB(mydb)

	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
		return false
	}

	stmt, err := tx.Prepare(INSERT)
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer stmt.Close()

	_, err = stmt.Exec(strACName, strPassword, 0, strID, nSource, strSourceID)
	if err != nil {
		fmt.Println(err)
		return false
	}
	tx.Commit()
	return true
}
func register_insert(ac *Account) (ok bool) {
	mydb := common.GetDB()
	if mydb == nil {
		return false
	}
	defer common.FreeDB(mydb)

	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
		return false
	}
	stmt, err := tx.Prepare(INSERT)
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer stmt.Close()

	_, err = stmt.Exec(ac.User_Name, ac.Password, ac.Email, ac.Mobile, 0, time.Now().Unix())

	if err != nil {
		fmt.Println(err)
		return false
	}
	tx.Commit()
	return true
}
Beispiel #4
0
func DeleteUser(nACID int) (ok bool) {
	mydb := common.GetDB()
	if mydb == nil {
		return false
	}
	defer common.FreeDB(mydb)

	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
		return false
	}

	stmt, err := tx.Prepare("delete from account_tab where ac_id=?")
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer stmt.Close()

	_, err = stmt.Exec(nACID)
	if err != nil {
		fmt.Println(err)
		return false
	}
	tx.Commit()
	return true
}
Beispiel #5
0
func UpdatePassword(strAcName string, strOldPwd string, strNewPwd string) (ok bool) {
	mydb := common.GetDB()
	if mydb == nil {
		return false
	}
	defer common.FreeDB(mydb)

	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
		return false
	}
	stmt, err := tx.Prepare(" UPDATE account_tab SET ac_password=? where ac_name=?  and ac_password=? ")
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer stmt.Close()

	_, err = stmt.Exec(strNewPwd, strAcName, strOldPwd)

	if err != nil {
		fmt.Println(err)
		return false
	}
	tx.Commit()
	return true
}
//通过res_name查询资源记录
func GetResByResName(resName string) []Resource {
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error")
		return nil
	}
	defer common.FreeDB(mydb)

	sqlStr := "select res_id,app_id,res_name,res_cname,res_type,res_target,res_desc,status,create_time from resource_tab where res_name=?"
	rows, err := mydb.Query(sqlStr, resName)

	var resList []Resource = make([]Resource, 0)

	if err != nil {
		fmt.Println("query res_id failure", err)
		return nil
	} else {
		for rows.Next() {
			var res Resource
			rows.Scan(&res.Res_id, &res.App_id, &res.Res_name, &res.Res_cname, &res.Res_type, &res.Res_target, &res.Res_desc, &res.Status, &res.Create_time)
			resList = append(resList, res)
		}
	}
	return resList
}
//增加资源记录
func InsertResource(res Resource) bool {
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error")
		return false
	}
	defer common.FreeDB(mydb)

	sqlStr := "insert into resource_tab(app_id, res_name, res_cname, res_type, res_target, res_desc, status, create_time) values(?,?,?,?,?,?,?,unix_timestamp())"
	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
		return false
	}
	stmt, err := tx.Prepare(sqlStr)
	if err != nil {
		fmt.Println(err)
		return false
	}
	defer stmt.Close()

	_, err = stmt.Exec(res.App_id, res.Res_name, res.Res_cname, res.Res_type, res.Res_target, res.Res_desc, res.Status)

	if err != nil {
		fmt.Println(err)
		return false
	}
	tx.Commit()
	return true
}
func GetAcidByOpenid(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	strParams := getParams(r)
	var openvalue map[string]interface{}
	err := json.Unmarshal([]byte(strParams), &openvalue)
	var strBody []byte
	if err != nil {
		logger.Println("json data decode faild :", err)
		strBody, _ = setParams("/auth/getacid", 1, "json data decode faild!", "")
		w.Write(strBody)
		return
	}

	strOpenid, ok := openvalue["openid"].(string)
	if !ok {
		strBody, _ = setParams("/auth/getacid", 1, "params error, ac_name miss !", "")
		w.Write(strBody)
		return
	}

	mydb := common.GetDB()
	if mydb == nil {
		strBody, _ = setParams("/auth/getacid", 1, "database error!!!!", "")
		w.Write(strBody)
		return
	}
	defer common.FreeDB(mydb)

	strSQL := fmt.Sprintf("select acid from openid_tab where openid='%s'", strOpenid)
	rows, err := mydb.Query(strSQL)
	if err != nil {
		strBody, _ = setParams("/auth/getacid", 1, "database error !", "")
	} else {
		defer rows.Close()
		var nAcid int
		for rows.Next() {
			rows.Scan(&nAcid)
		}
		if nAcid == 0 {
			strBody, _ = setParams("/auth/getacid", 1, "user acid not exist!", "")
		} else {
			strData := fmt.Sprintf("{\"acid\":\"%d\"}", nAcid)
			strBody, _ = setParams("/auth/getacid", 0, "ok", strData)
		}
	}

	w.Write(strBody)
}
Beispiel #9
0
//通过app_id获取app_key
func GetAppKey(appId string) (appKey string) {
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error")
		return ""
	}
	defer common.FreeDB(mydb)

	sqlStr := "select app_key from app_info_tab where app_id=?"
	rows, err := mydb.Query(sqlStr, appId)
	if err != nil {
		fmt.Println("query openid failure", err)
		return ""
	} else {
		rows.Next()
		rows.Scan(&appKey)
		return appKey
	}
}
Beispiel #10
0
//通过res_name查询res_cname
func GetResCname(resName string) (resCname string) {
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error")
		return ""
	}
	defer common.FreeDB(mydb)

	sqlStr := "select res_cname from resource_tab where res_name=?"
	rows, err := mydb.Query(sqlStr, resName)
	if err != nil {
		fmt.Println("query res_id failure", err)
		return ""
	} else {
		rows.Next()
		rows.Scan(&resCname)
		return resCname
	}
}
Beispiel #11
0
func GetTimeStamp() (TimeStamp int) {
	strSQL := fmt.Sprintf("select unix_timestamp()")
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error3333")
		return 0
	}
	defer common.FreeDB(mydb)

	rows, err := mydb.Query(strSQL)
	if err != nil {
		return 0
	} else {
		defer rows.Close()
		if rows.Next() {
			rows.Scan(&TimeStamp)
		}
	}
	return TimeStamp

}
Beispiel #12
0
// ab -c 100 -n 1000 'http://127.0.0.1:8080/hello/tomzhao'
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	acname := r.FormValue("acname")
	password := r.FormValue("password")
	fmt.Println("acname=", acname)
	fmt.Println("password="******"name=", ps.ByName("name"))

	strSQL := "SELECT ac_name FROM account_tab"
	mydb := common.GetDB()
	defer common.FreeDB(mydb)

	rows, err := mydb.Query(strSQL)
	if err != nil {
	} else {
		defer rows.Close()
		var strAcName string
		for rows.Next() {
			rows.Scan(&strAcName)
		}
		fmt.Fprintf(w, "hello, %s at %s!!!!!!\n", strAcName, time.Now().String())
	}
}
Beispiel #13
0
func RegUserStat(start_time, end_time, source int) (count int, ok bool) {
	mydb := common.GetDB()
	if mydb == nil {
		return 0, false
	}
	defer common.FreeDB(mydb)

	strSQL := fmt.Sprintf("select count(ac_id) from account_tab where create_time>%d and create_time<=%d and  source=%d", start_time, end_time, source)
	fmt.Println(strSQL)
	rows, err := mydb.Query(strSQL)
	if err != nil {
		return 0, false
	} else {
		defer rows.Close()
		if rows.Next() {
			rows.Scan(&count)
		} else {
			return 0, false
		}
	}
	return count, true

}
Beispiel #14
0
func LoginById(ac_id int, strPassword string) (strName string, ok bool) {
	strSQL := fmt.Sprintf("select ac_name from account_tab where ac_id=%d and ac_password='******'", ac_id, strPassword)
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error 1111")
		return "", false
	}
	defer common.FreeDB(mydb)

	rows, err := mydb.Query(strSQL)
	if err != nil {
		return "", false
	} else {
		defer rows.Close()
		for rows.Next() {
			rows.Scan(&strName)
		}
		if len(strName) == 0 {
			return "", false
		}
	}
	return strName, false
}
Beispiel #15
0
func GetUserByAcId(acid int) (UserData *ATUserData, ok bool) {
	UserData = &ATUserData{}
	strSQL := fmt.Sprintf("select ac_name,ac_id,status,source,source_id,mid,create_time from account_tab where ac_id=%d ", acid)
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error2222")
		return UserData, false
	}
	defer common.FreeDB(mydb)

	rows, err := mydb.Query(strSQL)
	if err != nil {
		return UserData, false
	} else {
		defer rows.Close()
		if rows.Next() {
			rows.Scan(&UserData.Ac_name, &UserData.Ac_id, &UserData.Status, &UserData.Source, &UserData.Source_id, &UserData.Mid, &UserData.Create_time)
		} else {
			return UserData, false
		}
	}
	return UserData, true
}
//查询账户是否存在
func isFieldExist(name string, value string) bool {
	mydb := common.GetDB()
	if mydb == nil {
		return false
	}
	defer common.FreeDB(mydb)

	strSQL := fmt.Sprintf("select count(ac_name) from account_tab where %s='%s' ", name, value)
	rows, err := mydb.Query(strSQL)
	if err != nil {
		return false
	} else {
		defer rows.Close()
		var nCount int
		for rows.Next() {
			rows.Scan(&nCount)
		}

		if nCount == 0 {
			return false
		}
	}
	return true
}
Beispiel #17
0
//登录插入
func LoginQuery(strACName, strPassword string) bool {
	strSQL := fmt.Sprintf("select count(ac_name) from account_tab where ac_name='%s' and ac_password='******'", strACName, strPassword)
	mydb := common.GetDB()
	if mydb == nil {
		fmt.Println("get db connection error3333")
		return false
	}
	defer common.FreeDB(mydb)

	rows, err := mydb.Query(strSQL)
	if err != nil {
		return false
	} else {
		defer rows.Close()
		var nCount int
		for rows.Next() {
			rows.Scan(&nCount)
		}
		if nCount == 0 {
			return false
		}
	}
	return true
}
//登录插入
func login_query(login *StructLogin) (ok bool) {
	mydb := common.GetDB()
	if mydb == nil {
		return false
	}
	defer common.FreeDB(mydb)

	strSQL := fmt.Sprintf("select count(ac_name) from account_tab where (ac_name='%s' or email='%s' or mobile='%s') and ac_password='******'", login.User_Name, login.User_Name, login.User_Name, login.Password)
	rows, err := mydb.Query(strSQL)
	if err != nil {
		return false
	} else {
		defer rows.Close()
		var nCount int
		for rows.Next() {
			rows.Scan(&nCount)
		}

		if nCount == 0 {
			return false
		}
	}
	return true
}
func update_password(strAcName string, strOldPwd string, strNewPwd string) {
	mydb := common.GetDB()
	if mydb == nil {
		return
	}
	defer common.FreeDB(mydb)

	tx, err := mydb.Begin()
	if err != nil {
		fmt.Println(err)
	}
	stmt, err := tx.Prepare(" UPDATE account_tab SET ac_password=? where (ac_name=? or email=? or mobile=?) and ac_password=? ")
	if err != nil {
		fmt.Println(err)
	}
	defer stmt.Close()

	_, err = stmt.Exec(strNewPwd, strAcName, strAcName, strAcName, strOldPwd)

	if err != nil {
		fmt.Println(err)
	}
	tx.Commit()
}