3.2 KiB
3.2 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
589a8eb3f9fc0f352b528e72 | Implementation of Social Authentication III | 2 | 社会认证的实施III |
Description
console.log(profile);
目前是: db.collection( 'socialusers')。findAndModify( {id:profile.id}, {}, {$ setOnInsert:{ id:profile.id, name:profile.displayName || 'John Doe', 照片:profile.photos [0] .value || ” 电子邮件:profile.emails [0] .value || '没有公开电子邮件', created_on:new Date(), provider:profile.provider || “ } $设置:{ last_login:新日期() } $ INC { login_count:1 }}, {upsert:true,new:true}, (错误,doc)=> { return cb(null,doc.value); } );使用findAndModify,它允许您搜索对象并对其进行更新,如果对象不存在则将其置换,并在每次回调函数中接收新对象。在这个例子中,我们总是将last_login设置为now,我们总是将login_count增加1,并且只有当我们插入一个新对象(新用户)时,我们才会填充大部分字段。需要注意的是使用默认值。有时,返回的个人资料不会填写所有信息,或者用户会选择保留私密信息;所以在这种情况下我们必须处理它以防止错误。你现在应该可以登录你的应用了 - 试试吧!当您认为自己已经做对时,请提交您的页面。如果你正在运行到错误,您可以检查出的这个小项目的完成代码的例子在这里 。
Instructions
Tests
tests:
- text: Github策略设置完成
testString: 'getUserInput => $.get(getUserInput("url")+ "/_api/server.js") .then(data => { assert.match(data, /GitHubStrategy[^]*db.collection/gi, "Strategy should use now use the database to search for the user"); assert.match(data, /GitHubStrategy[^]*socialusers/gi, "Strategy should use "socialusers" as db collection"); assert.match(data, /GitHubStrategy[^]*return cb/gi, "Strategy should return the callback function "cb""); }, xhr => { throw new Error(xhr.statusText); })'
Challenge Seed
Solution
// solution required