Example #1
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)
	}
}
Example #2
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)
}
Example #3
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)
	}

}