MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / GetUser

Method GetUser

pkg/account/session/session.go:142–164  ·  view source on GitHub ↗

GetUser retrieves the user that is associated with the current session.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

140
141// GetUser retrieves the user that is associated with the current session.
142func (s *Session) GetUser(w http.ResponseWriter, r *http.Request) (*http.Request, *ttnpb.User, error) {
143 if user, ok := r.Context().Value(userKey).(*ttnpb.User); ok {
144 return r, user, nil
145 }
146 r, session, err := s.Get(w, r)
147 if err != nil {
148 return r, nil, err
149 }
150 ctx := r.Context()
151 var user *ttnpb.User
152 err = s.Store.Transact(ctx, func(ctx context.Context, st Store) (err error) {
153 user, err = st.GetUser(
154 ctx,
155 &ttnpb.UserIdentifiers{UserId: session.GetUserIds().GetUserId()},
156 nil,
157 )
158 return err
159 })
160 if err != nil {
161 return r, nil, err
162 }
163 return r.WithContext(context.WithValue(ctx, userKey, user)), user, nil
164}
165
166// DoLogin performs the authentication using user id and password.
167func (s *Session) DoLogin(ctx context.Context, userID, password string) error {

Callers

nothing calls this directly

Calls 7

GetMethod · 0.95
GetUserIdMethod · 0.80
ContextMethod · 0.65
TransactMethod · 0.65
GetUserMethod · 0.65
ValueMethod · 0.45
GetUserIdsMethod · 0.45

Tested by

no test coverage detected