mirror of
https://github.com/cnodejs/nodeclub.git
synced 2025-12-08 19:55:55 +00:00
record github access-token
This commit is contained in:
parent
8145be26fd
commit
aa41af263e
@ -15,6 +15,8 @@ exports.callback = function (req, res, next) {
|
||||
// 当用户已经是 cnode 用户时,通过 github 登陆将会更新他的资料
|
||||
if (user) {
|
||||
user.githubUsername = profile.username;
|
||||
user.githubId = profile.id;
|
||||
user.githubAccessToken = profile.accessToken;
|
||||
user.loginname = profile.username;
|
||||
user.avatar = profile._json.avatar_url;
|
||||
|
||||
@ -51,13 +53,13 @@ exports.create = function (req, res, next) {
|
||||
delete req.session.profile;
|
||||
if (isnew) { // 注册新账号
|
||||
var user = new User({
|
||||
name: profile.username,
|
||||
loginname: profile.username,
|
||||
pass: profile.accessToken,
|
||||
email: profile.emails[0].value,
|
||||
avatar: profile._json.avatar_url,
|
||||
githubId: profile.id,
|
||||
githubUsername: profile.username,
|
||||
githubAccessToken: profile.accessToken,
|
||||
active: true,
|
||||
});
|
||||
user.save(function (err) {
|
||||
@ -93,7 +95,12 @@ exports.create = function (req, res, next) {
|
||||
if (!bool) {
|
||||
return ep.emit('login_error');
|
||||
}
|
||||
user.githubUsername = profile.username;
|
||||
user.githubId = profile.id;
|
||||
user.loginname = profile.username;
|
||||
user.avatar = profile._json.avatar_url;
|
||||
user.githubAccessToken = profile.accessToken;
|
||||
|
||||
user.save(function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@ -17,6 +17,7 @@ var UserSchema = new Schema({
|
||||
avatar: { type: String },
|
||||
githubId: { type: String},
|
||||
githubUsername: {type: String},
|
||||
githubAccessToken: {type: String},
|
||||
is_block: {type: Boolean, default: false},
|
||||
|
||||
score: { type: Number, default: 0 },
|
||||
|
||||
@ -84,13 +84,13 @@ describe('test/controllers/github.test.js', function () {
|
||||
|
||||
describe('post /auth/github/create', function () {
|
||||
before(function () {
|
||||
var displayName = 'alsotang' + new Date();
|
||||
var username = 'alsotang' + new Date();
|
||||
var email = 'alsotang@gmail.com' + new Date();
|
||||
var displayName = 'alsotang' + +new Date();
|
||||
var username = 'alsotang' + +new Date();
|
||||
var email = 'alsotang@gmail.com' + +new Date();
|
||||
app.post('/auth/github/test_create', function (req, res, next) {
|
||||
req.session.profile = {
|
||||
displayName: displayName,
|
||||
username: username,
|
||||
username: req.body.githubName || username,
|
||||
accessToken: 'a3l24j23lk5jtl35tkjglfdsf',
|
||||
emails: [
|
||||
{value: email}
|
||||
@ -138,7 +138,7 @@ describe('test/controllers/github.test.js', function () {
|
||||
var pass = 'hehe';
|
||||
support.createUserByNameAndPwd(username, pass, function (user) {
|
||||
request.post('/auth/github/test_create')
|
||||
.send({name: username, pass: pass})
|
||||
.send({name: username, pass: pass, githubName: username})
|
||||
.end(function (err, res) {
|
||||
res.status.should.equal(302);
|
||||
res.headers.location.should.equal('/');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user