当前位置: 首页>>代码示例>>Golang>>正文


Golang user.LogoutURL函数代码示例

本文整理汇总了Golang中google/golang.org/appengine/user.LogoutURL函数的典型用法代码示例。如果您正苦于以下问题:Golang LogoutURL函数的具体用法?Golang LogoutURL怎么用?Golang LogoutURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LogoutURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetUserInfoHandler

// GetUserInfoHandler returns either the location where the user can log into
// the app, or metadata about the currently authenticated user.
func GetUserInfoHandler(w util.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)

	dest := mux.Vars(r)["dest"]
	if dest == "" {
		dest = "/"
	}

	if u == nil {
		url, err := user.LoginURL(c, dest)
		w.WriteJSON(map[string]interface{}{"loginURL": url}, err)
		return
	}

	// Check if the user exists in the database
	q := datastore.NewQuery("Users").Limit(1)
	q.Filter("GoogleID = ", u.ID)

	var results []User
	keys, err := q.GetAll(c, &results)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if len(results) == 0 {
		newUser := User{
			GoogleID:    u.ID,
			CreatedTime: time.Now(),
			Email:       u.Email,
		}

		key := datastore.NewIncompleteKey(c, "Users", nil)
		newKey, err := datastore.Put(c, key, &newUser)

		if newKey != nil {
			newUser.ID = newKey.IntID()
		}

		url, _ := user.LogoutURL(c, dest)
		newUser.LogoutURL = url
		w.WriteJSON(newUser, err)
		return
	}

	url, _ := user.LogoutURL(c, dest)

	fullUser := results[0]
	fullUser.ID = keys[0].IntID()
	fullUser.LogoutURL = url

	w.WriteJSON(fullUser, nil)
}
开发者ID:tgrosinger,项目名称:mac-and-cheese,代码行数:56,代码来源:user.go

示例2: rootHandler

func rootHandler(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)
	u := user.Current(ctx)
	if u == nil {
		url, _ := user.LoginURL(ctx, "/")
		fmt.Fprintf(w, `<a href="%s">Sign in or register</a>`, url)
		return
	}

	fmt.Fprint(w, `<html><h1>Hi! Welcome to Tada</h1>`)

	fmt.Fprint(w, "<!-- About to call writeItems -->")

	fmt.Fprint(w, `<ol>`)
	writeItems(w, r, u)
	fmt.Fprint(w, `</ol>`)

	fmt.Fprint(w, "<!-- Called writeItems -->")

	url, _ := user.LogoutURL(ctx, "/")
	fmt.Fprintf(w, `Welcome, %s! (<a href="%s">sign out</a>)`, u, url)

	fmt.Fprint(w, `</html>`)

	makeNewItemForm(w)
}
开发者ID:catamorphism,项目名称:tada,代码行数:26,代码来源:tada.go

示例3: GetUser

// Retrieve User object and return the user's email
// If the user is logged in, return a logout URL so
// the user can logout
func GetUser(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	u := user.Current(c)
	localUser := new(User)

	if u == nil {
		url, _ := user.LoginURL(c, "/")

		localUser.Url = url
		data, err := json.MarshalIndent(localUser, "", "\t")
		if err != nil {
			panic(err)
		}

		w.Write(data)
		return
	}

	url, _ := user.LogoutURL(c, "/")

	localUser.Url = url
	localUser.Email = u.Email
	data, err := json.MarshalIndent(localUser, "", "\t")
	if err != nil {
		panic(err)
	}

	w.Write(data)
}
开发者ID:Ymihere03,项目名称:bodger-bowl,代码行数:33,代码来源:user.go

示例4: loginWithGoogle

func loginWithGoogle() gin.HandlerFunc {
	return func(c *gin.Context) {
		ctx := appengine.NewContext(c.Request)
		u := user.Current(ctx)
		if u == nil {
			url, _ := user.LoginURL(ctx, c.Request.URL.String())
			c.HTML(302, "login.tmpl", gin.H{
				"url": url,
			})
			c.Abort()
			return
		}
		email := strings.Split(u.Email, "@")
		if email[1] == "elo7.com" && len(email) == 2 {
			developer := models.Developer{Email: u.Email}
			developer.Create(&db)

			log.Infof(ctx, developer.Email)
		} else {
			url, _ := user.LogoutURL(ctx, "/")
			c.Redirect(http.StatusTemporaryRedirect, url)
		}
		c.Next()
	}
}
开发者ID:mottam,项目名称:goploy,代码行数:25,代码来源:goploy.go

示例5: index

func index(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	// user.Current gives data about what the requester is
	// logged in as, or nil if they are not logged in.
	u := user.Current(ctx)

	var model indexModel

	// If they are not nil, they are logged in.
	if u != nil {
		// So let the template know, and get the logout url.
		model.Login = true
		logoutURL, err := user.LogoutURL(ctx, "/")
		if err != nil {
			log.Errorf(ctx, err.Error())
			http.Error(res, "Server Error", http.StatusInternalServerError)
			return
		}
		model.LogoutURL = logoutURL
	} else {
		// Otherwise, get the login url.
		loginURL, err := user.LoginURL(ctx, "/")
		if err != nil {
			log.Errorf(ctx, err.Error())
			http.Error(res, "Server Error", http.StatusInternalServerError)
			return
		}
		model.LoginURL = loginURL
	}
	tpl.ExecuteTemplate(res, "index", model)
}
开发者ID:Oralordos,项目名称:DevFest-2015,代码行数:31,代码来源:main.go

示例6: Api1UserProfileHandler

// If the user is not logged in, then return the login url.  Otherwise return a json
// structure containing the user's name and email address, and which team they are on.
func Api1UserProfileHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")

	data := UserProfileData{}
	ctx := appengine.NewContext(r)
	u := user.Current(ctx)
	if u == nil {
		url, _ := user.LoginURL(ctx, "/")
		data.LoginUrl = url
		datajson, err := json.Marshal(data)
		if err != nil {
			http.Error(w, "Internal Service Error", http.StatusInternalServerError)
			return
		}
		fmt.Fprintf(w, "%s", datajson)
		return
	}
	url, _ := user.LogoutURL(ctx, "/")
	data.LogoutUrl = url
	data.Email = u.Email
	data.IsAdmin = u.Admin
	data.IsLoggedIn = true
	datajson, err := json.Marshal(data)
	if err != nil {
		http.Error(w, "Internal Service Error", http.StatusInternalServerError)
		return
	}

	fmt.Fprintf(w, "%s", datajson)
}
开发者ID:dherbst,项目名称:lmjrfll,代码行数:32,代码来源:api.go

示例7: admin

func admin(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	u := user.Current(ctx)
	url, _ := user.LogoutURL(ctx, "/")
	res.Header().Set("Content-Type", "text/html")
	fmt.Fprintf(res, `Welcome ADMIN, %s! <br>`, u.Email)
	fmt.Fprintf(res, `(<a href="%s">sign out</a>)`, url)
}
开发者ID:RobertoSuarez,项目名称:GolangTraining,代码行数:8,代码来源:main.go

示例8: logout

func logout(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	http.SetCookie(res, &http.Cookie{Name: "logged_in", Value: "", MaxAge: -1})
	url, err := user.LogoutURL(ctx, "/")
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
	http.Redirect(res, req, url, 302)
}
开发者ID:RamzesSoft,项目名称:GolangTraining,代码行数:10,代码来源:routes.go

示例9: welcome

func welcome(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-type", "text/html; charset=utf-8")
	ctx := appengine.NewContext(r)
	u := user.Current(ctx)
	if u == nil {
		url, _ := user.LoginURL(ctx, "/")
		fmt.Fprintf(w, `<a href="%s">Sign in or register</a>`, url)
		return
	}
	url, _ := user.LogoutURL(ctx, "/")
	fmt.Fprintf(w, `Welcome, %s! (<a href="%s">sign out</a>)`, u, url)
}
开发者ID:wuman,项目名称:golang-samples,代码行数:12,代码来源:users.go

示例10: index

func index(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	u := user.Current(ctx)
	url, _ := user.LogoutURL(ctx, "/")
	res.Header().Set("Content-Type", "text/html")
	fmt.Fprintf(res, `Welcome, %s! <br>`, u.Email)
	fmt.Fprintf(res, `You are admin: %v  <br>`, u.Admin)
	if u.Admin {
		fmt.Fprint(res, `(<a href="/admin">go to admin</a>) <br>`)
	}
	fmt.Fprintf(res, `(<a href="%s">sign out</a>)`, url)
}
开发者ID:RobertoSuarez,项目名称:GolangTraining,代码行数:12,代码来源:main.go

示例11: mainHandler

// mainHandler tracks how many times each user has visited this page.
func mainHandler(w http.ResponseWriter, r *http.Request) *appError {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return nil
	}

	ctx := appengine.NewContext(r)
	u := user.Current(ctx)
	if u == nil {
		login, err := user.LoginURL(ctx, r.URL.String())
		if err != nil {
			return &appError{err, "Error finding login URL", http.StatusInternalServerError}
		}
		http.Redirect(w, r, login, http.StatusFound)
		return nil
	}
	logoutURL, err := user.LogoutURL(ctx, "/")
	if err != nil {
		return &appError{err, "Error finding logout URL", http.StatusInternalServerError}
	}

	// Increment visit count for user.
	tbl := client.Open(tableName)
	rmw := bigtable.NewReadModifyWrite()
	rmw.Increment(familyName, u.Email, 1)
	row, err := tbl.ApplyReadModifyWrite(ctx, u.Email, rmw)
	if err != nil {
		return &appError{err, "Error applying ReadModifyWrite to row: " + u.Email, http.StatusInternalServerError}
	}
	data := struct {
		Username, Logout string
		Visits           uint64
	}{
		Username: u.Email,
		// Retrieve the most recently edited column.
		Visits: binary.BigEndian.Uint64(row[familyName][0].Value),
		Logout: logoutURL,
	}

	// Display hello page.
	var buf bytes.Buffer
	if err := tmpl.Execute(&buf, data); err != nil {
		return &appError{err, "Error writing template", http.StatusInternalServerError}
	}
	buf.WriteTo(w)
	return nil
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:48,代码来源:main.go

示例12: logOutHandler

func logOutHandler(w http.ResponseWriter, r *http.Request, s string) {
	ctx := appengine.NewContext(r)
	url, err := user.LogoutURL(ctx, "/")
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	// Deleting session cookie
	var cookie *http.Cookie
	cookie, err = r.Cookie(s)
	if err != http.ErrNoCookie {
		cookie.MaxAge = -1
		http.SetCookie(w, cookie)
	}
	//  CHANGE NECESSARY DB FIELDS OF USER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	http.Redirect(w, r, url, http.StatusFound)
}
开发者ID:MerinEREN,项目名称:InceIs,代码行数:17,代码来源:inceis.go

示例13: handleMainPage

func handleMainPage(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Error(w, "GET requests only", http.StatusMethodNotAllowed)
		return
	}
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}

	c := appengine.NewContext(r)
	tic := time.Now()
	q := datastore.NewQuery("Greeting").Ancestor(guestbookKey(c)).Order("-Date").Limit(10)
	var gg []*Greeting
	_, err := q.GetAll(c, &gg)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		c.Errorf("GetAll: %v", err)
		return
	}
	c.Infof("Datastore lookup took %s", time.Since(tic).String())
	c.Infof("Rendering %d greetings", len(gg))

	var email, logout, login string
	if u := user.Current(c); u != nil {
		logout, _ = user.LogoutURL(c, "/")
		email = u.Email
	} else {
		login, _ = user.LoginURL(c, "/")
	}
	data := struct {
		Greetings            []*Greeting
		Login, Logout, Email string
	}{
		Greetings: gg,
		Login:     login,
		Logout:    logout,
		Email:     email,
	}
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	if err := tpl.ExecuteTemplate(w, "guestbook.html", data); err != nil {
		c.Errorf("%v", err)
	}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:44,代码来源:guestbook.go

示例14: init

func init() {
	r := gin.New()
	r.LoadHTMLGlob("templates/*")
	r.Use(sessions.Sessions("session_id", store))
	r.Static("/assets", "./assets")

	r.Use(gin.Recovery())
	v1 := r.Group("api/v1")
	v1.Use(loginWithGoogle())
	{
		v1.GET("/systems", controllers.GetSystems)
		v1.POST("/systems", controllers.CreateSystem)
		v1.GET("/systems/:id", controllers.GetSystem)
		v1.PUT("/systems/:id", controllers.UpdateSystem)
		v1.DELETE("/systems/:id", controllers.DeleteSystem)

		v1.GET("/developers", controllers.UpdatePage)
		v1.POST("/developers", controllers.UpdateDeveloper)

		v1.GET("/deploys", controllers.GetDeploys)
		v1.POST("/deploys", controllers.CreateDeploy)
	}
	r.Use(loginWithGoogle())
	r.Use(updateDevPending())
	{
		r.GET("/", func(c *gin.Context) {
			c.HTML(http.StatusOK, "index.tmpl", gin.H{})
		})
	}
	r.GET("/logout", func(c *gin.Context) {
		ctx := appengine.NewContext(c.Request)
		url, _ := user.LogoutURL(ctx, "/")
		c.Redirect(http.StatusTemporaryRedirect, url)
	})
	http.Handle("/", r)

	/*
		Use this for https instead of r.Run()
		r.RunTLS(":8080", pathToCertFile, pathToKeyFile)
	*/
}
开发者ID:mottam,项目名称:goploy,代码行数:41,代码来源:goploy.go

示例15: listHandler

func listHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
		return
	}
	var (
		c = appengine.NewContext(r)
		d listTemplateData
	)
	if _, err := memcache.Gob.Get(c, cacheKey, &d); err != nil {
		if err == memcache.ErrCacheMiss {
			log.Debugf(c, "cache miss")
		} else {
			log.Errorf(c, "cache get error: %v", err)
		}

		var fs []File
		_, err := datastore.NewQuery("File").Ancestor(rootKey(c)).GetAll(c, &fs)
		if err != nil {
			log.Errorf(c, "error listing: %v", err)
			return
		}
		d.Stable, d.Unstable = filesToReleases(fs)
		if len(d.Stable) > 0 {
			d.Featured = filesToFeatured(d.Stable[0].Files)
		}

		d.LoginURL, _ = user.LoginURL(c, "/dl")
		if user.Current(c) != nil {
			d.LoginURL, _ = user.LogoutURL(c, "/dl")
		}

		item := &memcache.Item{Key: cacheKey, Object: &d, Expiration: cacheDuration}
		if err := memcache.Gob.Set(c, item); err != nil {
			log.Errorf(c, "cache set error: %v", err)
		}
	}
	if err := listTemplate.ExecuteTemplate(w, "root", d); err != nil {
		log.Errorf(c, "error executing template: %v", err)
	}
}
开发者ID:barthy1,项目名称:s3cli,代码行数:41,代码来源:dl.go


注:本文中的google/golang.org/appengine/user.LogoutURL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。