示例#1
0
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()
	}

}
示例#2
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)
	}

}
示例#3
0
func (this *LoginController) Check() {
	data := e.Data{Status: 1, Msg: "已登录"}
	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	if cookie.UserId == nil { //没有登录
		data.Status = 0
		data.Msg = "没有登录"
		data.Data = "/login"
	}
	u.OutputJson(this.ResponseWriter, &data)
}
示例#4
0
func (this *AvatarController) Post() {
	w := this.ResponseWriter
	r := this.Request
	data := e.Data{Status: 1, Msg: "上传成功"}
	log.Println("头像上传post")
	r.ParseMultipartForm(32 << 20)
	log.Println("表单解析")
	file, handler, err := r.FormFile("realPicFile")

	if err != nil {
		log.Println("上传错误")
		return
	}

	fileext := filepath.Ext(handler.Filename)
	log.Println("文件后缀名字" + fileext)
	if u.Check(fileext) == false {
		data.Status = 0
		data.Msg = "不允许的上传类型"
		u.OutputJson(w, &data)
		return
	}
	cookie := u.Cookie{HTTP: this.HTTP}

	filename := cookie.GetCookie().UserId.Value + ".png"
	log.Println("文件名称" + filename)

	imgfile, _ := os.OpenFile(Upload_Dir+filename, os.O_CREATE|os.O_WRONLY, 0660)
	defer imgfile.Close()
	//把图片变成400X400尺寸的
	m1, err := jpeg.Decode(file)
	if err != nil {
		panic(err)
	}
	bounds := m1.Bounds()
	//如果第二参数为0则保持横纵比
	g := gift.New(
		gift.Resize(400, 400, gift.LanczosResampling),
	)
	dst := image.NewRGBA(g.Bounds(bounds))
	g.Draw(dst, m1)
	err = png.Encode(imgfile, dst)

	if err != nil {
		log.Println("上传失败")
		return
	}
	filedir := Show_Dir + filename
	data.Data = filedir
	log.Println(data)
	u.OutputJson(w, &data)
}
示例#5
0
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)
			}
		}

	}
}
示例#6
0
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)
}
示例#7
0
func (this *OrderController) Add() {
	w := this.ResponseWriter
	r := this.Request
	data := e.Data{Msg: "生成订单成功", Status: 1}
	r.ParseForm()

	money := r.FormValue("money")
	startTime := r.FormValue("startTime")
	endTime := r.FormValue("endTime")
	address := r.FormValue("address")
	ruserId := r.FormValue("ruser")
	remark := r.FormValue("remark")
	skillId := r.FormValue("skill")

	order := m.Order{}
	order.Skill.Id = skillId
	order.Skill = order.Skill.GetSkillById()

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

	if cookie.UserId != nil {
		order.OUser = cookie.UserId.Value
	}

	log.Println(startTime)
	log.Println(endTime)
	order.BeginTime, _ = time.Parse("2006-01-02 15:04", startTime)
	order.EndTime, _ = time.Parse("2006-01-02 15:04", endTime)
	order.OrderTime = time.Now()
	order.Status = "预约"
	order.Remark = remark
	order.Address = address
	order.TotalPrice, _ = strconv.ParseFloat(money, 32)
	ordered, err := order.InsertOrder()
	data.Data = ordered
	if err != nil {
		data.Msg = "订单生成失败"
		data.Status = 0
	}
	u.OutputJson(w, &data)
}
示例#8
0
func (this *OrderController) Get() {
	w := this.ResponseWriter
	r := this.Request
	skill := r.FormValue("skill")
	// common := CommonController{HTTP: this.HTTP}
	// common.ShowPage("", "Order.add.tpl")
	cookie := u.Cookie{HTTP: this.HTTP}
	cookie = cookie.GetCookie()
	log.Println(cookie.UserId)
	if cookie.UserId == nil { //没有登录,则跳转到登录界面
		http.Redirect(w, r, "/login", http.StatusSeeOther)
	} else {
		t, err := t.ParseFiles("views/Order.add.tpl")
		if err != nil {
			log.Println(err)
		}
		t.ExecuteTemplate(w, "orderAdd", skill)
	}
}
示例#9
0
func (this *AvatarController) Cut() {
	r := this.Request
	data := e.Data{Status: 1, Msg: "上传成功"}
	r.ParseForm()
	x, err := strconv.Atoi(r.FormValue("x"))
	y, err := strconv.Atoi(r.FormValue("y"))
	x2, err := strconv.Atoi(r.FormValue("x2"))
	y2, err := strconv.Atoi(r.FormValue("y2"))

	fileName := r.FormValue("fileName")
	log.Println(x, y, x2, y2, fileName)
	g := gift.New(
		gift.Crop(image.Rect(x, y, x2, y2)),
		gift.Resize(220, 220, gift.LanczosResampling),
	)
	log.Println("图片名称" + fileName)
	//打开待处理的图片
	file, err := os.Open(fileName)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	m1, err := png.Decode(file)
	if err != nil {
		panic(err)
	}
	bounds := m1.Bounds()

	dst := image.NewRGBA(g.Bounds(bounds))
	g.Draw(dst, m1)
	cookie := u.Cookie{HTTP: this.HTTP}

	filename := cookie.GetCookie().UserId.Value + ".png"

	imgfile, err := os.Create(Avatar_ReDir + filename)
	os.Remove(Upload_Dir + filename)
	defer imgfile.Close()
	err = png.Encode(imgfile, dst)
	u.OutputJson(this.ResponseWriter, &data)
}