當前位置: 首頁>>代碼示例>>Golang>>正文


Golang User.Name方法代碼示例

本文整理匯總了Golang中github.com/couchbaselabs/sync_gateway/auth.User.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.Name方法的具體用法?Golang User.Name怎麽用?Golang User.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/couchbaselabs/sync_gateway/auth.User的用法示例。


在下文中一共展示了User.Name方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ComputeRolesForUser

// Recomputes the set of roles a User has been granted access to by sync() functions.
// This is part of the ChannelComputer interface defined by the Authenticator.
func (context *DatabaseContext) ComputeRolesForUser(user auth.User) ([]string, error) {
	var vres struct {
		Rows []struct {
			Value channels.TimedSet
		}
	}

	opts := map[string]interface{}{"stale": false, "key": user.Name()}
	if verr := context.Bucket.ViewCustom("sync_gateway", "role_access", opts, &vres); verr != nil {
		return nil, verr
	}
	// Boil the list of TimedSets down to a simple set of role names:
	all := map[string]bool{}
	for _, row := range vres.Rows {
		for name, _ := range row.Value {
			all[name] = true
		}
	}
	// Then turn that set into an array to return:
	values := make([]string, 0, len(all))
	for name, _ := range all {
		values = append(values, name)
	}
	return values, nil
}
開發者ID:jnordberg,項目名稱:sync_gateway,代碼行數:27,代碼來源:crud.go

示例2: makeUserCtx

// Creates a userCtx object to be passed to the sync function
func makeUserCtx(user auth.User) map[string]interface{} {
	if user == nil {
		return nil
	}
	return map[string]interface{}{
		"name":     user.Name(),
		"roles":    user.RoleNames(),
		"channels": user.InheritedChannels().AllChannels(),
	}
}
開發者ID:racido,項目名稱:sync_gateway,代碼行數:11,代碼來源:crud.go

示例3: NewWaiterWithChannels

func (listener *changeListener) NewWaiterWithChannels(chans base.Set, user auth.User) *changeWaiter {
	waitKeys := make([]string, 0, 5)
	for channel, _ := range chans {
		waitKeys = append(waitKeys, channelLogDocID(channel))
	}
	if user != nil {
		waitKeys = append(waitKeys, auth.UserKeyPrefix+user.Name())
		for _, role := range user.RoleNames() {
			waitKeys = append(waitKeys, auth.RoleKeyPrefix+role)
		}
	}
	return listener.NewWaiter(waitKeys)
}
開發者ID:nod,項目名稱:sync_gateway,代碼行數:13,代碼來源:change_listener.go

示例4: makeSession

func (h *handler) makeSession(user auth.User) error {
	if user == nil {
		return base.HTTPErrorf(http.StatusUnauthorized, "Invalid login")
	}
	h.user = user
	auth := h.db.Authenticator()
	session, err := auth.CreateSession(user.Name(), kDefaultSessionTTL)
	if err != nil {
		return err
	}
	cookie := auth.MakeSessionCookie(session)
	cookie.Path = "/" + h.db.Name + "/"
	http.SetCookie(h.response, cookie)
	return h.respondWithSessionInfo()
}
開發者ID:rajasaur,項目名稱:sync_gateway,代碼行數:15,代碼來源:session_api.go

示例5: NewWaiterWithChannels

func (listener *changeListener) NewWaiterWithChannels(chans base.Set, user auth.User) *changeWaiter {
	waitKeys := make([]string, 0, 5)
	for channel, _ := range chans {
		waitKeys = append(waitKeys, channel)
	}
	var userKeys []string
	if user != nil {
		userKeys = []string{auth.UserKeyPrefix + user.Name()}
		for role, _ := range user.RoleNames() {
			userKeys = append(userKeys, auth.RoleKeyPrefix+role)
		}
		waitKeys = append(waitKeys, userKeys...)
	}
	waiter := listener.NewWaiter(waitKeys)
	waiter.userKeys = userKeys
	return waiter
}
開發者ID:joscas,項目名稱:sync_gateway,代碼行數:17,代碼來源:change_listener.go

示例6: ComputeRolesForUser

// Recomputes the set of roles a User has been granted access to by sync() functions.
// This is part of the ChannelComputer interface defined by the Authenticator.
func (context *DatabaseContext) ComputeRolesForUser(user auth.User) (channels.TimedSet, error) {
	var vres struct {
		Rows []struct {
			Value channels.TimedSet
		}
	}

	opts := map[string]interface{}{"stale": false, "key": user.Name()}
	if verr := context.Bucket.ViewCustom("sync_gateway", "role_access", opts, &vres); verr != nil {
		return nil, verr
	}
	// Merge the TimedSets from the view result:
	var result channels.TimedSet
	for _, row := range vres.Rows {
		if result == nil {
			result = row.Value
		} else {
			result.Add(row.Value)
		}
	}
	return result, nil
}
開發者ID:racido,項目名稱:sync_gateway,代碼行數:24,代碼來源:crud.go

示例7: putUser

// Handles PUT or POST to /username
func putUser(r http.ResponseWriter, rq *http.Request, a *auth.Authenticator, username string) error {
	body, _ := ioutil.ReadAll(rq.Body)
	var user auth.User
	err := json.Unmarshal(body, &user)
	if err != nil {
		return err
	}
	if user.Channels == nil {
		return &base.HTTPError{http.StatusBadRequest, "Missing channels property"}
	}

	if rq.Method == "POST" {
		username = user.Name
		if username == "" {
			return &base.HTTPError{http.StatusBadRequest, "Missing name property"}
		}
	} else if user.Name == "" {
		user.Name = username
	} else if user.Name != username {
		return &base.HTTPError{http.StatusBadRequest, "Name mismatch (can't change name)"}
	}
	log.Printf("SaveUser: %v", user) //TEMP
	return a.SaveUser(&user)
}
開發者ID:jchris,項目名稱:sync_gateway,代碼行數:25,代碼來源:authrest.go


注:本文中的github.com/couchbaselabs/sync_gateway/auth.User.Name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。