OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 function User(name, email, displayName) | 7 function User(name, email, displayName) |
8 { | 8 { |
9 this.name = name || ""; | 9 this.name = name || ""; |
10 this.email = email || ""; | 10 this.email = email || ""; |
11 this.openIssues = 0; | 11 this.openIssues = 0; |
12 this.reviewedIssues = 0; | 12 this.reviewedIssues = 0; |
13 this.xsrfToken = ""; | 13 this.xsrfToken = ""; |
14 this.displayName = displayName || this.email.split("@")[0] || this.name; | 14 this.displayName = displayName || this.email.split("@")[0] || this.name; |
15 } | 15 } |
16 | 16 |
17 User.CURRENT_USER_URL = "/scrape/settings"; | 17 User.CURRENT_USER_URL = "/scrape/settings"; |
18 User.DETAIL_URL = "/scrape/user_popup/{1}"; | 18 User.DETAIL_URL = "/scrape/user_popup/{1}"; |
19 User.ISSUE_LIST_URL = "/scrape/user/{1}"; | 19 User.ISSUE_LIST_URL = "/scrape/user/{1}"; |
20 | 20 |
21 User.EMAIL_PATTERN = /^([^@]+@[^ ]+) \((.+?)\)$/; | 21 User.EMAIL_PATTERN = /^([^@]+@[^ ]+) \((.+?)\)$/; |
22 User.EMAIL_SUFFIX_PATTERN = /(\+[^@]+)?@.*/; | 22 User.EMAIL_SUFFIX_PATTERN = /(\+[^@]+)?@.*/; |
23 User.ISSUES_OPEN_PATTERN = /issues created: (\d+)/; | 23 User.ISSUES_OPEN_PATTERN = /issues created: (\d+)/; |
24 User.ISSUES_REVIEW_PATTERN = /issues reviewed: (\d+)/; | 24 User.ISSUES_REVIEW_PATTERN = /issues reviewed: (\d+)/; |
25 User.XSRF_TOKEN_PATTERN = /xsrfToken = '([^']+)';/; | 25 User.XSRF_TOKEN_PATTERN = /xsrfToken = '([^']+)';/; |
26 User.LOGIN_REDIRECT_URL = "https://www.google.com/accounts/ServiceLogin?service=
ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3
D{1}<mpl=gm"; | 26 User.LOGIN_REDIRECT_URL = "https://www.google.com/accounts/ServiceLogin?service=
ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3
D{1}<mpl=gm"; |
| 27 User.LOGOUT_REDIRECT_URL = "{1}/_ah/logout?continue=https://www.google.com/accou
nts/Logout%3Fcontinue%3Dhttps://appengine.google.com/_ah/logout%253Fcontinue%253
D{2}"; |
27 | 28 |
28 User.current = null; | 29 User.current = null; |
29 User.currentPromise = null; | 30 User.currentPromise = null; |
30 | 31 |
31 (function() { | 32 (function() { |
32 // Take the user information provided by the server in the initial request | 33 // Take the user information provided by the server in the initial request |
33 // if it's available. | 34 // if it's available. |
34 if (window.INITIAL_USER_DATA) { | 35 if (window.INITIAL_USER_DATA) { |
35 var data = window.INITIAL_USER_DATA; | 36 var data = window.INITIAL_USER_DATA; |
36 User.current = new User(data.name, data.email, "me"); | 37 User.current = new User(data.name, data.email, "me"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 User.currentPromise = null; | 71 User.currentPromise = null; |
71 }); | 72 }); |
72 return User.currentPromise; | 73 return User.currentPromise; |
73 }; | 74 }; |
74 | 75 |
75 User.getLoginUrl = function() | 76 User.getLoginUrl = function() |
76 { | 77 { |
77 return User.LOGIN_REDIRECT_URL.assign(encodeURIComponent(location.href)); | 78 return User.LOGIN_REDIRECT_URL.assign(encodeURIComponent(location.href)); |
78 }; | 79 }; |
79 | 80 |
| 81 User.getLogoutUrl = function() |
| 82 { |
| 83 return User.LOGOUT_REDIRECT_URL.assign( |
| 84 location.origin, |
| 85 encodeURIComponent(location.href)); |
| 86 }; |
| 87 |
80 User.forName = function(name, email) | 88 User.forName = function(name, email) |
81 { | 89 { |
82 if (User.current && (name === "me" || name === User.current.name)) | 90 if (User.current && (name === "me" || name === User.current.name)) |
83 return User.current; | 91 return User.current; |
84 return new User(name, email); | 92 return new User(name, email); |
85 }; | 93 }; |
86 | 94 |
87 User.forMailingListEmail = function(email) | 95 User.forMailingListEmail = function(email) |
88 { | 96 { |
89 // Lots of people use a + url for auto-cc lists, remove it since they | 97 // Lots of people use a + url for auto-cc lists, remove it since they |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 164 } |
157 | 165 |
158 match = User.ISSUES_OPEN_PATTERN.exec(text); | 166 match = User.ISSUES_OPEN_PATTERN.exec(text); |
159 if (match) | 167 if (match) |
160 this.openIssues = Number(match[1]); | 168 this.openIssues = Number(match[1]); |
161 | 169 |
162 match = User.ISSUES_REVIEW_PATTERN.exec(text); | 170 match = User.ISSUES_REVIEW_PATTERN.exec(text); |
163 if (match) | 171 if (match) |
164 this.reviewedIssues = Number(match[1]); | 172 this.reviewedIssues = Number(match[1]); |
165 }; | 173 }; |
OLD | NEW |