mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-20 12:32:28 -05:00
8496343a02
This adds the ability to verify email addresses of a user, so we know they have access to the email address on their account. Until a user has verified their email address, any teacher of a class they're in can reset their password for them via the Teacher Dashboard. When a user's email address is verified, a teacher may trigger a password recovery email to be sent to the student. Verification links are valid forever, until the user changes the email address they have on file. They are created using a timestamp, with a sha256 of timestamp+salt+userID+email. Currently the hash value is rather long, could be shorter. Squashed commit messages: Add server endpoints for verifying email address Add server endpoints for verifying email address (pt 2) Add Server+Client endpoint for sending verification email Add client view for verification links Add Edit Student Modal for resetting passwords Add specs for EditStudentModal Tweak method name in EditStudentModal Add edit student button to TeacherClassView Fix up frontend for teacher password resetting Add middleware for teacher password resetting Improve button UX in EditStudentModal Add JoinClassModal Add welcome emails, use broad name Use email without domain as fallback instead of full email Fetch user on edit student modal open Don't allow password reset if student email is verified Set role to student on user signup with classCode Tweak interface for joinClassModal Add button to request verification email for yourself Fix verify email template ID Move text to en.coffee Minor tweaks Fix code review comments Fix some tests, disable a broken one Fix misc tests Fix more tests Refactor recovery email sending to auth Fix overbroad sass Add options to refactored recovery email function Rename getByCode to fetchByCode Fix error message Fix up error handling in users middleware Use .get instead of .toObject Use findById Fix more code review comments Disable still-broken test
67 lines
2.5 KiB
CoffeeScript
67 lines
2.5 KiB
CoffeeScript
GLOBAL._ = require 'lodash'
|
|
|
|
User = require '../../../server/models/User'
|
|
|
|
describe 'User', ->
|
|
|
|
it 'uses the schema defaults to fill in email preferences', (done) ->
|
|
user = new User()
|
|
expect(user.isEmailSubscriptionEnabled('generalNews')).toBeTruthy()
|
|
expect(user.isEmailSubscriptionEnabled('anyNotes')).toBeTruthy()
|
|
expect(user.isEmailSubscriptionEnabled('recruitNotes')).toBeTruthy()
|
|
expect(user.isEmailSubscriptionEnabled('archmageNews')).toBeFalsy()
|
|
done()
|
|
|
|
it 'uses old subs if they\'re around', (done) ->
|
|
user = new User()
|
|
user.set 'emailSubscriptions', ['tester']
|
|
expect(user.isEmailSubscriptionEnabled('adventurerNews')).toBeTruthy()
|
|
expect(user.isEmailSubscriptionEnabled('generalNews')).toBeFalsy()
|
|
done()
|
|
|
|
it 'maintains the old subs list if it\'s around', (done) ->
|
|
user = new User()
|
|
user.set 'emailSubscriptions', ['tester']
|
|
user.setEmailSubscription('artisanNews', true)
|
|
expect(JSON.stringify(user.get('emailSubscriptions'))).toBe(JSON.stringify(['tester', 'level_creator']))
|
|
done()
|
|
|
|
describe '.updateServiceSettings()', ->
|
|
makeMC = (callback) ->
|
|
|
|
it 'uses emails to determine what to send to MailChimp', (done) ->
|
|
spyOn(mc.lists, 'subscribe').and.callFake (params) ->
|
|
expect(JSON.stringify(params.merge_vars.groupings[0].groups)).toBe(JSON.stringify(['Announcements']))
|
|
done()
|
|
|
|
user = new User({emailSubscriptions: ['announcement'], email: 'tester@gmail.com'})
|
|
User.updateServiceSettings(user)
|
|
|
|
describe '.isAdmin()', ->
|
|
it 'returns true if user has "admin" permission', (done) ->
|
|
adminUser = new User()
|
|
adminUser.set('permissions', ['whatever', 'admin', 'user'])
|
|
expect(adminUser.isAdmin()).toBeTruthy()
|
|
done()
|
|
|
|
it 'returns false if user has no permissions', (done) ->
|
|
myUser = new User()
|
|
myUser.set('permissions', [])
|
|
expect(myUser.isAdmin()).toBeFalsy()
|
|
done()
|
|
|
|
it 'returns false if user has other permissions', (done) ->
|
|
classicUser = new User()
|
|
classicUser.set('permissions', ['user'])
|
|
expect(classicUser.isAdmin()).toBeFalsy()
|
|
done()
|
|
|
|
describe '.verificationCode(timestamp)', ->
|
|
it 'returns a timestamp and a hash', (done) ->
|
|
user = new User()
|
|
now = new Date()
|
|
code = user.verificationCode(now.getTime())
|
|
expect(code).toMatch(/[0-9]{13}:[0-9a-f]{64}/)
|
|
[timestamp, hash] = code.split(':')
|
|
expect(new Date(parseInt(timestamp))).toEqual(now)
|
|
done()
|