OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // 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" |
| 11 "net/mail" |
11 "net/url" | 12 "net/url" |
12 "strings" | 13 "strings" |
13 "sync" | 14 "sync" |
14 | 15 |
15 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
16 | 17 |
17 "github.com/luci/gae/service/user" | 18 "github.com/luci/gae/service/user" |
18 ) | 19 ) |
19 | 20 |
20 type userData struct { | 21 type userData struct { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return u | 87 return u |
87 } | 88 } |
88 | 89 |
89 func (u *userImpl) SetUser(user *user.User) { | 90 func (u *userImpl) SetUser(user *user.User) { |
90 u.data.Lock() | 91 u.data.Lock() |
91 defer u.data.Unlock() | 92 defer u.data.Unlock() |
92 u.data.user = user | 93 u.data.user = user |
93 } | 94 } |
94 | 95 |
95 func (u *userImpl) Login(email, clientID string, admin bool) { | 96 func (u *userImpl) Login(email, clientID string, admin bool) { |
| 97 adr, err := mail.ParseAddress(email) |
| 98 if err != nil { |
| 99 panic(err) |
| 100 } |
| 101 email = adr.Address |
| 102 |
96 parts := strings.Split(email, "@") | 103 parts := strings.Split(email, "@") |
97 if len(parts) != 2 { | 104 if len(parts) != 2 { |
98 panic(fmt.Errorf("%q doesn't seem to be a valid email", email)) | 105 panic(fmt.Errorf("%q doesn't seem to be a valid email", email)) |
99 } | 106 } |
100 | 107 |
101 id := sha256.Sum256([]byte("ID:" + email)) | 108 id := sha256.Sum256([]byte("ID:" + email)) |
102 | 109 |
103 u.SetUser(&user.User{ | 110 u.SetUser(&user.User{ |
104 Email: email, | 111 Email: email, |
105 AuthDomain: parts[1], | 112 AuthDomain: parts[1], |
106 Admin: admin, | 113 Admin: admin, |
107 | 114 |
108 ID: fmt.Sprint(binary.LittleEndian.Uint64(id[:])), | 115 ID: fmt.Sprint(binary.LittleEndian.Uint64(id[:])), |
109 ClientID: clientID, | 116 ClientID: clientID, |
110 }) | 117 }) |
111 } | 118 } |
112 | 119 |
113 func (u *userImpl) Logout() { | 120 func (u *userImpl) Logout() { |
114 u.SetUser(nil) | 121 u.SetUser(nil) |
115 } | 122 } |
OLD | NEW |