Skip to content

Commit ee30404

Browse files
committed
Refactor: remove duplicate code to get user name.
Signed-off-by: Eric Wang <[email protected]>
1 parent a58ac43 commit ee30404

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

Diff for: lib/plugins/leetcode.js

+2-4
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
};

Diff for: test/plugins/test_leetcode.js

+1-2
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)