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


Golang models.User類代碼示例

本文整理匯總了Golang中ibookings/models.User的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: Skills

/**
 * 特長項新增修改
 */
func (this *UserController) Skills() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	userId := r.FormValue("user")
	category := r.FormValue("category")
	subCategory := r.FormValue("subCategory")
	experience := r.FormValue("experience")
	price := r.FormValue("price")
	item := r.FormValue("item")
	title := r.FormValue("title")

	user := m.User{Id: userId}
	skill := make([]m.Skill, 1) //普通用戶默認隻有一個技能項
	data := e.Data{Msg: "保存成功", Status: 1}
	skill[0].Id = userId + "1"
	skill[0].Category = m.Category{category, subCategory, item}
	skill[0].Title = title

	skill[0].Experience, _ = strconv.Atoi(experience)
	skill[0].Price, _ = strconv.ParseFloat(price, 1000)
	skill[0].UserId = userId
	skill[0].InsertOrUpdateSkillsById()
	user.Skill = skill
	user.UpdateSkillById()
	u.OutputJson(w, &data)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:30,代碼來源:User.go

示例2: Edit

func (this *UserController) Edit() {
	w := this.ResponseWriter
	r := this.Request
	data := e.TData{}

	common := CommonController{HTTP: this.HTTP}

	t := common.getTpl("User.edit.introduction.tpl", "User.edit.tpl", "User.edit.avatar.tpl", "User.edit.baseinfo.tpl", "User.edit.skills.tpl", "User.edit.skill.tpl", "User.edit.introduction.tpl")

	r.ParseForm()
	userId := r.FormValue("id")
	user := m.User{Id: userId}

	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()

	flag := true
	if cookie.UserId == nil || userId != cookie.UserId.Value { //無登錄cookie
		flag = false
	}
	if flag {
		user = user.GetOneUserById()
		data.CurrentUser = user
		data.Data = user
		data.Flag = flag
		t.Execute(w, &data)
	} else {
		Error{HTTP: this.HTTP}.Get()
	}

}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:31,代碼來源:User.go

示例3: Post

func (this *LoginController) Post() {
	r := this.Request
	w := this.ResponseWriter
	data := e.Data{}
	r.ParseForm()
	username := r.FormValue("username")
	password := r.FormValue("password")
	//remomberme := r.FormValue("remember")
	vercode := r.FormValue("vercode")

	cookie, _ := r.Cookie("gsid")
	if cookie != nil { //如果cookie為空

		key := cookie.Value + "Img"
		captchaS := u.Session[key]
		log.Println("獲得session中得驗證碼", captchaS)
		if captchaS == vercode {
			delete(u.Session, key)
			data.Status = 1
			data.Msg = ""
			//http.Redirect(w, r, "/", http.StatusSeeOther)
		} else {
			data.Status = 0
			data.Msg = "驗證碼錯誤"
		}
		user := m.User{UserName: username, PassWord: password}
		log.Println("用戶表單數據:", user.UserName, user.PassWord)

		//user.InsertOneUserById(user)
		userDetail := user.GetUserDetil(user)
		log.Println(userDetail)
		if userDetail.UserName == "" {
			data.Status = 0
			data.Msg = "用戶名或密碼錯誤"
		}
		//登錄成功設置成功標誌位
		if data.Msg == "" {
			// usernameCookie := http.Cookie{Name: "username", Value: userDetail.UserName}
			// usernameCookie.Expires = time.Now().AddDate(0, 3, 0)
			// http.SetCookie(w, &usernameCookie)
			idCookie := http.Cookie{Name: "userid", Value: userDetail.Id, Path: "/"}
			idCookie.Expires = time.Now().AddDate(0, 3, 0)
			log.Println("設置登錄cookie", idCookie)
			http.SetCookie(w, &idCookie)

		}
	} else {
		data.Status = 0
		data.Msg = "非法訪問!"
	}
	u.OutputJson(w, &data)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:52,代碼來源:Login.go

示例4: Introduction

func (this *UserController) Introduction() {
	data := e.Data{Msg: "保存成功", Status: 1}
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	id := r.FormValue("id")
	introduction := r.FormValue("data")
	introduction = strings.Replace(introduction, "##", ";", -1)
	user := m.User{Id: id, Introduction: introduction}
	log.Println("user", user)
	user.UpdateIntroductionById()
	u.OutputJson(w, &data)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:13,代碼來源:User.go

示例5: Get

func (main *MainController) Get(w http.ResponseWriter, r *http.Request) {
	t, err := t.ParseFiles("views/T.main.tpl", "views/T.navbar.tpl", "views/T.foot.tpl")
	if err != nil {
		log.Println(err)
	}

	cookie, _ := r.Cookie("username")
	user := m.User{}
	if cookie != nil {
		user.UserName = cookie.Value
	}
	t.Execute(w, &user)

}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:14,代碼來源:main.go

示例6: Info

func (this *AccountController) Info() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	parId := r.FormValue("id")

	common := CommonController{HTTP: this.HTTP}

	t := common.getTpl("account", "Account.info.tpl")

	showuser := m.User{Id: parId}
	data := e.TData{}
	flag := false

	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	// log.Println("獲取cookie中的用戶名")
	// username := u.GetCookieUserName(w, r)
	// if username != "" { //如果已經登錄了
	// 	user = user.GetOneUserByName(username)
	// } else {

	// }

	log.Println(parId)
	if parId == "" {
		log.Println("url有錯誤")
	}
	showuser = showuser.GetOneUserById()
	loginuser := m.User{}
	log.Println(showuser.ABalance, showuser.FBalance)
	userId := cookie.UserId //登錄用戶

	log.Println(showuser.RealName)
	if showuser.RealName != "" { //查到用戶
		if userId != nil { //查到有登錄用戶
			loginuser.Id = userId.Value
			flag = true
			if showuser.Id == loginuser.Id { //自己瀏覽自己
				data = e.TData{Data: showuser, CurrentUser: loginuser, Flag: flag}
				t.Execute(w, &data)
			}
		}

	}
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:46,代碼來源:Account.go

示例7: ShowPage

func (this *CommonController) ShowPage(choose string, views ...string) {
	wr := this.ResponseWriter

	t := u.ParesFiles(views...)

	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	user := m.User{}
	flag := false
	log.Println("登錄cookie獲取", cookie)
	if cookie.UserId != nil {
		user.Id = cookie.UserId.Value
		flag = true
	}
	var data e.TData = e.TData{CurrentUser: user, Flag: flag, Selected: choose}
	log.Println("data", data)
	t.Execute(wr, &data)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:18,代碼來源:Common.go

示例8: Cash

func (this *AccountController) Cash() {
	data := e.Data{Msg: "申請成功", Status: 1}
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	userId := r.FormValue("user")
	money, _ := strconv.ParseFloat(r.FormValue("cash"), 32)
	user := m.User{Id: userId}
	user = user.GetOneUserById()
	if user.RealName == "" { //無開戶人姓名
		data.Status = 0
		data.Msg = "真實姓名為空,請先設置真實姓名"
	}
	if data.Status == 1 && user.ABalance < money {
		data.Status = 0
		data.Msg = "提取金額有誤"
	}
	if data.Status == 1 {
		username := user.RealName
		bank := r.FormValue("bank")

		card := r.FormValue("card")
		address := r.FormValue("address")
		cash := m.Cash{Id: this.getCashId(userId), UserId: userId, UserName: username, Bank: bank, Card: card, Address: address, Money: money, BeginTime: time.Now(), Status: "申請"}
		cash.InsertCash()
		user.ABalance = user.ABalance - money
		user.UpdateABalance()
	}
	u.OutputJson(w, &data)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:30,代碼來源:Account.go

示例9: Q

func (this *UserController) Q() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	parId := r.FormValue("id")

	common := CommonController{HTTP: this.HTTP}

	t := common.getTpl("UserDetail", "T.user.tpl", "Order.add.tpl")

	showuser := m.User{Id: parId}
	data := e.TData{}
	flag := false
	isCurrentUser := false
	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	// log.Println("獲取cookie中的用戶名")
	// username := u.GetCookieUserName(w, r)
	// if username != "" { //如果已經登錄了
	// 	user = user.GetOneUserByName(username)
	// } else {

	// }

	log.Println(parId)
	if parId == "" {
		log.Println("url有錯誤")
	}
	showuser = showuser.GetOneUserById()
	loginuser := m.User{}
	userId := cookie.UserId //登錄用戶

	log.Println(showuser.RealName)
	if showuser.RealName != "" { //查到用戶
		if userId != nil { //查到有登錄用戶
			loginuser.Id = userId.Value
			flag = true
			if showuser.Id == loginuser.Id { //已登錄的用戶瀏覽別人的資料
				isCurrentUser = true
			}
		}
		if !isCurrentUser { //別人瀏覽
			telph := u.SubString(showuser.UserName, 0, len(showuser.UserName)-4) + "****"
			idCard := u.SubString(showuser.IDCard, 0, len(showuser.IDCard)-4) + "****"
			showuser.UserName = telph
			showuser.IDCard = idCard
		}

		data = e.TData{Data: showuser, CurrentUser: loginuser, Flag: flag}

		t.Execute(w, &data)
	}

}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:54,代碼來源:User.go

示例10: Post

func (this *SignupController) Post() {
	w := this.ResponseWriter
	r := this.Request
	user := m.User{}
	data := e.Data{Msg: "注冊成功", Status: 1}
	r.ParseForm()
	userName := r.FormValue("username")
	passWord1 := r.FormValue("password1")
	passWord2 := r.FormValue("password2")
	reg := regexp.MustCompile(mobile)
	pleng := len(passWord1)
	if userName == "" {
		data.Status = 0
		data.Msg = "用戶名不能為空"
	}

	if data.Status != 0 && !reg.MatchString(userName) {
		data.Status = 0
		data.Msg = "手機號碼格式錯誤"
	}
	if data.Status != 0 && passWord1 == "" {
		data.Status = 0
		data.Msg = "密碼不能為空"
	}

	if data.Status != 0 && (pleng < 6 || pleng > 12) {
		data.Status = 0
		data.Msg = "密碼為6-12位字母或者數字組合"
	}

	if data.Status != 0 && passWord2 == "" {
		data.Status = 0
		data.Msg = "確認密碼不能為空"
	}
	if data.Status != 0 && passWord1 != passWord2 { //後端驗證兩次密碼不一致
		data.Status = 0
		data.Msg = "兩次密碼不一致!"
	}

	log.Println(template.HTMLEscapeString(passWord1))
	if data.Status != 0 {
		user.UserName = userName
		user.TelPhone = userName
		user.PassWord = passWord2
		/*新增用戶*/
		user, err := user.InsertUser()
		if err != nil {
			data.Status = 0
			data.Msg = "用戶注冊出錯"
			data.Data = err.Error()
		} else {
			data.Data = user
		}
	}
	u.OutputJson(w, &data)
	// user.Id = "9527"
	// user.RealName = "張力"
	// user.IDCard = "5002351991000000"
	// user.UserName = "15520010009"
	// user.Area = "重慶"

	// honours := make([]m.Honours, 1, 5)
	// h1 := m.Honours{"實名認證用戶", "card"}

	// h2 := m.Honours{"會員", "vip"}
	// honours[0] = h1
	// honours = append(honours, h2)
	// user.Honours = honours
	// log.Println(cap(honours))

	// skills := make([]m.Skill, 2, 10)
	// skills[0].Category = "運動"
	// skills[0].Item = "遊泳"
	// skills[0].Price = 50.00
	// skills[0].Bid = 0.00
	// skills[0].Experience = 2
	// skills[0].Sales = 90
	// skills[0].Title = "重慶市渝北區遊泳館高級遊泳教練"
	// skills[0].Area = "重慶 雲陽"
	// skills[0].UserId = "9530"

	// skills[1].Category = "電竟"
	// skills[1].Item = "LOL"
	// skills[1].Price = 10.00
	// skills[1].Bid = 0.00
	// skills[1].Experience = 3
	// skills[1].Sales = 1000
	// skills[1].Title = "英雄聯盟LOL巨神峰白銀高級帶練"
	// skills[0].Area = "重慶 渝北"
	// skills[0].UserId = "9530"

	// skills[0].InsertSkills(skills)

	// user.Skill = skills
	// user.Introduction = "我就是愛音樂別讓我停下來"
	// user.InsertUser(user)

	//log.Println(user)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:99,代碼來源:Signup.go

示例11: Info

func (this *UserController) Info() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	user := m.User{}
	data := e.Data{Msg: "保存成功", Status: 1}

	id := r.FormValue("id")
	realName := r.FormValue("realName")
	idCard := r.FormValue("idCard")
	age := r.FormValue("age")
	sex := r.FormValue("sex")
	province := r.FormValue("province")
	city := r.FormValue("city")
	country := r.FormValue("country")

	if realName == "" {
		data.Msg = "真實姓名不能為空"
		data.Status = 0
	}
	if data.Status == 1 {
		if idCard == "" {
			data.Msg = "身份證號不能為空"
			data.Status = 0
		} else {
			reg := regexp.MustCompile(idCardReg)
			if !reg.MatchString(idCard) {
				data.Msg = "身份證號格式錯誤"
				data.Status = 0
			}
		}
	}
	if data.Status == 1 {
		if province == "請選擇" {
			data.Msg = "請選擇完整的地區信息"
			data.Status = 0
		}
		if city == "請選擇" {
			data.Msg = "請選擇完整的地區信息"
			data.Status = 0
		}
		if country == "請選擇" {
			data.Msg = "請選擇完整的地區信息"
			data.Status = 0
		}
	}
	if data.Status == 1 {
		user.Id = id
		user.RealName = realName
		user.IDCard = idCard
		user.Age, _ = strconv.Atoi(age)
		if sex == "on" {
			user.Sex = "男"
		} else {
			user.Sex = "女"
		}
		user.Area = m.Area{province, city, country}
		honours := make([]m.Honours, 3)
		honours[0].Name = "sm"
		honours[0].Title = "未實名認證"
		honours[1].Name = "vip"
		honours[1].Title = "普通用戶"
		honours[2].Name = "db"
		honours[2].Title = "未交擔保金"
		user.Honours = honours

		err := user.UpdateBaseInfoById()
		if err != nil {
			panic(err)
		}
	}

	u.OutputJson(w, &data)
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:74,代碼來源:User.go


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