| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "crypto/sha256" | 8 "crypto/sha256" |
| 9 "encoding/binary" | 9 "encoding/binary" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 type userData struct { | 21 type userData struct { |
| 22 sync.RWMutex | 22 sync.RWMutex |
| 23 user *user.User | 23 user *user.User |
| 24 } | 24 } |
| 25 | 25 |
| 26 // userImpl is a contextual pointer to the current userData. | 26 // userImpl is a contextual pointer to the current userData. |
| 27 type userImpl struct { | 27 type userImpl struct { |
| 28 data *userData | 28 data *userData |
| 29 } | 29 } |
| 30 | 30 |
| 31 var _ user.Interface = (*userImpl)(nil) | 31 var _ user.RawInterface = (*userImpl)(nil) |
| 32 | 32 |
| 33 // useUser adds a user.Interface implementation to context, accessible | 33 // useUser adds a user.RawInterface implementation to context, accessible |
| 34 // by user.Get(c) | 34 // by user.Raw(c) or the exported user methods. |
| 35 func useUser(c context.Context) context.Context { | 35 func useUser(c context.Context) context.Context { |
| 36 data := &userData{} | 36 data := &userData{} |
| 37 | 37 |
| 38 » return user.SetFactory(c, func(ic context.Context) user.Interface { | 38 » return user.SetFactory(c, func(ic context.Context) user.RawInterface { |
| 39 return &userImpl{data} | 39 return &userImpl{data} |
| 40 }) | 40 }) |
| 41 } | 41 } |
| 42 | 42 |
| 43 func (u *userImpl) Current() *user.User { | 43 func (u *userImpl) Current() *user.User { |
| 44 u.data.RLock() | 44 u.data.RLock() |
| 45 defer u.data.RUnlock() | 45 defer u.data.RUnlock() |
| 46 if u.data.user != nil && u.data.user.ClientID == "" { | 46 if u.data.user != nil && u.data.user.ClientID == "" { |
| 47 ret := *u.data.user | 47 ret := *u.data.user |
| 48 return &ret | 48 return &ret |
| (...skipping 27 matching lines...) Expand all Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 func (u *userImpl) LoginURLFederated(dest, identity string) (string, error) { | 78 func (u *userImpl) LoginURLFederated(dest, identity string) (string, error) { |
| 79 return "", fmt.Errorf("LoginURLFederated is deprecated") | 79 return "", fmt.Errorf("LoginURLFederated is deprecated") |
| 80 } | 80 } |
| 81 | 81 |
| 82 func (u *userImpl) OAuthConsumerKey() (string, error) { | 82 func (u *userImpl) OAuthConsumerKey() (string, error) { |
| 83 return "", fmt.Errorf("OAuthConsumerKey is deprecated") | 83 return "", fmt.Errorf("OAuthConsumerKey is deprecated") |
| 84 } | 84 } |
| 85 | 85 |
| 86 func (u *userImpl) Testable() user.Testable { | 86 func (u *userImpl) GetTestable() user.Testable { return u } |
| 87 » return u | |
| 88 } | |
| 89 | 87 |
| 90 func (u *userImpl) SetUser(user *user.User) { | 88 func (u *userImpl) SetUser(user *user.User) { |
| 91 u.data.Lock() | 89 u.data.Lock() |
| 92 defer u.data.Unlock() | 90 defer u.data.Unlock() |
| 93 u.data.user = user | 91 u.data.user = user |
| 94 } | 92 } |
| 95 | 93 |
| 96 func (u *userImpl) Login(email, clientID string, admin bool) { | 94 func (u *userImpl) Login(email, clientID string, admin bool) { |
| 97 adr, err := mail.ParseAddress(email) | 95 adr, err := mail.ParseAddress(email) |
| 98 if err != nil { | 96 if err != nil { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 113 Admin: admin, | 111 Admin: admin, |
| 114 | 112 |
| 115 ID: fmt.Sprint(binary.LittleEndian.Uint64(id[:])), | 113 ID: fmt.Sprint(binary.LittleEndian.Uint64(id[:])), |
| 116 ClientID: clientID, | 114 ClientID: clientID, |
| 117 }) | 115 }) |
| 118 } | 116 } |
| 119 | 117 |
| 120 func (u *userImpl) Logout() { | 118 func (u *userImpl) Logout() { |
| 121 u.SetUser(nil) | 119 u.SetUser(nil) |
| 122 } | 120 } |
| OLD | NEW |