func (us *Users) GET(c *kocha.Context) error { var n int var users []model.User num, _ := GetPerItem(c) currentPage, _ := GetPageNum(c) page := currentPage if page > 0 { page-- } dbInst := db.Get("default") condition := dbInst.OrderBy("id", genmai.DESC).Limit(num).Offset(page * num) err := dbInst.Select(&users, condition) if err == nil { if page > 0 && len(users) == 0 { c.Redirect("/users", false) } err = dbInst.Select(&n, dbInst.Count(), dbInst.From(&model.User{})) } if err != nil { c.RenderError(500, err, nil) } pagination, _ := simpagin.New(currentPage, n, num, DEFAULT_PER_PAGE) return c.Render(map[string]interface{}{ "ControllerName": "Users", "users": users, "totalPage": int(math.Ceil(float64(n) / float64(num))), "pagination": pagination, }) }
func (qu *Queues) GET(c *kocha.Context) error { var n int var queues []Queue num, _ := GetPerItem(c) currentPage, _ := GetPageNum(c) page := currentPage if page > 0 { page-- } dbInst := db.Get("default") rows, err := dbInst.DB().Query(` SELECT queues.id, status, screen_name, tweet_id, action, execute_time, fail_count, queues.created_at, queues.updated_at FROM queues JOIN users ON user_id = users.id ORDER BY id DESC LIMIT ? OFFSET ? `, num, page*num) if err == nil { defer rows.Close() for rows.Next() { var queue Queue if err := rows.Scan( &queue.Id, &queue.Status, &queue.ScreenName, &queue.TweetId, &queue.Action, &queue.ExecuteTime, &queue.FailCount, &queue.CreatedAt, &queue.UpdatedAt, ); err != nil { panic(err) } queues = append(queues, queue) } if page > 0 && len(queues) == 0 { c.Redirect("/queues", false) } err = dbInst.Select(&n, dbInst.Count(), dbInst.From(&model.Queue{})) } if err != nil { c.RenderError(500, err, nil) } pagination, _ := simpagin.New(currentPage, n, num, DEFAULT_PER_PAGE) return c.Render(map[string]interface{}{ "ControllerName": "Queues", "queues": queues, "totalPage": int(math.Ceil(float64(n) / float64(num))), "pagination": pagination, }) }
func (au *Auth) GET(c *kocha.Context) error { client := twitter.GetClient() callbackUrl := kocha.Getenv("RETWITTER_TWITTER_CALLBACK", "") requestToken, url, err := client.GetRequestTokenAndUrl(callbackUrl) if err != nil { return c.RenderError(500, err, nil) } c.Session.Set("requestToken.Token", requestToken.Token) c.Session.Set("requestToken.Secret", requestToken.Secret) return c.Redirect(url, false) }
func (au *AuthCallback) GET(c *kocha.Context) error { oauthVerifier := c.Params.Get("oauth_verifier") requestToken := au.GetRequestToken(c) if oauthVerifier != "" && requestToken != nil { client := twitter.GetClient() accessToken, err := client.AuthorizeToken(requestToken, oauthVerifier) if err == nil { err = model.RegisterUser(accessToken) } if err != nil { return c.RenderError(500, err, nil) } } return c.Redirect("/users", false) }
func (r *Root) GET(c *kocha.Context) error { return c.Redirect("/users", false) }