func docs(ctx *macaron.Context, locale i18n.Locale, name string) { docRoot := models.GetDocByLocale(name, locale.Lang) if docRoot == nil { docRoot = models.GetDocByLocale(name, "en-US") } link := strings.TrimPrefix(ctx.Params("*"), "/") link = strings.TrimSuffix(link, ".html") link = strings.TrimSuffix(link, ".md") ctx.Data["Link"] = "/docs/" + link var doc *models.DocNode if len(link) == 0 { ctx.Redirect("/docs/intro/") return } doc, _ = docRoot.GetNodeByLink(link) if doc == nil { doc, _ = docRoot.GetNodeByLink(link + "/") } if doc == nil { ctx.Error(404) return } ctx.Data["DocRoot"] = docRoot ctx.Data["Doc"] = doc ctx.Data["Title"] = doc.Name ctx.Data["Data"] = doc.GetContent() ctx.HTML(200, "document_"+name, ctx.Data) }
//process post alipay return func AlipayReturn(ctx *macaron.Context, x *xorm.Engine) { m, _ := url.ParseQuery(ctx.Req.URL.RawQuery) params := map[string]string{} for k, v := range m { params[k] = v[0] } result := alipay.Return(params) type OrderInfo struct { Result bool OrderId string GoodId string GoodCnt int64 Tel string Name string Addr string Sum float32 } var orderInfo OrderInfo orderInfo.Result = false if result.Status == -1 || result.Status == -5 || result.Status == -3 { ctx.HTML(400, "orderresult", orderInfo) return } o := &Order{Uuid: result.OrderNo} has, err := x.Where("status=?", "等待支付").Get(o) if err != nil || !has { ctx.HTML(400, "orderresult", orderInfo) return } if result.Status != 1 { o.Status = "支付失败" x.Id(o.Id).Cols("status").Update(o) ctx.HTML(400, "orderresult", orderInfo) return } o.Status = "支付成功" _, err = x.Id(o.Id).Cols("status").Update(o) if err != nil { ctx.HTML(400, "orderresult", orderInfo) return } orderInfo.Result = true orderInfo.OrderId = o.CusTel + "_" + strconv.FormatInt(o.Id, 10) orderInfo.GoodId = strconv.FormatInt(o.GoodId, 10) orderInfo.GoodCnt = o.GoodCnt orderInfo.Tel = o.CusTel orderInfo.Name = o.CusName orderInfo.Addr = o.CusAddr orderInfo.Sum = o.Sum ctx.HTML(200, "orderresult", orderInfo) return }
func DoPupDetail(ctx *macaron.Context) { id := ctx.Query("Id") pup := findPup(id) if pup != nil { ctx.Data["IsPup"] = true ctx.Data["Pup"] = pup ctx.HTML(200, "showDetail") } }
func DoDogDetail(ctx *macaron.Context) { id := ctx.Query("Id") dog := findDog(id) if dog != nil { ctx.Data["IsDog"] = true ctx.Data["Dog"] = dog ctx.HTML(200, "showDetail") } }
func Build(tokens oauth2.Tokens, ctx *macaron.Context, req *http.Request) { gh := github.New(tokens.Access()) user, err := gh.User() if err != nil { ctx.Error(500, err.Error()) return } muser := &models.User{ Name: user.Name, Email: user.Email, GithubToken: tokens.Access(), Admin: false, } models.DB.Insert(muser) // repos var repos []*github.Repository reposKey := "orgs:" + user.Login + ":repos" if !rdx.Exists(reposKey).Val() || req.FormValue("refresh") != "" { var err error repos, err = gh.Repositories() if err != nil { ctx.Error(500, err.Error()) return } for _, repo := range repos { rdx.HMSet(reposKey, repo.Fullname, "") } } else { for _, repoName := range rdx.HKeys(reposKey).Val() { repos = append(repos, &github.Repository{ Fullname: repoName, }) } } // token rdx.Set("user:"******":github_token", tokens.Access(), 0) tokenKey := "user:"******":token" if !rdx.Exists(tokenKey).Val() { rdx.Set(tokenKey, "gr"+goutils.RandNString(40), 0) } token := rdx.Get(tokenKey).Val() rdx.Set("token:"+token+":user", user.Login, 0) ctx.Data["User"] = user ctx.Data["Token"] = token ctx.Data["Repos"] = repos ctx.HTML(200, "build") }
func OnSignin(ctx *macaron.Context, f *session.Flash) { userName := ctx.Query("username") Password := ctx.Query("password") c := db.C("Account") account := Account{} err := c.Find(bson.M{"UserName": userName, "Password": Password}).One(&account) if err != nil { ctx.Data["Title"] = "出错啦!" ctx.Data["Info"] = "您的账户或密码错误,登录失败啦!" ctx.HTML(200, "info") } ctx.Data["Admin"] = account.Role == 1 ctx.Data["Comments"] = getComments() ctx.HTML(200, "profile") }
func Team(ctx *macaron.Context, locale i18n.Locale) { ctx.Data["Link"] = "/team" df := models.GetDoc( "gitea", "team", locale.Lang) if df == nil { ctx.Error(404) return } ctx.Data["Data"] = string(df.Data) ctx.HTML(200, "page", ctx.Data) }
func Docs(ctx *macaron.Context, locale i18n.Locale) { docRoot := models.GetDocByLocale( "gitea", locale.Lang) if docRoot == nil { ctx.Error(404) return } link := strings.TrimSuffix( strings.TrimSuffix( strings.TrimPrefix( ctx.Params("*"), "/"), ".html"), ".md") ctx.Data["Link"] = "/docs/" + link if len(link) == 0 { ctx.Redirect("/docs/intro/") return } doc, _ := docRoot.GetNodeByLink(link) if doc == nil { doc, _ = docRoot.GetNodeByLink(link + "/") } if doc == nil { ctx.Error(404) return } ctx.Data["DocRoot"] = docRoot ctx.Data["Doc"] = doc ctx.Data["Title"] = doc.Name ctx.Data["Data"] = doc.GetContent() ctx.HTML(200, "gitea", ctx.Data) }
func OnComment(ctx *macaron.Context) { title := ctx.Query("title") content := ctx.Query("content") c := db.C("Comment") comment := Comment{} comment.Id = bson.NewObjectId() comment.Title = title comment.Content = content comment.DateTime = time.Now() err := c.Insert(comment) if err != nil { panic(err) } // resp := response.NewText("oMl6fs9C4x583NvZJfTcJxqvcomw", "", comment.DateTime, "["+comment.Title+"]"+comment.Content) // mp.WriteRawResponse(ctx.Resp, nil, resp) ctx.Data["Title"] = "成功啦!" ctx.Data["Info"] = "您的留言已经第一时间发送出去啦!" ctx.HTML(200, "info") }
func DoComment(ctx *macaron.Context) { ctx.HTML(200, "comment") }
func DoAbout(ctx *macaron.Context) { ctx.Data["Global"] = getGlobal() ctx.HTML(200, "about") }
func DoDogs(ctx *macaron.Context) { ctx.Data["Title"] = "种犬展示" ctx.Data["Dogs"] = getDogs() ctx.HTML(200, "showList") }
func DoPups(ctx *macaron.Context) { ctx.Data["Title"] = "待售幼犬" ctx.Data["Pups"] = getPups() ctx.HTML(200, "showList") }
func DashboardHandler(ctx *macaron.Context) { ctx.HTML(200, "dashboard") }
func myHandler(ctx *macaron.Context) { ctx.Data["Name"] = "Person" ctx.HTML(200, "hello") // 200 is the response code. }
func GogsHome(ctx *macaron.Context) { ctx.Data["IsPageHome"] = true ctx.HTML(200, "home_gogs", ctx.Data) }
func Donate(ctx *macaron.Context, locale i18n.Locale) { ctx.Data["Link"] = "/donate" df := models.GetDoc("gogs", "donate", locale.Lang) ctx.Data["Data"] = string(df.Data) ctx.HTML(200, "page", ctx.Data) }
func mySubmitHandler(ctx *macaron.Context, contact ContactForm) { submission := ContactEntry{0, contact.Name, contact.Email, contact.Message, contact.MailingAddress} // ctx.JSON(200, &submission) ctx.Data["Submission"] = &submission ctx.HTML(200, "success") }
func myQueryStringHandler(ctx *macaron.Context) { ctx.Data["Name"] = ctx.QueryEscape("name") ctx.HTML(200, "hello") }
func myOtherHandler(ctx *macaron.Context) { ctx.Data["Message"] = "the request path is: " + ctx.Req.RequestURI ctx.HTML(200, "welcome") }
func SettingHandler(ctx *macaron.Context) { ctx.HTML(200, "setting") }
func DoSignin(ctx *macaron.Context) { ctx.HTML(200, "signin") }
func AdminAuthHandler(ctx *macaron.Context) { ctx.HTML(200, "admin/auth") }
func NewsHandler(ctx *macaron.Context) { ctx.HTML(200, "news") }
func Homepage(ctx *macaron.Context) { ctx.Data["Host"] = ctx.Req.Host ctx.HTML(200, "homepage") }
func IndexHandler(ctx *macaron.Context) { ctx.HTML(200, "index") }
// Home returns main page func Home(ctx *macaron.Context) { ctx.Data["Version"] = viper.GetString("version") ctx.Data["GitlabHost"] = viper.GetString("gitlab.url") ctx.HTML(200, "templates/index") }