Пример #1
0
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)
	}

}
Пример #2
0
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)

}
Пример #3
0
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 = "******"
	// 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)
}