コード例 #1
0
func GetAccount(c web.C, w http.ResponseWriter, r *http.Request) {
	template := c.Env["render"].(*render.Render)
	db := c.Env["mysql"].(*sqlx.DB)
	bnd := binding.GetDefault(r)
	id, _ := strconv.Atoi(c.URLParams["uid"])
	cookie, _ := r.Cookie("injuv_auth")
	claims, _ := security.Decode(cookie.Value)
	u, err := user.Get(db, id)

	if err != nil {
		panic(err)
	}

	if r.FormValue("edit") == getresponse.ComparableValue {
		bnd["Success"] = strEditSuccess
	}

	bnd["User"] = u
	bnd["ID"] = claims["id"]
	bnd["ADMIN"] = claims["guuid"]

	template.HTML(w, http.StatusOK, "panel/show", bnd, render.HTMLOptions{
		Layout: "panel/layout",
	})
}
コード例 #2
0
func NewActivitie(c web.C, w http.ResponseWriter, r *http.Request) {
	template := c.Env["render"].(*render.Render)
	db := c.Env["mysql"].(*sqlx.DB)
	bnd := binding.GetDefault(r)

	name := utils.GetAndTrim(r, "name")
	description := utils.GetAndTrim(r, "description")
	dateExpire := utils.GetAndTrim(r, "fechaExpiracion")
	recursos := utils.GetAndTrim(r, "recurso")
	estado := utils.GetAndTrim(r, "estado")
	pioridad := utils.GetAndTrim(r, "pioridad")
	//	adjunto := utils.GetAndTrim(r, "adjunto")

	fmt.Println("\n\n\n%s", dateExpire)

	userid, _ := strconv.Atoi(recursos)

	if name == "" {
		bnd["Error"] = StrUserEmpty
	}

	if description == "" {
		bnd["Error"] = StrDescriptionEmpty
	}

	activityNew := &activity.Activity{
		Title:       name,
		Description: description,
		ExpireDate:  dateExpire,
		User:        userid,
		Estate:      estado,
		Adjuntos:    0,
		Pioridad:    pioridad,
	}

	activityNew.Create(db)

	userAdd, _ := user.Get(db, userid)

	//TO_DO LOAD EMAIL FOR USER=user

	emailSender := fmt.Sprintf(strSenderFormat, "injuv araucania", config.SendTo)
	emailFullSubject := fmt.Sprintf("%s", "Notificacion nueva tarea")
	emailMessage := fmt.Sprintf("Se a creado una nueva Tarea %s fecha termino tarea %s", name, dateExpire)
	emailFullName := fmt.Sprintf("Asignada a %s %s", userAdd.FirstName, userAdd.LastName)
	emailBody := fmt.Sprintf(
		strEmailFormat,
		emailMessage,
		emailFullName,
	)

	err := sendEmail(emailBody, emailSender, emailFullSubject, userAdd.Email)
	if err == errBadMail {
		bnd["Error"] = errStrUnableToSend
		template.JSON(w, http.StatusOK, bnd)
		return
	}

	template.JSON(w, http.StatusOK, bnd)
}
コード例 #3
0
ファイル: home.go プロジェクト: injuvproject/backofficeinjuv
func GetHome(c web.C, w http.ResponseWriter, r *http.Request) {
	template := c.Env["render"].(*render.Render)
	bnd := binding.GetDefault(r)

	template.HTML(w, http.StatusOK, "home/home", bnd, render.HTMLOptions{
		Layout: "home/template",
	})
}
コード例 #4
0
func GetNewAccount(c web.C, w http.ResponseWriter, r *http.Request) {
	template := c.Env["render"].(*render.Render)
	bnd := binding.GetDefault(r)
	cookie, _ := r.Cookie("injuv_auth")
	claims, _ := security.Decode(cookie.Value)

	bnd["ID"] = claims["id"]
	bnd["ADMIN"] = claims["guuid"]

	template.HTML(w, http.StatusOK, "panel/create", bnd, render.HTMLOptions{
		Layout: "panel/layout",
	})
}
コード例 #5
0
ファイル: auth.go プロジェクト: injuvproject/backofficeinjuv
func GetLogin(c web.C, w http.ResponseWriter, r *http.Request) {
	template := c.Env["render"].(*render.Render)
	bnd := binding.GetDefault(r)

	cookie, _ := r.Cookie("injuv_auth")

	if cookie != nil {
		claims, _ := security.Decode(cookie.Value)
		id := int(claims["id"].(float64))
		http.Redirect(w, r, fmt.Sprintf("/panel/%d.html", id), http.StatusFound)
		return

	}

	template.HTML(w, http.StatusOK, "home/login", bnd)
}
コード例 #6
0
func UpdateActivity(c web.C, w http.ResponseWriter, r *http.Request) {

	template := c.Env["render"].(*render.Render)
	db := c.Env["mysql"].(*sqlx.DB)
	bnd := binding.GetDefault(r)
	idActivity, _ := strconv.Atoi(utils.GetAndTrim(r, "id"))
	estado := utils.GetAndTrim(r, "estado")

	err := activity.UpdateStatusActivity(db, idActivity, estado)
	if err != nil {
		panic(err)
	}

	template.JSON(w, http.StatusOK, bnd)

}
コード例 #7
0
func GetActivities(c web.C, w http.ResponseWriter, r *http.Request) {
	var (
		pendientes []*activity.Activity
		impedidas  []*activity.Activity
		proceso    []*activity.Activity
		terminados []*activity.Activity
	)
	template := c.Env["render"].(*render.Render)
	db := c.Env["mysql"].(*sqlx.DB)
	id, _ := strconv.Atoi(c.URLParams["id"])
	cookie, _ := r.Cookie("injuv_auth")
	claims, _ := security.Decode(cookie.Value)
	users, _ := user.GetAll(db)
	bnd := binding.GetDefault(r)

	fmt.Println("\n\n\n\n\n\n %d", id)
	if claims["guuid"].(bool) {
		impedidas, _ = activity.GetImpedidas(db, 0)
		pendientes, _ = activity.GetPendintes(db, 0)
		proceso, _ = activity.GetEnProceso(db, 0)
		terminados, _ = activity.GetTerminados(db, 0)

		fmt.Println("\n\n\n\n\n\n ", impedidas)
	} else {

		impedidas, _ = activity.GetImpedidas(db, id)
		pendientes, _ = activity.GetPendintes(db, id)
		proceso, _ = activity.GetEnProceso(db, id)
		terminados, _ = activity.GetTerminados(db, id)

	}

	bnd["Users"] = users
	bnd["ID"] = claims["id"]
	bnd["ADMIN"] = claims["guuid"]
	bnd["Impedidas"] = impedidas
	bnd["Pendientes"] = pendientes
	bnd["Proceso"] = proceso
	bnd["Terminados"] = terminados
	template.HTML(w, http.StatusOK, "panel/activities", bnd, render.HTMLOptions{
		Layout: "panel/layout",
	})
}
コード例 #8
0
func GetDeleteProfile(c web.C, w http.ResponseWriter, r *http.Request) {
	template := c.Env["render"].(*render.Render)
	db := c.Env["mysql"].(*sqlx.DB)
	bnd := binding.GetDefault(r)
	cookie, _ := r.Cookie("injuv_auth")
	claims, _ := security.Decode(cookie.Value)

	ids := claims["id"].(float64)

	id, _ := strconv.Atoi(c.URLParams["uid"])
	err := user.Delete(db, id)
	bnd["ID"] = ids
	bnd["ADMIN"] = claims["guuid"]

	if err == user.ErrUserNotExist {
		bnd["Error"] = user.ErrUserNotExist
		template.HTML(w, http.StatusOK, "/panel/profile", bnd)
	}

	http.Redirect(w, r, fmt.Sprintf(URLPanelDelete, int(ids), getresponse.ComparableValue), http.StatusFound)
	return

}
コード例 #9
0
func PostEditAccount(c web.C, w http.ResponseWriter, r *http.Request) {
	bnd := binding.GetDefault(r)
	db := c.Env["mysql"].(*sqlx.DB)
	template := c.Env["render"].(*render.Render)
	id, _ := strconv.Atoi(c.URLParams["uid"])
	cookie, _ := r.Cookie("injuv_auth")
	claims, _ := security.Decode(cookie.Value)

	firstName := utils.GetAndTrim(r, "firstname")
	lastName := utils.GetAndTrim(r, "lastname")
	userName := utils.GetAndTrim(r, "userName")
	email := utils.GetAndTrim(r, "email")
	password := utils.GetAndTrim(r, "password")
	rePassword := utils.GetAndTrim(r, "repassword")
	userAdmin, _ := strconv.ParseBool(utils.GetAndTrim(r, "admin"))

	fmt.Println("%t\n\n", userAdmin)

	if firstName == "" {
		bnd["Error"] = strFirstNameEmpty
	}

	if lastName == "" {
		bnd["Error"] = strLastNameEmpty
	}

	if userName == "" {
		bnd["Error"] = strUserNameEmpty
	}

	if password == "" {
		bnd["Error"] = strPasswordEmpty
	}
	if rePassword == "" {
		bnd["Error"] = strPasswordEmpty
	}
	if password != rePassword {
		bnd["Error"] = strErrorPassword
	}

	if bnd["Error"] != nil {
		template.HTML(w, http.StatusOK, "panel/edit", bnd)
		return
	}

	newUser := &user.User{
		ID:         id,
		FirstName:  firstName,
		LastName:   lastName,
		UserName:   userName,
		Email:      email,
		Password:   password,
		Admin:      userAdmin,
		SignupDate: time.Now(),
	}
	ids := claims["id"].(float64)
	bnd["ADMIN"] = claims["guuid"]
	bnd["User"] = newUser

	newUser.Save(db)

	if claims["guuid"].(bool) == true {
		http.Redirect(w, r, fmt.Sprintf(URLPanelUserByID, int(ids), id, getresponse.ComparableValue), http.StatusFound)
		return
	}

	http.Redirect(w, r, fmt.Sprintf(URLProfileUserByID, int(ids), id, getresponse.ComparableValue), http.StatusFound)
	return

}