• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang user.LoginURL函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: APIKeyAddHandler

func APIKeyAddHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		loginUrl, _ := user.LoginURL(c, r.URL.RequestURI())
		http.Redirect(w, r, loginUrl, http.StatusFound)
		return
	} else {
		if !u.Admin {
			w.WriteHeader(http.StatusForbidden)
			w.Write([]byte("You're not an admin. Go away."))
		} else {
			key := randomString(26)
			owner := r.FormValue("owner")

			if owner == "" {
				w.Write([]byte("You forgot a parameter."))
			} else {
				apiKey := APIKey{
					APIKey:     key,
					OwnerEmail: owner,
				}
				dkey := datastore.NewIncompleteKey(c, "APIKey", nil)
				_, err := datastore.Put(c, dkey, &apiKey)
				if err != nil {
					w.Write([]byte(fmt.Sprintf("error! %s", err.Error())))
				} else {
					w.Write([]byte(key))

				}
			}
		}
	}
}
开发者ID:jordonwii,项目名称:hms,代码行数:34,代码来源:hms.go


示例2: 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


示例3: 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


示例4: 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


示例5: 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


示例6: editHandler

func editHandler(w http.ResponseWriter, r *http.Request) {
	//For now identify by the ThreadId since each submission will have a unique one
	strVal := r.FormValue("thread")

	//TODO update with YAML require login to not need to check the user status

	c := appengine.NewContext(r)
	u := user.Current(c)

	if u == nil {
		url, err := user.LoginURL(c, r.URL.String())
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Location", url)
		w.WriteHeader(http.StatusFound)
		return
	}

	page := template.Must(template.ParseFiles(
		"public/templates/_base_edit.html",
		"public/templates/edit.html",
	))

	data := struct{ ThreadId string }{strVal}

	if err := page.Execute(w, data); err != nil {
		serveError(c, w, err)
		fmt.Fprintf(w, "\n%v\n%v", err.Error(), data)
		return
	}
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:33,代码来源:main.go


示例7: appstatsHandler

func appstatsHandler(w http.ResponseWriter, r *http.Request) {
	ctx := storeContext(appengine.NewContext(r))
	if appengine.IsDevAppServer() {
		// noop
	} else if u := user.Current(ctx); u == nil {
		if loginURL, err := user.LoginURL(ctx, r.URL.String()); err == nil {
			http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
		} else {
			serveError(w, err)
		}
		return
	} else if !u.Admin {
		http.Error(w, "Forbidden", http.StatusForbidden)
		return
	}

	if detailsURL == r.URL.Path {
		details(ctx, w, r)
	} else if fileURL == r.URL.Path {
		file(ctx, w, r)
	} else if strings.HasPrefix(r.URL.Path, staticURL) {
		name := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:]
		content, ok := static[name]
		if !ok {
			http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
			return
		}
		http.ServeContent(w, r, name, initTime, content)
	} else {
		index(ctx, w, r)
	}
}
开发者ID:flowlo,项目名称:appstats,代码行数:32,代码来源:handler.go


示例8: 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


示例9: handle

func handle(res http.ResponseWriter, req *http.Request) {
	if req.URL.Path != "/" {
		http.NotFound(res, req)
		return
	}

	ctx := appengine.NewContext(req)
	u := user.Current(ctx)

	if u != nil {
		key := datastore.NewKey(ctx, "profile", u.Email, 0, nil)
		var p profile
		err := datastore.Get(ctx, key, &p)
		if err == datastore.ErrNoSuchEntity {
			http.Redirect(res, req, "/CreateProfile", http.StatusSeeOther)
			return
		} else if err != nil {
			http.Error(res, "Server error!", http.StatusInternalServerError)
			log.Errorf(ctx, "Datastore get Error: %s\n", err.Error())
			return
		}
	}

	// Get recent tweets
	query := datastore.NewQuery("Tweets")
	tweets := []tweet{}
	_, err := query.GetAll(ctx, &tweets)
	if err != nil {
		http.Error(res, "Server error!", http.StatusInternalServerError)
		log.Errorf(ctx, "Query Error: %s\n", err.Error())
		return
	}

	// Create template
	loginURL, err := user.LoginURL(ctx, "/")
	if err != nil {
		http.Error(res, "Server error!", http.StatusInternalServerError)
		log.Errorf(ctx, "Login URL Error: %s\n", err.Error())
		return
	}
	data := mainpageData{
		Tweets:   tweets,
		Logged:   u != nil,
		LoginURL: loginURL,
	}
	if data.Logged {
		data.Email = u.Email
	}

	err = tpl.ExecuteTemplate(res, "index.gohtml", data)
	if err != nil {
		http.Error(res, "Server error!", http.StatusInternalServerError)
		log.Errorf(ctx, "Template Execute Error: %s\n", err.Error())
		return
	}
}
开发者ID:kaveenherath,项目名称:SummerBootCamp,代码行数:56,代码来源:main.go


示例10: handleGAEAuth

// handleGAEAuth sends a redirect to GAE authentication page.
func handleGAEAuth(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	url, err := user.LoginURL(c, r.URL.String())
	if err != nil {
		errorf(c, "user.LoginURL(%q): %v", r.URL.String(), err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	http.Redirect(w, r, url, http.StatusFound)
}
开发者ID:pathikdevani,项目名称:ioweb2015,代码行数:11,代码来源:server_gae.go


示例11: 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


示例12: 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


示例13: handle

func handle(res http.ResponseWriter, req *http.Request) {
	if req.URL.Path != "/" {
		http.NotFound(res, req)
		return
	}

	ctx := appengine.NewContext(req)
	u := user.Current(ctx)

	if u != nil {
		_, err := getProfileByEmail(ctx, u.Email)
		if err == datastore.ErrNoSuchEntity {
			http.Redirect(res, req, "/CreateProfile", http.StatusSeeOther)
			return
		} else if err != nil {
			http.Error(res, "Server error!", http.StatusInternalServerError)
			log.Errorf(ctx, "Datastore get Error: %s\n", err.Error())
			return
		}
	}

	//Get recent tweets
	tweets, err := getTweets(ctx, "")
	if err != nil {
		http.Error(res, "server error!", http.StatusInternalServerError)
		log.Errorf(ctx, "Query Error: &s\n", err.Error())
		return
	}

	// Create template
	loginURL, err := user.LoginURL(ctx, "/")
	if err != nil {
		http.Error(res, "server error!", http.StatusInternalServerError)
		log.Errorf(ctx, "Login URL Error: &s\n", err.Error())
		return
	}
	data := mainpageData{
		Tweets:   tweets,
		Logged:   u != nil,
		LoginURL: loginURL,
	}
	if data.Logged {
		data.Email = u.Email
	}

	err = tpl.ExecuteTemplate(res, "index.gohtml", nil)
	if err != nil {
		http.Error(res, "Serever error!", http.StatusInternalServerError)
		log.Errorf(ctx, "Template Parse Error: %s\n", err.Error())
		return
	}
}
开发者ID:KingRick,项目名称:SummerBootCamp,代码行数:52,代码来源:main.go


示例14: login

func login(c context.Context, w http.ResponseWriter, r *http.Request) {
	// TODO: check default page and redirect to page list without it

	var postLogin string
	if dest, ok := r.URL.Query()["dest"]; ok {
		postLogin = dest[0]
	} else {
		postLogin = MNG_ROOT_URL
	}

	loginURL, _ := user.LoginURL(c, postLogin)
	http.Redirect(w, r, loginURL, http.StatusFound)
}
开发者ID:gcpug-shonan,项目名称:gcpug-shonan-cms,代码行数:13,代码来源:caterpillar.go


示例15: handler

func handler(res http.ResponseWriter, req *http.Request) {
	c := appengine.NewContext(req)
	u := user.Current(c)
	if u == nil {
		url, err := user.LoginURL(c, req.URL.String())
		if err != nil {
			http.Error(res, err.Error(), http.StatusInternalServerError)
			return
		}
		res.Header().Set("Location", url)
		res.WriteHeader(http.StatusFound)
		return
	}
	fmt.Fprintf(res, "Hello, %v!", u)
}
开发者ID:GoesToEleven,项目名称:golang-web,代码行数:15,代码来源:hello.go


示例16: authdemo

func authdemo(w http.ResponseWriter, r *http.Request) *appError {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		url, err := user.LoginURL(c, r.URL.String())
		if err != nil {
			return &appError{err, "Could not determine LoginURL", http.StatusInternalServerError}
		}
		w.Header().Set("Location", url)
		w.WriteHeader(http.StatusFound)
		return nil
	}
	fmt.Fprintf(w, "Hello, %v!", u)
	return nil
}
开发者ID:ramjac,项目名称:RAP-Google-App-Engine,代码行数:15,代码来源:authpage.go


示例17: handleLogin

func handleLogin(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	next := r.URL.Query().Get("next")
	if next == "" {
		next = r.URL.Query().Get("continue")
	}
	if next == "" {
		next = r.Referer()
	}

	if user.Current(ctx) != nil {
		url, _ := user.LoginURL(ctx, "/")
		http.Redirect(w, r, url, http.StatusTemporaryRedirect)
	} else {
		http.Redirect(w, r, next, http.StatusTemporaryRedirect)
	}
}
开发者ID:husio,项目名称:apps,代码行数:16,代码来源:urls.go


示例18: handleAuth

// Hard profiles?
//
// Not used yet.
// TODO To be adapted to : Handle optional user strong auth
func handleAuth(w http.ResponseWriter, r *http.Request) error {
	// Cf https://developers.google.com/appengine/docs/go/users/
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		url, err := user.LoginURL(c, "/")
		if err != nil {
			return err
		}
		w.Header().Set("Location", url)
		w.WriteHeader(http.StatusFound)
		return nil
	}
	fmt.Fprintf(w, "Hello, %v!", u)
	return nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:20,代码来源:softProfile.go


示例19: meHandler

func meHandler(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)
	u := user.Current(c)

	if u == nil {
		url, err := user.LoginURL(c, "/me/")
		if err != nil {
		}

		http.Redirect(w, r, url, 301)
		return
	}

	du, err := getUser(r)
	if err != nil {
	}

	if du == nil {
		//register userkey
		meRender(w, "./templates/me/userkey.tmpl", nil)
	} else {
		//select user slide
		userkey := du.UserKey
		q := datastore.NewQuery("Slide").
			Filter("UserKey = ", userkey).
			Order("- SpeakDate")
		var s []Slide

		// function get user Slide

		keys, err := q.GetAll(c, &s)
		if err != nil {
		}

		rtn := make([]TemplateSlide, len(s))
		for i, elm := range s {
			rtn[i] = TemplateSlide{
				Title:     elm.Title,
				SubTitle:  elm.SubTitle,
				SpeakDate: elm.SpeakDate,
				Key:       keys[i].StringID(),
			}
		}
		meRender(w, "./templates/me/top.tmpl", rtn)
	}
}
开发者ID:shizuokago,项目名称:gopredit,代码行数:47,代码来源:me.go


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang user.LogoutURL函数代码示例发布时间:2022-05-28
下一篇:
Golang user.Current函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap