コード例 #1
0
ファイル: controller.go プロジェクト: cclient/gowebframework
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)
	}
}
コード例 #2
0
ファイル: controller.go プロジェクト: cclient/gowebframework
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)
	}
}
コード例 #3
0
ファイル: controller.go プロジェクト: cclient/gowebframework
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)
}
コード例 #4
0
ファイル: controller.go プロジェクト: cclient/gowebframework
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)
	}

}
コード例 #5
0
ファイル: controller.go プロジェクト: cclient/gowebframework
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)
	}
}