func (u User) sendConfirmEmail(request prago.Request, a *Admin) error { if u.emailConfirmed() { return errors.New("email already confirmed") } if a.noReplyEmail == "" { return errors.New("no reply email empty") } locale := GetLocale(request) urlValues := make(url.Values) urlValues.Add("email", u.Email) urlValues.Add("token", u.emailToken(a.App)) subject := messages.Messages.Get(locale, "admin_confirm_email_subject", a.AppName) link := request.App().Config.GetString("baseUrl") + a.Prefix + "/user/confirm_email?" + urlValues.Encode() body := messages.Messages.Get(locale, "admin_confirm_email_body", link, link, a.AppName) message := sendgrid.NewMail() message.SetFrom(a.noReplyEmail) message.AddTo(u.Email) message.AddToName(u.Name) message.SetSubject(subject) message.SetHTML(body) return a.sendgridClient.Send(message) }
func DevelopmentRecovery(p *prago.Request, recoveryData interface{}) { if p.App().DevelopmentMode { temp, err := template.New("development_error").Parse(developmentErrorTmpl) if err != nil { panic(err) } byteData := fmt.Sprintf("%s", recoveryData) buf := new(bytes.Buffer) err = temp.ExecuteTemplate(buf, "development_error", map[string]interface{}{ "name": byteData, "subname": "500 Internal Server Error", "stack": string(debug.Stack()), }) if err != nil { panic(err) } p.Response().Header().Add("Content-type", "text/html") p.Response().WriteHeader(500) p.Response().Write(buf.Bytes()) } else { p.Response().WriteHeader(500) p.Response().Write([]byte("We are sorry, some error occured. (500)")) } p.Log().Errorln(fmt.Sprintf("500 - error\n%s\nstack:\n", recoveryData)) p.Log().Errorln(string(debug.Stack())) }
func stats(request prago.Request) { if !AuthenticateSysadmin(GetUser(request)) { render403(request) return } stats := [][2]string{} stats = append(stats, [2]string{"App name", request.App().Data()["appName"].(string)}) stats = append(stats, [2]string{"App version", request.App().Data()["version"].(string)}) port := request.App().Data()["port"].(int) stats = append(stats, [2]string{"Port", fmt.Sprintf("%d", port)}) developmentModeStr := "false" if request.App().DevelopmentMode { developmentModeStr = "true" } stats = append(stats, [2]string{"Development mode", developmentModeStr}) stats = append(stats, [2]string{"Started at", request.App().StartedAt.Format(time.RFC3339)}) stats = append(stats, [2]string{"Go version", runtime.Version()}) stats = append(stats, [2]string{"Compiler", runtime.Compiler}) stats = append(stats, [2]string{"GOARCH", runtime.GOARCH}) stats = append(stats, [2]string{"GOOS", runtime.GOOS}) stats = append(stats, [2]string{"GOMAXPROCS", fmt.Sprintf("%d", runtime.GOMAXPROCS(-1))}) configStats := request.App().Config.Export() osStats := [][2]string{} osStats = append(osStats, [2]string{"EGID", fmt.Sprintf("%d", os.Getegid())}) osStats = append(osStats, [2]string{"EUID", fmt.Sprintf("%d", os.Geteuid())}) osStats = append(osStats, [2]string{"GID", fmt.Sprintf("%d", os.Getgid())}) osStats = append(osStats, [2]string{"Page size", fmt.Sprintf("%d", os.Getpagesize())}) osStats = append(osStats, [2]string{"PID", fmt.Sprintf("%d", os.Getpid())}) osStats = append(osStats, [2]string{"PPID", fmt.Sprintf("%d", os.Getppid())}) wd, _ := os.Getwd() osStats = append(osStats, [2]string{"Working directory", wd}) hostname, _ := os.Hostname() osStats = append(osStats, [2]string{"Hostname", hostname}) var mStats runtime.MemStats runtime.ReadMemStats(&mStats) memStats := [][2]string{} memStats = append(memStats, [2]string{"Alloc", fmt.Sprintf("%d", mStats.Alloc)}) memStats = append(memStats, [2]string{"TotalAlloc", fmt.Sprintf("%d", mStats.TotalAlloc)}) memStats = append(memStats, [2]string{"Sys", fmt.Sprintf("%d", mStats.Sys)}) memStats = append(memStats, [2]string{"Lookups", fmt.Sprintf("%d", mStats.Lookups)}) memStats = append(memStats, [2]string{"Mallocs", fmt.Sprintf("%d", mStats.Mallocs)}) memStats = append(memStats, [2]string{"Frees", fmt.Sprintf("%d", mStats.Frees)}) memStats = append(memStats, [2]string{"HeapAlloc", fmt.Sprintf("%d", mStats.HeapAlloc)}) memStats = append(memStats, [2]string{"HeapSys", fmt.Sprintf("%d", mStats.HeapSys)}) memStats = append(memStats, [2]string{"HeapIdle", fmt.Sprintf("%d", mStats.HeapIdle)}) memStats = append(memStats, [2]string{"HeapInuse", fmt.Sprintf("%d", mStats.HeapInuse)}) memStats = append(memStats, [2]string{"HeapReleased", fmt.Sprintf("%d", mStats.HeapReleased)}) memStats = append(memStats, [2]string{"HeapObjects", fmt.Sprintf("%d", mStats.HeapObjects)}) memStats = append(memStats, [2]string{"StackInuse", fmt.Sprintf("%d", mStats.StackInuse)}) memStats = append(memStats, [2]string{"StackSys", fmt.Sprintf("%d", mStats.StackSys)}) memStats = append(memStats, [2]string{"MSpanInuse", fmt.Sprintf("%d", mStats.MSpanInuse)}) memStats = append(memStats, [2]string{"MSpanSys", fmt.Sprintf("%d", mStats.MSpanSys)}) memStats = append(memStats, [2]string{"MCacheInuse", fmt.Sprintf("%d", mStats.MCacheInuse)}) memStats = append(memStats, [2]string{"MCacheSys", fmt.Sprintf("%d", mStats.MCacheSys)}) memStats = append(memStats, [2]string{"BuckHashSys", fmt.Sprintf("%d", mStats.BuckHashSys)}) memStats = append(memStats, [2]string{"GCSys", fmt.Sprintf("%d", mStats.GCSys)}) memStats = append(memStats, [2]string{"OtherSys", fmt.Sprintf("%d", mStats.OtherSys)}) memStats = append(memStats, [2]string{"NextGC", fmt.Sprintf("%d", mStats.NextGC)}) memStats = append(memStats, [2]string{"LastGC", fmt.Sprintf("%d", mStats.LastGC)}) memStats = append(memStats, [2]string{"PauseTotalNs", fmt.Sprintf("%d", mStats.PauseTotalNs)}) memStats = append(memStats, [2]string{"NumGC", fmt.Sprintf("%d", mStats.NumGC)}) environmentStats := [][2]string{} for _, e := range os.Environ() { pair := strings.Split(e, "=") environmentStats = append(environmentStats, [2]string{pair[0], pair[1]}) } request.SetData("stats", stats) request.SetData("configStats", configStats) request.SetData("osStats", osStats) request.SetData("memStats", memStats) request.SetData("environmentStats", environmentStats) request.SetData("admin_yield", "admin_stats") prago.Render(request, 200, "admin_layout") }
func (u User) getRenewURL(request prago.Request, a *Admin) string { urlValues := make(url.Values) urlValues.Add("email", u.Email) urlValues.Add("token", u.emailToken(a.App)) return request.App().Config.GetString("baseUrl") + a.Prefix + "/user/renew_password?" + urlValues.Encode() }