當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CustomerUser.CustomerID方法代碼示例

本文整理匯總了Golang中github.com/ninnemana/API/models/customer.CustomerUser.CustomerID方法的典型用法代碼示例。如果您正苦於以下問題:Golang CustomerUser.CustomerID方法的具體用法?Golang CustomerUser.CustomerID怎麽用?Golang CustomerUser.CustomerID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ninnemana/API/models/customer.CustomerUser的用法示例。


在下文中一共展示了CustomerUser.CustomerID方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RegisterUser

//registers an inactive user; emails user and webdev that a new inactive user exists - used by dealers site
func RegisterUser(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder) string {
	var err error

	name := r.FormValue("name")
	email := r.FormValue("email")
	pass := r.FormValue("pass")
	customerID, err := strconv.Atoi(r.FormValue("customerID"))
	// isActive, err := strconv.ParseBool(r.FormValue("isActive"))
	locationID, err := strconv.Atoi(r.FormValue("locationID"))
	// isSudo, err := strconv.ParseBool(r.FormValue("isSudo"))
	cust_ID, err := strconv.Atoi(r.FormValue("cust_ID"))
	notCustomer, err := strconv.ParseBool(r.FormValue("notCustomer"))

	if email == "" || pass == "" {
		err = errors.New("Email and password are required.")
		apierror.GenerateError("Email and password are required", err, rw, r)
		return ""
	}

	var user customer.CustomerUser
	user.Email = email
	user.Password = pass
	if name != "" {
		user.Name = name
	}
	if customerID != 0 {
		user.OldCustomerID = customerID
	}
	if locationID != 0 {
		user.Location.Id = locationID
	}
	if cust_ID != 0 {
		user.CustomerID = cust_ID
	}
	user.Active = false
	user.Sudo = false
	user.Current = notCustomer

	//check for existence of user
	err = user.FindByEmail()
	if err == nil {
		apierror.GenerateError("A user with that email address already exists.", err, rw, r)
		return ""
	}
	err = nil

	user.Brands, err = brand.GetUserBrands(cust_ID)
	if err != nil {
		apierror.GenerateError("Trouble getting user brands.", err, rw, r)
		return ""
	}
	var brandIds []int
	for _, brand := range user.Brands {
		brandIds = append(brandIds, brand.ID)
	}

	if err = user.Create(brandIds); err != nil {
		apierror.GenerateError("Trouble registering new customer user", err, rw, r)
		return ""
	}

	//email
	if err = user.SendRegistrationEmail(); err != nil {
		apierror.GenerateError("Trouble emailing new customer user", err, rw, r)
		return ""
	}

	if err = user.SendRegistrationRequestEmail(); err != nil {
		apierror.GenerateError("Trouble emailing webdevelopment regarding new customer user", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode(user))
}
開發者ID:ninnemana,項目名稱:API,代碼行數:75,代碼來源:user.go


注:本文中的github.com/ninnemana/API/models/customer.CustomerUser.CustomerID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。