mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-12 08:41:46 -05:00
Merge branch 'master' into production
This commit is contained in:
commit
2bc020ab4d
4 changed files with 42 additions and 23 deletions
|
@ -281,22 +281,22 @@ module.exports = class User extends CocoModel
|
||||||
window.tracker?.trackEvent 'Finished Signup', category: "Signup", label: 'CodeCombat'
|
window.tracker?.trackEvent 'Finished Signup', category: "Signup", label: 'CodeCombat'
|
||||||
return jqxhr
|
return jqxhr
|
||||||
|
|
||||||
signupWithFacebook: (email, facebookID, options={}) ->
|
signupWithFacebook: (name, email, facebookID, options={}) ->
|
||||||
options.url = _.result(@, 'url') + '/signup-with-facebook'
|
options.url = _.result(@, 'url') + '/signup-with-facebook'
|
||||||
options.type = 'POST'
|
options.type = 'POST'
|
||||||
options.data ?= {}
|
options.data ?= {}
|
||||||
_.extend(options.data, {email, facebookID, facebookAccessToken: application.facebookHandler.token()})
|
_.extend(options.data, {name, email, facebookID, facebookAccessToken: application.facebookHandler.token()})
|
||||||
jqxhr = @fetch(options)
|
jqxhr = @fetch(options)
|
||||||
jqxhr.then ->
|
jqxhr.then ->
|
||||||
window.tracker?.trackEvent 'Facebook Login', category: "Signup", label: 'Facebook'
|
window.tracker?.trackEvent 'Facebook Login', category: "Signup", label: 'Facebook'
|
||||||
window.tracker?.trackEvent 'Finished Signup', category: "Signup", label: 'Facebook'
|
window.tracker?.trackEvent 'Finished Signup', category: "Signup", label: 'Facebook'
|
||||||
return jqxhr
|
return jqxhr
|
||||||
|
|
||||||
signupWithGPlus: (email, gplusID, options={}) ->
|
signupWithGPlus: (name, email, gplusID, options={}) ->
|
||||||
options.url = _.result(@, 'url') + '/signup-with-gplus'
|
options.url = _.result(@, 'url') + '/signup-with-gplus'
|
||||||
options.type = 'POST'
|
options.type = 'POST'
|
||||||
options.data ?= {}
|
options.data ?= {}
|
||||||
_.extend(options.data, {email, gplusID, gplusAccessToken: application.gplusHandler.token()})
|
_.extend(options.data, {name, email, gplusID, gplusAccessToken: application.gplusHandler.token()})
|
||||||
jqxhr = @fetch(options)
|
jqxhr = @fetch(options)
|
||||||
jqxhr.then ->
|
jqxhr.then ->
|
||||||
window.tracker?.trackEvent 'Google Login', category: "Signup", label: 'GPlus'
|
window.tracker?.trackEvent 'Google Login', category: "Signup", label: 'GPlus'
|
||||||
|
|
|
@ -147,9 +147,12 @@ module.exports =
|
||||||
unless req.user.isAnonymous()
|
unless req.user.isAnonymous()
|
||||||
throw new errors.Forbidden('You are already signed in.')
|
throw new errors.Forbidden('You are already signed in.')
|
||||||
|
|
||||||
{ facebookID, facebookAccessToken, email } = req.body
|
{ facebookID, facebookAccessToken, email, name } = req.body
|
||||||
unless _.all([facebookID, facebookAccessToken, email])
|
unless _.all([facebookID, facebookAccessToken, email, name])
|
||||||
throw new errors.UnprocessableEntity('Requires facebookID, facebookAccessToken and email')
|
throw new errors.UnprocessableEntity('Requires facebookID, facebookAccessToken, email, and name')
|
||||||
|
|
||||||
|
if not _.isEmpty(name) and yield User.findByName(name)
|
||||||
|
throw new errors.Conflict('Name already taken')
|
||||||
|
|
||||||
facebookResponse = yield facebook.fetchMe(facebookAccessToken)
|
facebookResponse = yield facebook.fetchMe(facebookAccessToken)
|
||||||
emailsMatch = email is facebookResponse.email
|
emailsMatch = email is facebookResponse.email
|
||||||
|
@ -157,16 +160,19 @@ module.exports =
|
||||||
unless emailsMatch and idsMatch
|
unless emailsMatch and idsMatch
|
||||||
throw new errors.UnprocessableEntity('Invalid facebookAccessToken')
|
throw new errors.UnprocessableEntity('Invalid facebookAccessToken')
|
||||||
|
|
||||||
req.user.set({ facebookID, email, anonymous: false })
|
req.user.set({ facebookID, email, name, anonymous: false })
|
||||||
yield module.exports.finishSignup(req, res)
|
yield module.exports.finishSignup(req, res)
|
||||||
|
|
||||||
signupWithGPlus: wrap (req, res) ->
|
signupWithGPlus: wrap (req, res) ->
|
||||||
unless req.user.isAnonymous()
|
unless req.user.isAnonymous()
|
||||||
throw new errors.Forbidden('You are already signed in.')
|
throw new errors.Forbidden('You are already signed in.')
|
||||||
|
|
||||||
{ gplusID, gplusAccessToken, email } = req.body
|
{ gplusID, gplusAccessToken, email, name } = req.body
|
||||||
unless _.all([gplusID, gplusAccessToken, email])
|
unless _.all([gplusID, gplusAccessToken, email, name])
|
||||||
throw new errors.UnprocessableEntity('Requires gplusID, gplusAccessToken and email')
|
throw new errors.UnprocessableEntity('Requires gplusID, gplusAccessToken, email, and name')
|
||||||
|
|
||||||
|
if not _.isEmpty(name) and yield User.findByName(name)
|
||||||
|
throw new errors.Conflict('Name already taken')
|
||||||
|
|
||||||
gplusResponse = yield gplus.fetchMe(gplusAccessToken)
|
gplusResponse = yield gplus.fetchMe(gplusAccessToken)
|
||||||
emailsMatch = email is gplusResponse.email
|
emailsMatch = email is gplusResponse.email
|
||||||
|
@ -175,7 +181,7 @@ module.exports =
|
||||||
unless emailsMatch and idsMatch
|
unless emailsMatch and idsMatch
|
||||||
throw new errors.UnprocessableEntity('Invalid gplusAccessToken')
|
throw new errors.UnprocessableEntity('Invalid gplusAccessToken')
|
||||||
|
|
||||||
req.user.set({ gplusID, email, anonymous: false })
|
req.user.set({ gplusID, email, name, anonymous: false })
|
||||||
yield module.exports.finishSignup(req, res)
|
yield module.exports.finishSignup(req, res)
|
||||||
|
|
||||||
finishSignup: co.wrap (req, res) ->
|
finishSignup: co.wrap (req, res) ->
|
||||||
|
|
|
@ -49,6 +49,15 @@ console.error = function() {
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (process.argv.indexOf('--with-test-names') > -1) {
|
||||||
|
jasmine.getEnv().addReporter({
|
||||||
|
specStarted: function(result){
|
||||||
|
// Printing weirdly so pass/fail indicator is on the same line as the test name
|
||||||
|
process.stdout.write('\n' + result.fullName);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var initialized = false;
|
var initialized = false;
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
|
|
|
@ -696,7 +696,8 @@ describe 'POST /db/user/:handle/signup-with-password', ->
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-password")
|
url = getURL("/db/user/#{user.id}/signup-with-password")
|
||||||
email = 'some@email.com'
|
email = 'some@email.com'
|
||||||
json = { email, password: '12345' }
|
name = 'someusername'
|
||||||
|
json = { name, email, password: '12345' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
updatedUser = yield User.findById(user.id)
|
updatedUser = yield User.findById(user.id)
|
||||||
|
@ -801,6 +802,7 @@ describe 'POST /db/user/:handle/signup-with-password', ->
|
||||||
describe 'POST /db/user/:handle/signup-with-facebook', ->
|
describe 'POST /db/user/:handle/signup-with-facebook', ->
|
||||||
facebookID = '12345'
|
facebookID = '12345'
|
||||||
facebookEmail = 'some@email.com'
|
facebookEmail = 'some@email.com'
|
||||||
|
name = 'someusername'
|
||||||
|
|
||||||
validFacebookResponse = new Promise((resolve) -> resolve({
|
validFacebookResponse = new Promise((resolve) -> resolve({
|
||||||
id: facebookID,
|
id: facebookID,
|
||||||
|
@ -835,7 +837,7 @@ describe 'POST /db/user/:handle/signup-with-facebook', ->
|
||||||
spyOn(sendwithus.api, 'send')
|
spyOn(sendwithus.api, 'send')
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-facebook")
|
url = getURL("/db/user/#{user.id}/signup-with-facebook")
|
||||||
json = { email: facebookEmail, facebookID, facebookAccessToken: '...' }
|
json = { name, email: facebookEmail, facebookID, facebookAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
updatedUser = yield User.findById(user.id)
|
updatedUser = yield User.findById(user.id)
|
||||||
|
@ -858,11 +860,11 @@ describe 'POST /db/user/:handle/signup-with-facebook', ->
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-facebook")
|
url = getURL("/db/user/#{user.id}/signup-with-facebook")
|
||||||
|
|
||||||
json = { email: 'some-other@email.com', facebookID, facebookAccessToken: '...' }
|
json = { name, email: 'some-other@email.com', facebookID, facebookAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
|
|
||||||
json = { email: facebookEmail, facebookID: '54321', facebookAccessToken: '...' }
|
json = { name, email: facebookEmail, facebookID: '54321', facebookAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
|
|
||||||
|
@ -874,7 +876,7 @@ describe 'POST /db/user/:handle/signup-with-facebook', ->
|
||||||
spyOn(facebook, 'fetchMe').and.returnValue(validFacebookResponse)
|
spyOn(facebook, 'fetchMe').and.returnValue(validFacebookResponse)
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-facebook")
|
url = getURL("/db/user/#{user.id}/signup-with-facebook")
|
||||||
json = { email: facebookEmail, facebookID, facebookAccessToken: '...' }
|
json = { name, email: facebookEmail, facebookID, facebookAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(409)
|
expect(res.statusCode).toBe(409)
|
||||||
done()
|
done()
|
||||||
|
@ -883,6 +885,7 @@ describe 'POST /db/user/:handle/signup-with-facebook', ->
|
||||||
describe 'POST /db/user/:handle/signup-with-gplus', ->
|
describe 'POST /db/user/:handle/signup-with-gplus', ->
|
||||||
gplusID = '12345'
|
gplusID = '12345'
|
||||||
gplusEmail = 'some@email.com'
|
gplusEmail = 'some@email.com'
|
||||||
|
name = 'someusername'
|
||||||
|
|
||||||
validGPlusResponse = new Promise((resolve) -> resolve({
|
validGPlusResponse = new Promise((resolve) -> resolve({
|
||||||
id: gplusID
|
id: gplusID
|
||||||
|
@ -923,10 +926,11 @@ describe 'POST /db/user/:handle/signup-with-gplus', ->
|
||||||
spyOn(sendwithus.api, 'send')
|
spyOn(sendwithus.api, 'send')
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
||||||
json = { email: gplusEmail, gplusID, gplusAccessToken: '...' }
|
json = { name, email: gplusEmail, gplusID, gplusAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
updatedUser = yield User.findById(user.id)
|
updatedUser = yield User.findById(user.id)
|
||||||
|
expect(updatedUser.get('name')).toBe(name)
|
||||||
expect(updatedUser.get('email')).toBe(gplusEmail)
|
expect(updatedUser.get('email')).toBe(gplusEmail)
|
||||||
expect(updatedUser.get('gplusID')).toBe(gplusID)
|
expect(updatedUser.get('gplusID')).toBe(gplusID)
|
||||||
expect(sendwithus.api.send).toHaveBeenCalled()
|
expect(sendwithus.api.send).toHaveBeenCalled()
|
||||||
|
@ -936,7 +940,7 @@ describe 'POST /db/user/:handle/signup-with-gplus', ->
|
||||||
spyOn(gplus, 'fetchMe').and.returnValue(invalidGPlusResponse)
|
spyOn(gplus, 'fetchMe').and.returnValue(invalidGPlusResponse)
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
||||||
json = { email: gplusEmail, gplusID, gplusAccessToken: '...' }
|
json = { name, email: gplusEmail, gplusID, gplusAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
done()
|
done()
|
||||||
|
@ -946,22 +950,22 @@ describe 'POST /db/user/:handle/signup-with-gplus', ->
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
||||||
|
|
||||||
json = { email: 'some-other@email.com', gplusID, gplusAccessToken: '...' }
|
json = { name, email: 'some-other@email.com', gplusID, gplusAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
|
|
||||||
json = { email: gplusEmail, gplusID: '54321', gplusAccessToken: '...' }
|
json = { name, email: gplusEmail, gplusID: '54321', gplusAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'returns 409 if there is already a user with the given email', utils.wrap (done) ->
|
it 'returns 409 if there is already a user with the given email', utils.wrap (done) ->
|
||||||
yield utils.initUser({email: gplusEmail})
|
yield utils.initUser({name: 'someusername', email: gplusEmail})
|
||||||
spyOn(gplus, 'fetchMe').and.returnValue(validGPlusResponse)
|
spyOn(gplus, 'fetchMe').and.returnValue(validGPlusResponse)
|
||||||
user = yield utils.becomeAnonymous()
|
user = yield utils.becomeAnonymous()
|
||||||
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
url = getURL("/db/user/#{user.id}/signup-with-gplus")
|
||||||
json = { email: gplusEmail, gplusID, gplusAccessToken: '...' }
|
json = { name: 'differentusername', email: gplusEmail, gplusID, gplusAccessToken: '...' }
|
||||||
[res, body] = yield request.postAsync({url, json})
|
[res, body] = yield request.postAsync({url, json})
|
||||||
expect(res.statusCode).toBe(409)
|
expect(res.statusCode).toBe(409)
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in a new issue