Beispiel #1
0
func Login(ctx *context.Context) {
	message := ""
	ctx.Request.ParseForm()
	form := &loginForm{
		EnableValidation: &common.EnableValidation{},
	}

	if ctx.Request.Method == "POST" {
		form.Email = ctx.Request.Form.Get("email")
		form.Password = ctx.Request.Form.Get("password")
		form.SetupValidation()

		if !form.EnableValidation.Valid.HasErrors() {
			// find user
			err := userExists(form)
			if err != nil {
				log.Println(err.Error())
				message = "User not found or wrong password"

			} else {
				ctx.Session.Set("email", form.Email)
				ctx.Render.Redirect("/")
			}
		}
	}

	ctx.HTML("users/login", context.ViewData{
		"form":    form,
		"message": message,
	})

}
Beispiel #2
0
func Index(ctx *context.Context) {
	ctx.Request.ParseForm()
	form := &profileForm{
		EnableValidation: &common.EnableValidation{},
		FirstName:        ctx.User.FirstName,
		LastName:         ctx.User.LastName,
	}

	if ctx.Request.Method == "POST" {
		form.FirstName = ctx.Request.Form.Get("firstName")
		form.LastName = ctx.Request.Form.Get("lastName")
		form.SetupValidation()
		if !form.EnableValidation.Valid.HasErrors() {
			ctx.User.FirstName = form.FirstName
			ctx.User.LastName = form.LastName
			ctx.User.Save()

			ctx.Session.AddFlash("Your data has been successfully saved.", "success")
			ctx.Render.Redirect("/profile")
		}
	}

	ctx.HTML("profile/index", context.ViewData{
		"form": form,
	})
}
Beispiel #3
0
func Register(ctx *context.Context) {
	ctx.Request.ParseForm()
	form := &registerForm{
		EnableValidation: &common.EnableValidation{},
	}

	if ctx.Request.Method == "POST" {
		form.Email = ctx.Request.Form.Get("email")
		form.Password = ctx.Request.Form.Get("password")
		form.SetupValidation()

		if !form.EnableValidation.Valid.HasErrors() && form.IsValid() {
			password, err := common.HashPassword(form.Password)

			if err != nil {
				panic(err.Error())
			}

			doc := goes.Document{
				Index: "users",
				Type:  "user",
				Fields: map[string]string{
					"email":    form.Email,
					"password": password,
					"apiKey":   buildApiKey(form.Email),
				},
			}
			extraArgs := make(url.Values, 0)
			common.GetConnection().Index(doc, extraArgs)
			ctx.Render.Redirect("/login")
		}
	}

	ctx.HTML("users/register", context.ViewData{
		"form": form,
	})
}
Beispiel #4
0
func update(ctx *context.Context, form *projectForm) {
	if ctx.Request.Method == "POST" {
		form.Name = ctx.Request.Form.Get("name")
		form.Description = ctx.Request.Form.Get("description")
		form.Types = ctx.Request.PostForm["types"]
		form.SetupValidation()

		if !form.EnableValidation.Valid.HasErrors() {
			group := &common.Project{
				Id:          form.Id,
				Name:        form.Name,
				Description: form.Description,
				Types:       form.Types,
			}
			ctx.User.AddProject(group).Save()
			ctx.Session.AddFlash("Project has been successfully saved.", "success")
			ctx.Render.Redirect("/projects")
		}
	}

	ctx.HTML("projects/new", context.ViewData{
		"form": form,
	})
}
Beispiel #5
0
// This function handles two routes "/" and "/project/:id"
func ProjectSearch(ctx *context.Context, params martini.Params) {
	var types []string
	var project *common.Project

	query_text := ctx.Request.URL.Query().Get("q")
	selected_types := ctx.Request.URL.Query()["types"]

	// Project scope
	if _, err := params["id"]; err {
		project, err := ctx.User.GetProject(params["id"])
		if err != nil {
			ctx.HTML("shared/error", context.ViewData{
				"message": "Project not found",
			})
			return
		}
		if len(project.Types) == 0 {
			ctx.HTML("home/empty_project", context.ViewData{
				"project": project,
			})
			return
		}
		if len(selected_types) > 0 {
			types = selected_types
		} else {
			types = project.Types
		}
	}

	// Pagination
	pagination := widgets.NewPagination(ctx.Request)
	pagination.SetPerPage(perPage)

	// Load records
	searchRequest := buildSearchRequest(
		query_text,
		[]string{ctx.User.GetIndexName()},
		types,
		pagination.GetPerPage(),
		pagination.DetectFrom(),
		buildTimeRange(ctx.Request),
	)
	// Search data in elastic
	data, _ := search(searchRequest)

	pagination.SetTotalRecords(data.Hits.Total)

	var viewName string
	viewData := context.ViewData{
		"project":    project,
		"logs":       data.Hits.Hits,
		"total":      data.Hits.Total,
		"took":       data.Took,
		"types":      types,
		"time":       ctx.Request.URL.Query().Get("time"),
		"time_start": ctx.Request.URL.Query().Get("time_start"),
		"time_stop":  ctx.Request.URL.Query().Get("time_stop"),
		"query_text": query_text,
		"pagination": pagination,
	}

	if ctx.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" {
		viewName = "home/table"
	} else {
		viewName = "home/index"
	}

	ctx.HTML(viewName, viewData)
}
Beispiel #6
0
// Display list of ES types available to user.
func Types(ctx *context.Context) {
	ctx.HTML("projects/types", context.ViewData{
		"docCounter": common.CountTypeDocs,
	})
}
Beispiel #7
0
func Index(ctx *context.Context) {
	ctx.HTML("live/index", context.ViewData{}, "layouts/simple")
}
Beispiel #8
0
func Index(ctx *context.Context) {
	ctx.HTML("projects/index", context.ViewData{})
}