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


Golang user.LoginURL函数代码示例

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


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


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