예제 #1
0
// GET admin get one employee
func AdminEmployeeGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-employee-form.tmpl", tmpl.Model{
		msgK:        msgV,
		"employees": service.FindAllEmployee(),
		"employee":  service.FindOneEmployee(c.GetPathVar("id")),
		"users":     service.UserRoles(),
	})
	return
}
예제 #2
0
// POST edit employee
func AdminEmployeeEdit(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	if !service.CanUpdateUser(r.FormValue("userId"), r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/employee/"+r.FormValue("id"), 303)
		return
	}
	r.ParseForm()
	employee := service.FindOneEmployee(r.FormValue("id"))
	util.FormToStruct(&employee, r.Form, "")
	user := service.FindOneUser(employee.UserId)
	util.FormToStruct(&user, r.Form, "")
	user.Id = employee.UserId
	service.SaveEmployee(employee)
	service.SaveUser(user)
	c.SetFlash("alertSuccess", "Successfully saved employee")
	http.Redirect(w, r, "/admin/employee", 303)
	return
}