Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ee30404

Browse files
Refactor: remove duplicate code to get user name.
Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent a58ac43 commit ee30404

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

‎lib/plugins/leetcode.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ plugin.signin = function(user, cb) {
391391

392392
user.sessionCSRF = h.getSetCookieValue(resp, 'csrftoken');
393393
user.sessionId = h.getSetCookieValue(resp, 'LEETCODE_SESSION');
394-
user.name = h.getSetCookieValue(resp, 'messages')
395-
.match('Successfully signed in as ([^.]*)')[1];
394+
session.saveUser(user);
396395
return cb(null, user);
397396
});
398397
});
@@ -407,7 +406,7 @@ plugin.getUser = function(user, cb) {
407406
});
408407
user.hash = favorite.id_hash;
409408
user.name = favorites.user_name;
410-
409+
session.saveUser(user);
411410
return cb(null, user);
412411
});
413412
};
@@ -416,7 +415,6 @@ plugin.login = function(user, cb) {
416415
log.debug('running leetcode.login');
417416
plugin.signin(user, function(e, user) {
418417
if (e) return cb(e);
419-
session.saveUser(user);
420418
plugin.getUser(user, cb);
421419
});
422420
};

‎test/plugins/test_leetcode.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ describe('plugin:leetcode', function() {
5353
.reply(302, '', {
5454
'Set-Cookie': [
5555
'csrftoken=SESSION_CSRF_TOKEN; Max-Age=31449600; Path=/; secure',
56-
'LEETCODE_SESSION=SESSION_ID; Max-Age=31449600; Path=/; secure',
57-
"messages='Successfully signed in as Eric.'; Max-Age=31449600; Path=/; secure"
56+
'LEETCODE_SESSION=SESSION_ID; Max-Age=31449600; Path=/; secure'
5857
]});
5958

6059
nock('https://leetcode.com')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /