Exemple #1
0
func (s *SampleHandler) HandleHTTP(ctx context.Context,
	w webhelp.ResponseWriter, r *http.Request) error {
	tokens, err := s.Group.Tokens(ctx)
	if err != nil {
		return err
	}
	w.Header().Set("Content-Type", "text/html")
	if s.Restricted {
		fmt.Fprintf(w, `<h3>Restricted</h3>`)
	}
	if len(tokens) > 0 {
		fmt.Fprintf(w, `
	    <p>Logged in with:
      	<ul>
  	`)
		for name := range tokens {
			fmt.Fprintf(w, `
		    <li>%s (<a href="%s">logout</a>)</li>
	    `, name, s.Group.LogoutURL(name, "/"))
		}
		fmt.Fprintf(w, `
		    <li><a href="%s">logout all</a></li>
	    `, s.Group.LogoutAllURL("/"))
		fmt.Fprintf(w, `
		  </ul></p>`)
	} else {
		fmt.Fprintf(w, `
	    <p>Not logged in</p>
    `)
	}

	login_possible := false
	for name := range s.Group.Providers() {
		_, logged_in := tokens[name]
		if !logged_in {
			login_possible = true
			break
		}
	}

	if login_possible {
		fmt.Fprintf(w, "<p>Log in with:<ul>")
	}
	for name, provider := range s.Group.Providers() {
		_, logged_in := tokens[name]
		if logged_in {
			continue
		}
		fmt.Fprintf(w, `<li><a href="%s">%s</a></li>`,
			provider.LoginURL(r.RequestURI, false), name)
	}
	fmt.Fprintf(w, "</ul></p>")

	if !s.Restricted {
		fmt.Fprintf(w, `
	    <p><a href="/restricted">Restricted</a></p>
    `)
	}
	return nil
}
Exemple #2
0
func (s *SampleHandler) HandleHTTP(ctx context.Context,
	w webhelp.ResponseWriter, r *http.Request) error {
	t, err := s.Prov.Token(ctx)
	if err != nil {
		return err
	}
	w.Header().Set("Content-Type", "text/html")
	if s.Restricted {
		fmt.Fprintf(w, `<h3>Restricted</h3>`)
	}
	if t != nil {
		fmt.Fprintf(w, `
		  <p>Logged in | <a href="%s">Log out</a></p>
	  `, s.Prov.LogoutURL("/"))
	} else {
		fmt.Fprintf(w, `
		  <p><a href="%s">Log in</a> | Logged out</p>
	  `, s.Prov.LoginURL(r.RequestURI, false))
	}
	if !s.Restricted {
		fmt.Fprintf(w, `
	    <p><a href="/restricted">Restricted</a></p>
    `)
	}
	return nil
}
Exemple #3
0
func (l *LoginHandler) HandleHTTP(ctx context.Context,
	w webhelp.ResponseWriter, r *http.Request) error {
	w.Header().Set("Content-Type", "text/html")
	fmt.Fprintf(w, `<h3>Login required</h3>`)
	fmt.Fprintf(w, "<p>Log in with:<ul>")
	for name, provider := range l.Group.Providers() {
		fmt.Fprintf(w, `<li><a href="%s">%s</a></li>`,
			provider.LoginURL(r.FormValue("redirect_to"), false), name)
	}
	fmt.Fprintf(w, "</ul></p>")
	return nil
}