コード例 #1
0
ファイル: admin.go プロジェクト: baiyuxiong/lms
func (c Admin) DoEditUser(id int, username, password, name, phone, phone1, position, email string, department_id, employment_type, gender, level, is_leader int, join_date, birth_date time.Time) revel.Result {

	c.Validation.Required(username).Message("用户名不能为空")
	c.Validation.Required(name).Message("姓名不能为空")

	if c.Validation.HasErrors() {
		c.Flash.Error(utils.ValidationErrorToString(c.Validation.Errors))
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect("/admin/editUser/?id=" + fmt.Sprintf("%d", id))
	}

	//判断部门有没有领导
	if is_leader == 1 {
		dept := &models.Department{}
		app.Engine.Id(department_id).Get(dept)
		if dept.LeaderId != 0 && dept.LeaderId != c.User.Id {
			up := &models.UserProfiles{}
			app.Engine.Id(dept.LeaderId).Get(up)

			c.Flash.Error("该部门当前审批负责人为" + up.Name + ",一个部门只能指定一个审批负责人")
			c.Validation.Keep()
			c.FlashParams()
			return c.Redirect("/admin/editUser?id=" + fmt.Sprintf("%d", id))
		}
	}

	service.EditUser(id, username, password, department_id, employment_type, gender, level, name, phone, phone1, position, email, join_date, birth_date, c.Request.RemoteAddr)

	return c.Redirect("/admin/listUser")
}
コード例 #2
0
ファイル: admin.go プロジェクト: baiyuxiong/lms
func (c Admin) DoAddDepartment(name, info string, parent_id int) revel.Result {

	c.Validation.Required(name).Message("名称不能为空")

	if c.Validation.HasErrors() {
		c.Flash.Error(utils.ValidationErrorToString(c.Validation.Errors))
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect("/admin/addDepartment")
	}

	//获取上一级的depth,本级加1
	depth := 0
	if parent_id > 0 {
		department := &models.Department{}
		app.Engine.Id(parent_id).Get(department)
		if nil != department {
			depth = department.Depth
		}
	}

	l := new(models.Department)
	l.Name = name
	l.Info = info
	l.Depth = (depth + 1)
	l.ParentId = parent_id
	l.UpdatedAt = time.Now()
	l.CreatedAt = time.Now()

	app.Engine.Insert(l)
	return c.Redirect("/admin/listDepartment")
}
コード例 #3
0
ファイル: auth.go プロジェクト: baiyuxiong/lms
func (c Auth) DoLogin(username, password string) revel.Result {
	revel.INFO.Println("DoLogin")

	c.Validation.Required(username).Message("用户名不能为空")
	c.Validation.Required(password).Message("密码不能为空")

	if c.Validation.HasErrors() {
		c.Flash.Error(utils.ValidationErrorToString(c.Validation.Errors))
		c.Validation.Keep()
		c.FlashParams()
		revel.INFO.Println("DoLogin Validation error")
		return c.Redirect("/auth/login")
	} else {
		errorMsg := ""

		var u = &models.Users{Username: username}
		has, _ := app.Engine.Get(u)

		if !has {
			errorMsg = "用户名或密码出错"
		}

		if utils.EncryptPassword(u.Salt, password) != u.Password {
			errorMsg = "用户名或密码出错"
		}

		if len(errorMsg) > 0 {
			c.Flash.Error(errorMsg)
			revel.INFO.Println("DoLogin Validation error - ", errorMsg)
			c.Validation.Keep()
			c.FlashParams()
			return c.Redirect("/auth/login")
		}

		c.Session[utils.SESSION_KEY_UID] = fmt.Sprintf("%d", u.Id)

		u.UpdatedAt = time.Now()
		app.Engine.Id(u.Id).Cols("updated_at").Update(u)

		if username == utils.ADMIN_USERNAME {
			return c.Redirect("/admin")
		} else {
			return c.Redirect("/")
		}
	}
}