예제 #1
0
파일: base.go 프로젝트: zbzzbd/beego
func (c *BaseController) setCurrentUser() {
	if !c.isLogin {
		return
	}
	userId := c.GetSession("user_id").(uint)
	var err error

	defer func() {
		if err != nil {
			utils.GetLog().Error("controllers.BaseController.setCurrentUser : NewUserWithId error : userId = %v, noNeedLogin=%v", userId, c.noNeedLogin)
		}
	}()

	if c.currentUser, err = user.NewUserWithId(userId); err != nil {
		if !c.noNeedLogin {
			c.Redirect("/login", 302)
		}
		return
	}
	c.userId = int(userId)

	c.Data["user_info"] = c.currentUser.GetUser()

	c.setUserCookie()
}
예제 #2
0
파일: user.go 프로젝트: zbzzbd/beego
func (c *UserController) Edit() {
	c.GetViewData()

	uid := c.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(uid)
	user, err := user.NewUserWithId(uint(id))

	if err != nil {
		c.Data["error"] = "用户不存在"
	}

	c.Data["user"] = user.GetUser()

	c.TplNames = "users/edit.tpl"
}
예제 #3
0
파일: user.go 프로젝트: zbzzbd/beego
func (c *UserController) Delete() {
	uid := c.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(uid)
	user, err := user.NewUserWithId(uint(id))
	if err != nil {
		c.SetJsonResponse("error", err.Error())
	} else {
		saveUser := user.GetUser()
		saveUser.Deleted = time.Now()
		err = saveUser.Update("deleted")
	}

	if err != nil {
		c.SetJsonResponse("error", err.Error())
	}

	c.GetJsonResponse().ServeJson()
}
예제 #4
0
파일: project.go 프로젝트: zbzzbd/beego
func (c *ProjectController) HandleFilter() map[string]interface{} {
	filter := make(map[string]interface{})
	filter["limit"] = 10
	filter["offset"] = 0
	id := c.GetString("project_name")
	if id != "" {
		filter["id"] = id
		p, _ := project.NewProject().GetOne(id)
		c.Data["project_default"] = p.GetModelProject()
	}
	bussiness_user := c.GetString("bussiness_user")
	if bussiness_user != "" {
		filter["bussiness_user_id"] = bussiness_user
		user_id, _ := strconv.Atoi(bussiness_user)
		user, _ := user.NewUserWithId(uint(user_id))
		c.Data["bussiness_user_default"] = user.GetUser()
	}

	progress_filter := c.GetString("progress")
	if progress_filter != "" {
		filter["progress"] = progress_filter
		progress, _ := project.NewProgress().GetProgressById(progress_filter)
		c.Data["progress_default"] = progress.GetModelProgress()
	}

	start_date := c.GetString("start_date")
	if start_date != "" {
		filter["start_date"] = start_date
		c.Data["start_date_default"] = start_date
	}

	end_date := c.GetString("end_date")
	if end_date != "" {
		filter["end_date"] = end_date
		c.Data["end_date_default"] = end_date
	}

	p, _ := c.GetInt("p")
	if p > 1 {
		filter["offset"] = (p - 1) * filter["limit"].(int)
	}
	return filter
}
예제 #5
0
파일: user.go 프로젝트: zbzzbd/beego
func (c *UserController) PostEdit() {
	uid, _ := c.GetInt("id")
	companyId, _ := c.GetInt("company")
	user, err := user.NewUserWithId(uint(uid))
	saveUser := user.GetUser()
	if err != nil {
		c.SetJsonResponse("error", err.Error())
	} else {
		saveUser.Company = &models.Company{Id: uint(companyId)}
		saveUser.Roles = c.GetString("role")
		saveUser.Name = c.GetString("name")
		saveUser.Email = c.GetString("email")
		saveUser.Mobile = c.GetString("mobile")
		err = saveUser.Update("company_id", "Roles", "name", "email", "mobile")
	}

	if err != nil {
		c.SetJsonResponse("error", err.Error())
	}

	c.GetJsonResponse().ServeJson()
}