Exemple #1
0
func MultiRegister(Info *map[string]string) (InfoResult UserInfoResult, code int) {
	session := common.GetSession()
	if session == nil {
		return InfoResult, 1
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("user_tab")
	User, OK := isUserExist_m(Info)
	if OK {
		InfoResult.Id = User.Id.Hex()
		return InfoResult, USER_EX
	}

	var UserInfo ATUserInfo
	UserInfo.Ac_id = -1
	UserInfo.Info = *Info
	UserInfo.Id = bson.NewObjectId()
	UserInfo.Create_time = GetTimeStamp()
	InfoResult.Info = *Info
	InfoResult.Id = UserInfo.Id.Hex()
	err := coll.Insert(&UserInfo)
	if err != nil {
		return InfoResult, INSERT_DB_ERROR
	}
	return InfoResult, 0
}
func GetUserInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	user_name := r.FormValue("user_name")
	token := r.FormValue("token")
	fmt.Println("user_name=", user_name)
	fmt.Println("token=", token)

	strCheckURL := "https://connect.funzhou.cn/oauth2/privilige"
	strInterface := "get_user_info"

	value := url.Values{}
	value.Set("token", token)
	value.Set("privilige", strInterface)
	strBody, err := common.Invoker(common.HTTP_POST, strCheckURL, value)
	if err != nil {
		fmt.Println(err)
		strBody, _ := setParams("/auth/get_user_info", 1, "submit check  faild !", "")
		w.Write(strBody)
		return
	}
	fmt.Println(strBody)

	var result AUResponse
	err = json.Unmarshal([]byte(strBody), &result)
	if err != nil {
		strBody, _ := setParams("/auth/get_user_info", 1, "json data decode faild!", "")
		w.Write(strBody)
		return
	}

	if result.Code != 0 {
		strBody, _ := setParams("/auth/get_user_info", 1, "user check faild beacuse of "+result.Message, "")
		w.Write(strBody)
		return
	}

	session := common.GetSession()
	if session == nil {
		strBody, _ := setParams("/auth/get_user_info", 1, "get DB faild !!", "")
		w.Write(strBody)
		return
	}
	defer common.FreeSession(session)

	user_info := Account{}
	coll := session.DB("at_db").C("user_tab")

	condition_or := bson.M{"$or": []bson.M{bson.M{"user_name": user_name}, bson.M{"email": user_name}, bson.M{"mobile": user_name}}}
	coll.Find(condition_or).Sort(user_name).One(&user_info)

	strResult, err := json.Marshal(user_info)
	if err != nil {
		strBody, _ := setParams("/auth/get_user_info", 1, "json data encode faild!", "")
		w.Write(strBody)
		return
	}

	strResult, _ = setParams("/auth/get_user_info", 0, "ok", string(strResult))
	w.Write(strResult)
	return
}
Exemple #3
0
func InsertUserInfo(UserInfo *ATUserInfo) (ok bool) {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("user_tab")
	err := coll.Insert(UserInfo)
	if err != nil {
		return false
	}
	return true
}
func register_insert_m(ac *Account) (ok bool) {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("user_tab")
	err := coll.Insert(ac)
	if err != nil {
		return false
	}
	return true
}
Exemple #5
0
func RemoveUserLocus(mid, mid_c string) (ok bool) {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("locus_tab")
	err := coll.Remove(bson.M{"mid": mid, "mid_c": mid_c})
	if err == nil {
		return true
	}
	fmt.Println(err)
	return false
}
Exemple #6
0
func isUserExistL(name, value, show_id string) (Locus UserJoinLocus, ok bool) {
	session := common.GetSession()
	if session == nil {
		return Locus, false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("locus_tab")
	err := coll.Find(&bson.M{name: value, "show_id": show_id}).Sort("mid").One(&Locus)
	if err == nil {
		return Locus, true
	}
	fmt.Println(err)
	return Locus, false
}
Exemple #7
0
func GetUserLocus(Mid, Mid_c, show_id string) (Locus UserJoinLocus, ok bool) {
	session := common.GetSession()
	if session == nil {
		return Locus, false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("locus_tab")
	err := coll.Find(&bson.M{"mid": Mid, "mid_c": Mid_c, "show_id": show_id}).Sort(Mid).One(&Locus)
	if err == nil {
		return Locus, true
	}
	fmt.Println(err)
	return Locus, false
}
Exemple #8
0
func RemoveUser(Id bson.ObjectId) (ok bool) {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("user_tab")
	err := coll.RemoveId(Id)
	if err == nil {
		return true
	}
	fmt.Println(err)
	return false
}
func update_password_m(strAcName string, strNewPwd string) bool {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("user_tab")
	// No changes is a no-op and shouldn't return an error.
	condition_or := bson.M{"$or": []bson.M{bson.M{"user_name": strAcName}, bson.M{"email": strAcName}, bson.M{"mobile": strAcName}}}
	err := coll.Update(condition_or, bson.M{"$set": bson.M{"password": strNewPwd}})
	if err == nil {
		return true
	}
	return false
}
Exemple #10
0
func GetUserInfoL(id string) (Locus UserJoinLocus, ok bool) {
	session := common.GetSession()
	if session == nil {
		return Locus, false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("locus_tab")
	fmt.Println("id=", id)
	err := coll.Find(&bson.M{"mid_c": id}).One(&Locus)
	if err == nil {
		return Locus, true
	}
	fmt.Println(err)
	return Locus, false
}
Exemple #11
0
func GetUserInfoM(id string) (UserInfo ATUserInfo, ok bool) {
	session := common.GetSession()
	if session == nil {
		return UserInfo, false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("user_tab")
	fmt.Println("id=", id)
	err := coll.Find(&bson.M{"_id": bson.ObjectIdHex(id)}).One(&UserInfo)
	if err == nil {
		return UserInfo, true
	}
	fmt.Println(err)
	return UserInfo, false
}
Exemple #12
0
func InitOnlyCheckList() (ok bool) {
	Mu.Lock()
	defer Mu.Unlock()
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("dictionary_tab")
	err := coll.Find(bson.M{"name": "check_list"}).One(&OnlyCheckList)
	if err != nil {
		return false
	}

	return true
}
//查询账户是否存在
func isFieldExist_m(name string, value string) bool {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	result := []Account{}
	coll := session.DB("at_db").C("user_tab")

	coll.Find(&bson.M{name: value}).Sort(name).All(&result)
	if len(result) == 0 {
		return false
	}

	return true
}
Exemple #14
0
func isUserExist(name, value string) (UserInfo *ATUserInfo, ok bool) {
	session := common.GetSession()
	if session == nil {
		return nil, false
	}
	defer common.FreeSession(session)

	result := ATUserInfo{}
	coll := session.DB("at_db").C("user_tab")

	err := coll.Find(&bson.M{name: value}).Sort(name).One(&result)
	if err != nil {
		return nil, false
	}

	return &result, true
}
Exemple #15
0
func isUserExist_m(Info *map[string]string) (UserInfo *ATUserInfo, ok bool) {

	FieldList := GetCheckList()
	var strTemp string
	nCount := 0
	for k, v := range *Info {
		if len(v) == 0 {
			continue
		}

		if in_array(strings.ToLower(k), FieldList) {
			nCount++
		}
	}

	condition := make([]bson.M, nCount)
	nCount = 0
	strNode := ""
	for i := 0; i < len(FieldList); i++ {
		strTemp = strings.ToLower(FieldList[i])
		if len((*Info)[strTemp]) > 0 {
			strNode = "info." + strTemp
			condition[nCount] = bson.M{strNode: (*Info)[strTemp]}
			nCount++
		}
	}

	condition_or := bson.M{"$or": condition}
	session := common.GetSession()
	if session == nil {
		return nil, false
	}
	defer common.FreeSession(session)

	result := ATUserInfo{}
	coll := session.DB("at_db").C("user_tab")
	err := coll.Find(condition_or).Sort("ac_id").One(&result)
	if err != nil {
		return nil, false
	}

	return &result, true
}
Exemple #16
0
func SetOnlyCheckList(Fieldes []string) (ok bool) {
	Mu.Lock()
	defer Mu.Unlock()
	OnlyCheckList.List = Fieldes
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	strName := "check_list"
	coll := session.DB("at_db").C("dictionary_tab")
	coll.Remove(bson.M{"name": strName})
	err := coll.Insert(OnlyCheckList)
	if err != nil {
		fmt.Println("SetOnlyCheckList:", err)
		return false
	}
	return true
}
//登录插入
func login_query_m(strUser_Name, strPassword string) (ok bool) {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	result := []Account{}
	coll := session.DB("at_db").C("user_tab")

	condition_or := bson.M{"$or": []bson.M{bson.M{"user_name": strUser_Name}, bson.M{"email": strUser_Name}, bson.M{"mobile": strUser_Name}}}
	coll.Find(condition_or).Sort(strUser_Name).All(&result)
	// 显示数据
	for _, m := range result {
		if m.Password == strPassword {
			return true
		}
	}

	return false
}
Exemple #18
0
func SetUserLocus(Mid string, Mid_c string, show_id string, Info *map[string]string) (ok bool, UserLocus UserJoinLocus) {
	UserLocus, OK := GetUserLocus(Mid, Mid_c, show_id)

	session := common.GetSession()
	if session == nil {
		return true, UserLocus
	}
	defer common.FreeSession(session)

	coll := session.DB("at_db").C("locus_tab")
	if OK {
		for k, v := range *Info {
			UserLocus.Info[k] = v
		}
		condition := bson.M{"mid": Mid, "mid_c": Mid_c, "show_id": show_id}
		err := coll.Update(condition, bson.M{"$set": bson.M{"info": UserLocus.Info}})
		if err == nil {
			return true, UserLocus
		}
		return false, UserLocus
	}

	UserLocus.Info = *Info
	UserLocus.Id = bson.NewObjectId()
	UserLocus.Create_time = GetTimeStamp()
	UserLocus.Info = *Info
	UserLocus.Mid = Mid
	UserLocus.Mid_c = Mid_c
	UserLocus.Show_id = show_id

	err := coll.Insert(&UserLocus)
	if err != nil {
		return false, UserLocus
	}
	return true, UserLocus
}
Exemple #19
0
func ExportMongo(start_time, end_time int) (count int, ok bool) {
	session := common.GetSession()
	if session == nil {
		return 0, false
	}
	defer common.FreeSession(session)

	result := []ATUserInfo{}
	coll := session.DB("at_db").C("user_tab")
	//conditions := make([]bson.M, 2)

	condition := bson.M{"info.name": bson.M{"$exists": true}}
	//conditions[0]=bson.M{"info.name": bson.M{"$exists": true}}
	//conditions[1]=bson.M{"create_time":bson.M{"$gte":start_time,"$lte":end_time}}
	err := coll.Find(condition).Sort("create_time").All(&result)
	if err != nil {
		fmt.Println(err)
		return 0, false
	}

	nCount := 0
	for i := 0; i < len(result); i++ {

		/*
			//delete from mongodb
			conditions :=bson.M{"info.phone":result[i].Info["phone"]}
			err = coll.Remove(conditions)
			if err!=nil {
				fmt.Println(err)
				return 0,false;
			}

			//delete from mysql
			if result[i].Ac_id>0 {
				DeleteUser(result[i].Ac_id)
			}
		*/
		if result[i].Create_time > start_time && result[i].Create_time < end_time {
			nCount++
		}
		fmt.Println(result[i].Id.Hex(), ";", result[i].Info["name"])
		//fmt.Println(result[i].Info)
	}
	return nCount, true
	/*
		//err:=coll.Find(&bson.M{"create_time":{"$gte":start_time,"$lte":end_time}}).Sort("create_time").All(&result)
		//err:=coll.Find(&bson.M{"create_time":bson.M{"$gte":start_time,"$lte":end_time}}).Sort("create_time").All(&result)
		condition := make([]bson.M, 6)
		condition[0]=bson.M{"info.user_type":"10"}
		condition[1]=bson.M{"info.user_type":"20"}
		condition[2]=bson.M{"info.user_type":"30"}
		condition[3]=bson.M{"info.user_type":"40"}
		condition[4]=bson.M{"info.user_type":"50"}
		condition[5]=bson.M{"info.user_type":"60"}
		//condition[6]=bson.M{"create_time":0}
		fmt.Println("start_time=",start_time,"end_time=",end_time)
		err:=coll.Find(&bson.M{"$or":condition}).Sort("create_time").All(&result)
		//err:=coll.Find(&bson.M{"create_time":bson.M{"$gte":start_time,"$lte":end_time}}).Sort("create_time").All(&result)
		if err!=nil {
			fmt.Println(err)
			return 0,false;
		}

		for i := 0; i < len(result); i++ {

			if result[i].Create_time==0  && result[i].Info["user_name"]!="" {
				strText:=fmt.Sprintf("%s,%s,%s,%s,%s",result[i].Id.Hex(),result[i].Info["user_name"],result[i].Info["company_name"],
					result[i].Info["job"],result[i].Info["mobile"])
				strText=strings.Trim(strText,"\n")
				strText=strings.Trim(strText,"\r")
				fmt.Println(strText)
				count++
			}
		}

		return count,true
	*/
}
Exemple #20
0
func UpdateUserInfo(UserInfo *ATUserInfo, show_id string) (ok bool) {
	session := common.GetSession()
	if session == nil {
		return false
	}
	defer common.FreeSession(session)

	if UserInfo.Ac_id > 0 {
		old_info, ok := isUserExist_i("ac_id", UserInfo.Ac_id)
		coll := session.DB("at_db").C("user_tab")
		if ok {
			for k, v := range UserInfo.Info {
				old_info.Info[k] = v
			}
			condition := bson.M{"ac_id": UserInfo.Ac_id}
			err := coll.Update(condition, bson.M{"$set": bson.M{"info": old_info.Info}})
			if err == nil {
				return true
			}
		}
		return false
	}

	User, OK := isUserExist_m(&UserInfo.Info)
	if OK {
		var Id bson.ObjectId
		if UserInfo.Id == User.Id {
			Id = UserInfo.Id
		} else {
			Id = User.Id
		}

		old_info, ok := GetUserInfoM(Id.Hex())
		coll := session.DB("at_db").C("user_tab")
		if ok {
			for k, v := range UserInfo.Info {
				old_info.Info[k] = v
			}
			condition := &bson.M{"_id": Id}
			err := coll.Update(condition, bson.M{"$set": bson.M{"info": old_info.Info}})
			if err != nil {
				return false
			}
		}

		if UserInfo.Id == User.Id {
			SetUserLocus(Id.Hex(), Id.Hex(), show_id, &UserInfo.Info)
		} else {
			RemoveUser(UserInfo.Id)
			RemoveUserLocus(UserInfo.Id.Hex(), UserInfo.Id.Hex())
			SetUserLocus(Id.Hex(), UserInfo.Id.Hex(), show_id, &UserInfo.Info)
		}
	} else {
		Locus, ok := GetUserInfoL(UserInfo.Id.Hex())
		if !ok {
			return false
		}
		old_info, ok := GetUserInfoM(Locus.Mid)
		coll := session.DB("at_db").C("user_tab")
		if ok {
			for k, v := range UserInfo.Info {
				old_info.Info[k] = v
			}
			condition := &bson.M{"_id": bson.ObjectIdHex(Locus.Mid)}
			err := coll.Update(condition, bson.M{"$set": bson.M{"info": old_info.Info}})
			if err != nil {
				return false
			}
			SetUserLocus(Locus.Mid, Locus.Mid_c, show_id, &UserInfo.Info)
		} else {
			return false
		}
	}

	return true
}