示例#1
0
func (s *accountRouter) GetAccountById(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	accountid := vars["id"]
	if accountid == "" {
		return httputils.WriteError(w, accountmanager.ErrorCodeInvalidAccountId)
	}
	res, err := accountdao.GetAccountById(accountid)
	if res != nil {
		return httputils.WriteJSON(w, http.StatusOK, tool.ResponseItem{Item: res})
	} else if err == nil {
		return httputils.WriteError(w, accountmanager.ErrorCodeIdGetNULL.WithArgs(accountid))
	} else {
		return httputils.WriteError(w, err)
	}
}
示例#2
0
func (s *accountRouter) UpdateAccountInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	//不能直接接收一个json 对象,比较悲剧
	id := r.FormValue("id")
	qm := make(tool.RequestMongoKeyMap)
	kmaps := tool.KeyMaps{
		{MgoKey: "email"},
		{MgoKey: "telphone"},
		{MgoKey: "truename"},
		{MgoKey: "noticemessage"},
		{MgoKey: "noticeemail"},
	}
	kmaps.SetReqKeys()
	for _, kmap := range kmaps {
		qm.SetMgoQKey(kmap.MgoKey, r.FormValue(kmap.ReqKey))
	}
	qm.SetMgoQKeyBool("isnoticeemail", r.FormValue("isnoticeemail"), httputils.BoolValueOrDefault(r, "isnoticeemail", false))
	qm.SetMgoQKeyBool("isnoticemessage", r.FormValue("isnoticemessage"), httputils.BoolValueOrDefault(r, "isnoticemessage", false))
	qm.SetMgoQKeyValue("roles", getRoles(r))
	fmt.Println(qm.ParseUpdateToMongoSet())
	res, err := accountmanager.UpdateAccountById(id, qm.ParseUpdateToMongoSet())
	fmt.Println(res, err)
	if err == nil && res == true {
		operaaccount, _ := accountdao.GetAccountById(r.FormValue("accountid"))
		operalogdao.InsertAccountOperalog(operaaccount, operalogmodel.AccountUpdate, id, qm.ParseUpdateToMongoSet())
		return httputils.WriteSuccess(w, http.StatusOK)
	} else {
		return httputils.WriteError(w, accountmanager.ErrorCodeUpdateFAILD)
	}
}
示例#3
0
func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// log the handler call
		logrus.Debugf("Calling %s %s", r.Method, r.URL.Path)

		// Define the context that we'll pass around to share info
		// like the docker-request-id.
		//
		// The 'context' will be used for global data that should
		// apply to all requests. Data that is specific to the
		// immediate function being called should still be passed
		// as 'args' on the function call.
		ctx := context.Background()
		handlerFunc := s.handleWithGlobalMiddlewares(handler)

		vars := mux.Vars(r)
		if vars == nil {
			vars = make(map[string]string)
		}

		if err := handlerFunc(ctx, w, r, vars); err != nil {
			logrus.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL.Path, utils.GetErrorMessage(err))
			httputils.WriteError(w, err)
		}
	}
}
示例#4
0
func (s *accountRouter) GetAccountsPage(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	meta := httputils.GetPagination(r)
	qm := make(tool.RequestMongoKeyMap)
	qm.SetMgoQKey("truename", r.FormValue("truename"))
	qm.SetMgoQKey("email", r.FormValue("email"))
	qm.SetMgoQKey("name", r.FormValue("name"))
	qm.SetMgoQKey("telphone", r.FormValue("telphone"))
	accountid := r.FormValue("accountid")
	account, err := accountdao.GetAccountById(accountid)
	fmt.Println(account, err)
	manageraccountids := []bson.ObjectId{}
	if err != nil {
		return httputils.WriteError(w, errors.ErrorCodeOther.WithArgs(err.Error()))
	}
	if account.IsSuperAdmin == false {
		ajrs, _ := accountmanager.GetAccountJustRoles(nil, 0, 0)
		for _, ajr := range ajrs {
			for _, role := range ajr.Roles {
				str := role.ToPCAString()
				if CheckHasPermi(str, account.Roles) == true {
					fmt.Println(str)
					manageraccountids = append(manageraccountids, ajr.Id)
					break
				}
			}
		}
		qm.SetInMgoIdArray("_id", manageraccountids)
	}
	res, err := accountmanager.GetAccountsPage(meta, qm.ParseRequestToMongoQuery())
	if res != nil {
		return httputils.WriteJSON(w, http.StatusOK, res)
	} else if err == nil {
		return httputils.WriteError(w, errors.ErrorCodeOther.WithArgs(err.Error()))
	} else {
		return httputils.WriteError(w, err)
	}
}
示例#5
0
func (s *accountRouter) RemoveAccountById(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	id := vars["id"]
	if id == "" {
		id = r.FormValue("id")
	}
	res, err := accountmanager.RemoveAccountById(id)
	fmt.Println(err)
	if err == nil && res == true {
		operaaccount, _ := accountdao.GetAccountById(r.FormValue("accountid"))
		operalogdao.InsertAccountOperalog(operaaccount, operalogmodel.AccountDel, id, nil)
		return httputils.WriteSuccess(w, http.StatusOK)
	}
	return httputils.WriteError(w, accountmanager.ErrorCodeRemoveFAILD)
}
示例#6
0
func (s *accountRouter) getAccountManagePCA(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	//查询场所条件
	qm := make(tool.RequestMongoKeyMap)
	issa, shopids, err := accountmanager.GetAccountManageShopIdsByAccountId(r.FormValue("accountid"))
	if err != nil {
		return httputils.WriteJSON(w, http.StatusOK, errors.ErrorCodeOther.WithArgs("get manager shop error"))
	} else {
		if issa != true {
			if shopids != nil && len(shopids) > 0 {
				qm.SetInStringArray("_id", shopids)
			} else {
				return httputils.WriteJSON(w, http.StatusOK, errors.ErrorCodeOther.WithArgs("get manager shop error"))
			}
		}
	}
	res, err := accountmanager.GetAccountManageShopSimplesPCA(qm.ParseRequestToMongoQuery())
	pcasmap := map[string]int{}
	rolecount := 0
	for _, shop := range res {
		arr := make([]string, 3)
		arr[0] = shop.Province
		arr[1] = shop.City
		arr[2] = shop.Area
		if shop.Province != "" {
			pcastr := strings.Join(arr, ",")
			if pcasmap[pcastr] != 1 {
				pcasmap[strings.Join(arr, ",")] = 1
				rolecount++
			}
		}
	}
	roles := make([]accountmodel.Role, rolecount)
	pcaarr := make([]string, 3)
	roleiter := 0
	for key, _ := range pcasmap {
		pcaarr = strings.Split(key, ",")
		roles[roleiter] = accountmodel.Role{Province: pcaarr[0], City: pcaarr[1], Area: pcaarr[2]}
		roleiter++
	}
	if res != nil {
		return httputils.WriteJSON(w, http.StatusOK, tool.ResponsePage{List: roles})
	} else if err != nil {
		return httputils.WriteError(w, errors.ErrorCodeOther.WithArgs(err.Error()))
	} else {
		return httputils.WriteJSON(w, http.StatusOK, tool.ResponsePage{List: nil})
	}
}
示例#7
0
func (s *accountRouter) InsertAccount(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	account := accountmodel.Account{}
	decoder := schema.NewDecoder()
	err := decoder.Decode(&account, r.Form)
	account.Roles = getRoles(r)
	account.Id = tool.CreateMgoId()
	fmt.Println(account.PasswdNew)
	account.PasswdNew = fmt.Sprintf("%x", md5.Sum([]byte(account.PasswdNew)))
	err = accountmanager.InsertAccount(account)
	if err == nil {
		operaaccount, _ := accountdao.GetAccountById(r.FormValue("accountid"))
		operalogdao.InsertAccountOperalog(operaaccount, operalogmodel.AccountAdd, nil, account)
		return httputils.WriteSuccess(w, http.StatusOK)
	} else {
		return httputils.WriteError(w, accountmanager.ErrorCodeUpdateFAILD)
	}

}