//HomePage shows the home page when logged in, if not, delegate to showing the public website
772019
func (service *Service) HomePage(w http.ResponseWriter, request *http.Request) {

	loggedinuser, err := service.GetLoggedInUser(request, w)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if loggedinuser == "" {
		service.ShowPublicSite(w, request)
		return
	}

	htmlData, err := html.Asset(homepageFileName)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	sessions.Save(request, w)
	w.Write(htmlData)
}
1302214
func (c *IPChannelList) LastPage() (*IPChannelList, error) {
	return c.getPage(c.Meta.LastPageUri)
}
1332091
func (c *ReactionsListCall) Page(page int) *ReactionsListCall {
	c.page = page
	return c
}
723792
func (p *Pager) Pages() Pages {
	if len(p.paginatedElements) == 0 {
		return paginatorEmptyPages
	}

	if pages, ok := p.element().(Pages); ok {
		return pages
	}

	return paginatorEmptyPages
}
1264540
func (l *BasicLayout) MovePage(state *Peco, p PagingRequest) (moved bool) {
	switch p.Type() {
	case ToScrollLeft, ToScrollRight:
		moved = horizontalScroll(state, l, p)
	default:
		moved = verticalScroll(state, l, p)
	}
	return
}
745954
func (self *SimpleIdComponent) Page(pb PBundle, path []string, trailingSlash bool) ComponentResult {

	//allow singular to be used as synonym for plural
	if len(path) == 0 {
		return ComponentResult{
			Path:   "/" + filepath.Join(self.UrlPrefix(), "index.html"),
			Status: http.StatusOK,
		}
	}

	if (len(path) == 1 && path[0] == "new") || (len(path) == 1 && path[0] == "new.html") {
		if self.newcheck != nil {
			ok, err := self.newcheck(pb)
			if err != nil {
				return ComponentResult{
					Status:  http.StatusInternalServerError,
					Message: err.Error(),
				}
			}
			if !ok {
				return ComponentResult{
					Message: "you lose",
					Status:  http.StatusUnauthorized,
				}
			}
		}
		return ComponentResult{
			Path:   "/" + filepath.Join(self.UrlPrefix(), "new.html"),
			Status: http.StatusOK,
		}
	}

	if (len(path) == 1 && path[0] == "index") || (len(path) == 1 && path[0] == "index.html") {
		return ComponentResult{
			Path:   "/" + filepath.Join(self.UrlPrefix(), "index.html"),
			Status: http.StatusOK,
		}
	}

	// parse the id in the URL
	rawId := path[0]
	id, err := strconv.ParseInt(rawId, 10, 64)
	if err != nil {
		//handle the case of /<singular>/new.js
		return ComponentResult{
			Status:           CONTINUE,
			ContinueAt:       self.singular,
			ContinueConsumed: 1,
		}
	}
	if self.exists != nil {
		ok, err := self.exists(pb, id)
		if err != nil {
			return ComponentResult{
				Status:  http.StatusInternalServerError,
				Message: err.Error(),
			}
		}
		if !ok {
			return ComponentResult{
				Status:  http.StatusNotFound,
				Message: fmt.Sprintf("could not find %d", id),
			}
		}
	}

	// show view.html for /foo/1 or /foo/1/
	if len(path) == 1 {
		if self.viewedit != nil {
			ok, err := self.viewedit(pb, id, true)
			if err != nil {
				return ComponentResult{
					Status:  http.StatusInternalServerError,
					Message: err.Error(),
				}
			}
			if !ok {
				return ComponentResult{
					Message: "you lose",
					Status:  http.StatusUnauthorized,
				}
			}
		}
		return ComponentResult{
			Path:   "/" + filepath.Join(self.UrlPrefix(), "view.html"),
			Status: http.StatusOK,
		}
	}

	// see if it's a verb we understand
	if len(path) == 2 {
		verb := path[1]
		switch verb {
		case "edit", "edit.html", "view", "view.html":
			if !strings.HasSuffix(verb, ".html") {
				verb = verb + ".html"
			}
			if self.viewedit != nil {
				ok, err := self.viewedit(pb, id, verb == "view.html")
				if err != nil {
					return ComponentResult{
						Status:  http.StatusInternalServerError,
						Message: err.Error(),
					}
				}
				if !ok {
					return ComponentResult{
						Message: "you lose",
						Status:  http.StatusUnauthorized,
					}
				}
				return ComponentResult{
					Path:   "/" + filepath.Join(self.UrlPrefix(), verb),
					Status: http.StatusOK,
				}

			}
		default:
			return ComponentResult{
				Status:           CONTINUE,
				ContinueAt:       self.UrlPrefix(),
				ContinueConsumed: 2,
			}
		}
	}

	//we don't accept any more parts to the URL
	return ComponentResult{
		Status:  http.StatusBadRequest,
		Message: fmt.Sprintf("Unacceptable url for %s", self.singular),
	}
}
779356
func HomeDir() (home string, err error) {
	if runtime.GOOS == "windows" {
		home = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
		if home == "" {
			home = os.Getenv("USERPROFILE")
		}
	} else {
		home = os.Getenv("HOME")
	}

	if len(home) == 0 {
		return "", errors.New("Cannot specify home directory because it's empty")
	}

	return home, nil
}
978088
func main() {
	// Imports the hello component declared above in order to make it loadable
	// in a page or usable in other components.
	//
	// Imported component can be used as URL or html tags by referencing them by
	// their lowercased names.
	// E.g:
	//  Hello   => hello
	//  foo.Bar => foo.bar
	app.Import(&Hello{})

	// Defines the component to load when an URL without path is loaded.
	app.DefaultPath = "/hello"

	// Runs the app in the browser.
	if err := app.Run(); err != nil {
		log.Print(err)
	}
}
292174
func (exp *explorerUI) ShowingSyncStatusPage() bool {
	display, ok := exp.displaySyncStatusPage.Load().(bool)
	return ok && display
}
1018857
func WithHome(path string) func(*icmd.Cmd) {
	return func(cmd *icmd.Cmd) {
		cmd.Env = append(cmd.Env, "HOME="+path)
	}
}
500540
func (exp *explorerUI) AddressPage(w http.ResponseWriter, r *http.Request) {
	// AddressPageData is the data structure passed to the HTML template

	type AddressPageData struct {
		*CommonPageData
		Data         *dbtypes.AddressInfo
		CRLFDownload bool
		FiatBalance  *exchanges.Conversion
	}

	// Grab the URL query parameters
	address, txnType, limitN, offsetAddrOuts, err := parseAddressParams(r)
	if err != nil {
		exp.StatusPage(w, defaultErrorCode, err.Error(), address, ExpStatusError)
		return
	}

	// Validate the address.
	addr, addrType, addrErr := txhelpers.AddressValidation(address, exp.ChainParams)
	isZeroAddress := addrErr == txhelpers.AddressErrorZeroAddress
	if addrErr != nil && !isZeroAddress {
		var status expStatus
		var message string
		code := defaultErrorCode
		switch addrErr {
		case txhelpers.AddressErrorDecodeFailed, txhelpers.AddressErrorUnknown:
			status = ExpStatusError
			message = "Unexpected issue validating this address."
		case txhelpers.AddressErrorWrongNet:
			status = ExpStatusWrongNetwork
			message = fmt.Sprintf("The address %v is valid on %s, not %s.",
				addr, addr.Net().Name, exp.NetName)
			code = wrongNetwork
		default:
			status = ExpStatusError
			message = "Unknown error."
		}

		exp.StatusPage(w, code, message, address, status)
		return
	}

	// Handle valid but unsupported address types.
	switch addrType {
	case txhelpers.AddressTypeP2PKH, txhelpers.AddressTypeP2SH:
		// All good.
	case txhelpers.AddressTypeP2PK:
		message := "Looks like you are searching for an address of type P2PK."
		exp.StatusPage(w, defaultErrorCode, message, address, ExpStatusP2PKAddress)
		return
	default:
		message := "Unsupported address type."
		exp.StatusPage(w, defaultErrorCode, message, address, ExpStatusNotSupported)
		return
	}

	// Retrieve address information from the DB and/or RPC.
	var addrData *dbtypes.AddressInfo
	if isZeroAddress {
		// For the zero address (e.g. DsQxuVRvS4eaJ42dhQEsCXauMWjvopWgrVg),
		// short-circuit any queries.
		addrData = &dbtypes.AddressInfo{
			Address:         address,
			Net:             addr.Net().Name,
			IsDummyAddress:  true,
			Balance:         new(dbtypes.AddressBalance),
			UnconfirmedTxns: new(dbtypes.AddressTransactions),
		}
	} else {
		addrData, err = exp.AddressListData(address, txnType, limitN, offsetAddrOuts)
		if exp.timeoutErrorPage(w, err, "TicketsPriceByHeight") {
			return
		} else if err != nil {
			exp.StatusPage(w, defaultErrorCode, err.Error(), address, ExpStatusError)
			return
		}
	}

	// Set page parameters.
	addrData.IsDummyAddress = isZeroAddress // may be redundant
	addrData.Path = r.URL.Path

	// If exchange monitoring is active, prepare a fiat balance conversion
	conversion := exp.xcBot.Conversion(dcrutil.Amount(addrData.Balance.TotalUnspent).ToCoin())

	// For Windows clients only, link to downloads with CRLF (\r\n) line
	// endings.
	UseCRLF := strings.Contains(r.UserAgent(), "Windows")

	// Execute the HTML template.
	pageData := AddressPageData{
		CommonPageData: exp.commonData(r),
		Data:           addrData,
		CRLFDownload:   UseCRLF,
		FiatBalance:    conversion,
	}
	str, err := exp.templates.execTemplateToString("address", pageData)
	if err != nil {
		log.Errorf("Template execute failure: %v", err)
		exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "", ExpStatusError)
		return
	}

	w.Header().Set("Content-Type", "text/html")
	w.Header().Set("Turbolinks-Location", r.URL.RequestURI())
	w.WriteHeader(http.StatusOK)
	io.WriteString(w, str)
}
1162316
func (c *IPMemberList) PreviousPage() (*IPMemberList, error) {
	if !c.HasPreviousPage() {
		return nil, Error{"No previous page"}
	}

	return c.getPage(c.Meta.NextPageUri)
}
1288131
func (exp *explorerUI) NextHome(w http.ResponseWriter, r *http.Request) {
	// Get top N blocks and trim each block to have just the fields required for
	// this page.
	height, err := exp.blockData.GetHeight()
	if err != nil {
		log.Errorf("GetHeight failed: %v", err)
		exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "",
			ExpStatusError)
		return
	}
	blocks := exp.blockData.GetExplorerFullBlocks(int(height),
		int(height)-homePageBlocksMaxCount)

	// trim unwanted data in each block
	trimmedBlocks := make([]*types.TrimmedBlockInfo, 0, len(blocks))
	for _, block := range blocks {
		trimmedBlock := &types.TrimmedBlockInfo{
			Time:         block.BlockTime,
			Height:       block.Height,
			Total:        block.TotalSent,
			Fees:         block.MiningFee,
			Subsidy:      block.Subsidy,
			Votes:        block.Votes,
			Tickets:      block.Tickets,
			Revocations:  block.Revs,
			Transactions: types.FilterRegularTx(block.Tx),
		}

		trimmedBlocks = append(trimmedBlocks, trimmedBlock)
	}

	// Construct the required TrimmedMempoolInfo from the shared inventory.
	inv := exp.MempoolInventory()
	mempoolInfo := inv.Trim() // Trim internally locks the MempoolInfo.

	exp.pageData.RLock()
	mempoolInfo.Subsidy = exp.pageData.HomeInfo.NBlockSubsidy

	str, err := exp.templates.execTemplateToString("nexthome", struct {
		*CommonPageData
		Info    *types.HomeInfo
		Mempool *types.TrimmedMempoolInfo
		Blocks  []*types.TrimmedBlockInfo
	}{
		CommonPageData: exp.commonData(r),
		Info:           exp.pageData.HomeInfo,
		Mempool:        mempoolInfo,
		Blocks:         trimmedBlocks,
	})

	exp.pageData.RUnlock()

	if err != nil {
		log.Errorf("Template execute failure: %v", err)
		exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "", ExpStatusError)
		return
	}
	w.Header().Set("Content-Type", "text/html")
	w.WriteHeader(http.StatusOK)
	io.WriteString(w, str)
}
1364642
func (p *PushEventRepository) GetHomepage() string {
	if p == nil || p.Homepage == nil {
		return ""
	}
	return *p.Homepage
}
867803
func (r *Repository) GetHomepage() string {
	if r == nil || r.Homepage == nil {
		return ""
	}
	return *r.Homepage
}
868123
func (s *IPRoleList) PreviousPage() (*IPRoleList, error) {
	if !s.HasPreviousPage() {
		return nil, Error{"No previous page"}
	}

	return s.getPage(s.Meta.NextPageUri)
}
1030845
func mainPage(w *rest.ResponseWriter, r *rest.Request) {
	noCache(w)
	http.ServeFile(
		w.ResponseWriter,
		r.Request,
		staticRoot()+"/index.html")
}