// Delete deletes the resume. // // Method POST // // Route /resume/delete/:id // // Restrictions Yes // // Template None func Delete(ctx *echo.Context) error { var flashMessages = flash.New() id, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } user := ctx.Get("User").(*models.Person) resume, err := query.GetResumeByID(id) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage) } // Users are allowed to delete resumes that they don't own. if resume.PersonID != user.ID { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } err = query.Delete(resume) if err != nil { utils.SetData(ctx, "Message", tmpl.ServerErrorMessage) return ctx.Render(http.StatusInternalServerError, tmpl.ErrServerTpl, utils.GetData(ctx)) } flashMessages.Success("resume successful deleted") flashMessages.Save(ctx) ctx.Redirect(http.StatusFound, "/resume/") return nil }
// RegionsHome renders regions home page. // // // Method GET // // Route /jobs/regions // // Restrictions None // // Template base/regions.html // func RegionsHome(ctx *echo.Context) error { regs, err := query.GetAllRegions() if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } utils.SetData(ctx, settings.RegionsListKey, regs) return ctx.Render(http.StatusOK, tmpl.BaseRegionsTpl, utils.GetData(ctx)) }
// JobsHome renders jobs home page // // // Method GET // // Route /jobs/ // // Restrictions None // // Template base/jobs.html func JobsHome(ctx *echo.Context) error { jobs, err := query.GetLatestJobs() if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } utils.SetData(ctx, settings.JobsListKey, jobs) utils.SetData(ctx, settings.PageTitleKey, "jobs") return ctx.Render(http.StatusOK, tmpl.BaseJobsHomeTpl, utils.GetData(ctx)) }
// RegionsJobView renders jobs from a gien region. The region name should be in short form. // // // Method GET // // Route /jobs/regions/:name // // Restrictions None // // Template base/regions_job.html // func RegionsJobView(ctx *echo.Context) error { name := ctx.Param("name") jobs, count, err := query.GetJobByRegionShort(name) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } utils.SetData(ctx, settings.JobsFound, count) utils.SetData(ctx, settings.JobsListKey, jobs) return ctx.Render(http.StatusOK, tmpl.BaseRegionsJobViewTpl, utils.GetData(ctx)) }
// View displays the resume. // // Method GET // // Route /resume/view // // Restrictions Yes // // Template resume/view.html func View(ctx *echo.Context) error { iid, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } resume, err := query.GetResumeByID(iid) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage) } utils.SetData(ctx, "resume", resume) return ctx.Render(http.StatusOK, tmpl.ResumeViewTpl, utils.GetData(ctx)) }
// DocsHome renders the home.md document for the given language. // // Method GET // // Route /docs // // Restrictions None // // Template base/docs_index.html // func DocsHome(ctx *echo.Context) error { data := utils.GetData(ctx).(utils.Data) lang := data.Get(settings.LangDataKey).(string) home := settings.DocsPath + "/" + lang + "/" + settings.DocsIndexPage d, err := static.Asset(home) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } data.Set("doc", string(d)) data.Set(docIndex, getDocIndex(lang)) data.Set("PageTitle", settings.DocsIndexPage) return ctx.Render(http.StatusOK, tmpl.BaseDocsHomeTpl, data) }
// RegisterPost handles registration form, and create a session for the new user if the registration // process is complete. // // Method POST // // Route /auth/register // // Restrictions None // // Template None (All actions redirect to other routes ) // // Flash messages may be set before redirection. func RegisterPost(ctx *echo.Context) error { var flashMessages = flash.New() f := forms.New(utils.GetLang(ctx)) lf := f.RegisterForm()(ctx.Request()) if !lf.IsValid() { // Case the form is not valid, ships it back with the errors exclusively utils.SetData(ctx, authForm, lf) return ctx.Render(http.StatusOK, tmpl.RegisterTpl, utils.GetData(ctx)) } // we are not interested in the returned user, rather we make sure the user has // been created. _, err := query.CreateNewUser(lf.GetModel().(forms.Register)) if err != nil { flashMessages.Err(msgAccountCreateFailed) flashMessages.Save(ctx) ctx.Redirect(http.StatusFound, "/auth/register") return nil } // TODO: improve the message to include directions to use the current email and // password to login? flashMessages.Success(msgAccountCreate) flashMessages.Save(ctx) // Don't create session in this route, its best to leave only one place which // messes with the main user session. So we redirect to the login page, and encourage // the user to login. ctx.Redirect(http.StatusFound, "/auth/login") return nil }
// JobView displays a single job by the given job id. // // // Method GET // // Route /jobs/view/:id // // Restrictions None // // Template base/jobs_view.html func JobView(ctx *echo.Context) error { id, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } job, err := query.GetJobByID(id) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } if job != nil { utils.SetData(ctx, "Job", job) } return ctx.Render(http.StatusOK, tmpl.BaseJobsViewTpl, utils.GetData(ctx)) }
// Home shows the resumes home page. // // Method GET // // Route /resume/ // // Restrictions Yes // // Template resume/home.html func Home(ctx *echo.Context) error { user := ctx.Get("User").(*models.Person) if res, err := query.GetAllPersonResumes(user); err == nil { utils.SetData(ctx, "resumes", res) } return ctx.Render(http.StatusOK, tmpl.ResumeHomeTpl, utils.GetData(ctx)) }
// Register renders registration form. // // Method GET // // Route /auth/register // // Restrictions None // // Template auth/register.html func Register(ctx *echo.Context) error { f := forms.New(utils.GetLang(ctx)) utils.SetData(ctx, authForm, f.RegisterForm()()) // set page tittle to register utils.SetData(ctx, "PageTitle", "register") return ctx.Render(http.StatusOK, tmpl.RegisterTpl, utils.GetData(ctx)) }
// Docs renders individual zedlist document. // // Method GET // // Route /docs/:name // // Restrictions None // // Template base/docs.html func Docs(ctx *echo.Context) error { data := utils.GetData(ctx).(utils.Data) lang := data.Get(settings.LangDataKey).(string) fname := ctx.Param("name") if filepath.Ext(fname) != ".md" { fname = fname + ".md" } fPath := settings.DocsPath + "/" + lang + "/" + fname d, err := static.Asset(fPath) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } data.Set("doc", string(d)) data.Set("PageTitle", fname) data.Set(docIndex, getDocIndex(lang)) return ctx.Render(http.StatusOK, tmpl.BaseDocTpl, data) }
func hello(ctx *echo.Context) error { token := "" d := utils.GetData(ctx).(utils.Data) tok := d.Get("CsrfToken") if tok != nil { token = tok.(string) } return ctx.String(http.StatusOK, token) }
// Login renders login form. // // Method GET // // Route /auth/login // // Restrictions None // // Template auth/login.html // func Login(ctx *echo.Context) error { f := forms.New(utils.GetLang(ctx)) utils.SetData(ctx, authForm, f.LoginForm()()) // set page tittle to login utils.SetData(ctx, "PageTitle", "login") return ctx.Render(http.StatusOK, tmpl.LoginTpl, utils.GetData(ctx)) }
// RegionsJobPaginate a route frr /jobs/regions/:name/:from/:to. It handles pagination where // form to is offset and limit respectively. // // For example route "/jobs/regions/mza/2/4" will render from 2nd to 4th latest jobs from mwanza. // // Method GET // // Route /jobs/regions/:name/:from/:to // // Restrictions None // // Template base/regions.html func RegionsJobPaginate(ctx *echo.Context) error { name := ctx.Param("name") offset, err := utils.GetInt(ctx.Param("from")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } limit, err := utils.GetInt(ctx.Param("to")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } jobs, err := query.GetJobByRegionPaginate(name, offset, limit) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } utils.SetData(ctx, settings.JobsListKey, jobs) return ctx.Render(http.StatusOK, tmpl.BaseRegionsPaginateTpl, utils.GetData(ctx)) }
// Update renders the resume update page. // // Method GET // // Route /resume/update/:id // // Restrictions Yes // // Template None func Update(ctx *echo.Context) error { id, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } user := ctx.Get("User").(*models.Person) resume, err := query.GetResumeByID(id) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage) } // Users are allowed to update resumes that they own. if resume.PersonID != user.ID { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } utils.SetData(ctx, "resume", resume) return ctx.Render(http.StatusOK, tmpl.ResumeUpddateTpl, utils.GetData(ctx)) }
// Create creates a new resume. // // Method POST // // Route /resume/new // // Restrictions Yes // // Template None func Create(ctx *echo.Context) error { var flashMessages = flash.New() r := ctx.Request() r.ParseForm() name := r.Form.Get("resume_name") user := ctx.Get("User").(*models.Person) resume := models.SampleResume() resume.Name = name err := query.CreateResume(user, resume) if err != nil { utils.SetData(ctx, "Message", tmpl.ServerErrorMessage) return ctx.Render(http.StatusInternalServerError, tmpl.ErrServerTpl, utils.GetData(ctx)) } flashMessages.Success("successful created a new resume") flashMessages.Save(ctx) // Redirect to the update page for further updating of the resume. ctx.Redirect(http.StatusFound, fmt.Sprintf("/resume/update/%d", resume.ID)) return nil }
// Home renders zedlist home page. // // Method GET // // Route / // // Restrictions None // // Template base/home.html func Home(ctx *echo.Context) error { return ctx.Render(http.StatusOK, tmpl.BaseHomeTpl, utils.GetData(ctx)) }
func home(ctx *echo.Context) error { d := utils.GetData(ctx).(utils.Data) flashes := d.Get("Flash").(flash.Flashes)[0] return ctx.String(http.StatusOK, fmt.Sprintf("%#v", pretty.Formatter(flashes))) }
// JobsNewGet renders the new job form. // // Method GET // // Route /dash/jobs/new // // Restrictions Yes // // Template dash/jobs_new.html func JobsNewGet(ctx *echo.Context) error { f := forms.New(utils.GetLang(ctx)) utils.SetData(ctx, "PageTitle", "new job") utils.SetData(ctx, "JobForm", f.JobForm()()) return ctx.Render(http.StatusOK, tmpl.DashJobTpl, utils.GetData(ctx)) }
// Home renders dashboard home page. // // Method GET // // Route /dash/ // // Restrictions Yes // // Template dash/home.html func Home(ctx *echo.Context) error { utils.SetData(ctx, "PageTitle", "dashboard") f := forms.New(utils.GetLang(ctx)) utils.SetData(ctx, "JobForm", f.JobForm()()) return ctx.Render(http.StatusOK, tmpl.DashHomeTpl, utils.GetData(ctx)) }
// Profile renders user profile. // // Method GET // // Route /dash/profile // // Restrictions Yes // // Template dash/profile.html func Profile(ctx *echo.Context) error { utils.SetData(ctx, "PageTitle", "profile") return ctx.Render(http.StatusOK, tmpl.DashProfileTpl, utils.GetData(ctx)) }