mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
commit
5c19e61e6b
6 changed files with 24 additions and 12 deletions
|
@ -7,7 +7,7 @@ block content
|
|||
|Please
|
||||
a.auth-button login
|
||||
| to view this profile.
|
||||
else
|
||||
else if user.loaded
|
||||
if allowedToEditJobProfile
|
||||
.profile-control-bar
|
||||
if editing
|
||||
|
@ -486,8 +486,9 @@ block content
|
|||
span(data-i18n="account_profile.profile_for_prefix") Profile for
|
||||
span= user.get('name') || "Anonymous Wizard"
|
||||
span(data-i18n="account_profile.profile_for_suffix")
|
||||
|
||||
img.profile-photo(src=user.getPhotoURL(256))
|
||||
|
||||
if user.loaded
|
||||
img.profile-photo(src=user.getPhotoURL(256))
|
||||
|
||||
p To see a private user profile, you may need to log in.
|
||||
|
||||
|
|
|
@ -9,15 +9,14 @@ module.exports = class UserView extends RootView
|
|||
|
||||
constructor: (@userID, options) ->
|
||||
super options
|
||||
@userID ?= me.id
|
||||
@listenTo @, 'userNotFound', @ifUserNotFound
|
||||
@fetchUser @userID
|
||||
|
||||
fetchUser: (id) ->
|
||||
fetchUser: ->
|
||||
if @isMe()
|
||||
@user = me
|
||||
@onLoaded()
|
||||
@user = new User _id: id
|
||||
@user = new User _id: @userID
|
||||
@supermodel.loadModel @user, 'user'
|
||||
|
||||
getRenderData: ->
|
||||
|
@ -29,8 +28,12 @@ module.exports = class UserView extends RootView
|
|||
isMe: -> @userID is me.id
|
||||
|
||||
onLoaded: ->
|
||||
@onUserLoaded @user if @user.loaded and not @userLoaded
|
||||
super()
|
||||
|
||||
onUserLoaded: ->
|
||||
@userLoaded = true
|
||||
|
||||
ifUserNotFound: ->
|
||||
console.warn 'user not found'
|
||||
@render()
|
||||
|
|
|
@ -54,7 +54,7 @@ module.exports = class JobProfileView extends UserView
|
|||
'change #admin-contact': 'onAdminContactChanged'
|
||||
'click .session-link': 'onSessionLinkPressed'
|
||||
|
||||
constructor: (userID, options) ->
|
||||
constructor: (options, userID) ->
|
||||
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
|
||||
@onRemarkChanged = _.debounce @onRemarkChanged, 1000
|
||||
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
|
||||
|
@ -63,7 +63,7 @@ module.exports = class JobProfileView extends UserView
|
|||
window.contractCallback = =>
|
||||
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
|
||||
@render()
|
||||
super options, userID
|
||||
super userID, options
|
||||
|
||||
onLoaded: ->
|
||||
@finishInit() unless @destroyed
|
||||
|
@ -530,7 +530,7 @@ module.exports = class JobProfileView extends UserView
|
|||
console.log 'Saved UserRemark', @remark, 'with response', response
|
||||
|
||||
updateProgress: (highlightNext) ->
|
||||
return unless @user?.loaded
|
||||
return unless @user?.loaded and @sessions?.loaded
|
||||
completed = 0
|
||||
totalWeight = 0
|
||||
next = null
|
||||
|
|
3
server/lib/utils.coffee
Normal file
3
server/lib/utils.coffee
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
module.exports =
|
||||
isID: (id) -> _.isString(id) and id.length is 24 and id.match(/[a-f0-9]/gi)?.length is 24
|
|
@ -1,6 +1,7 @@
|
|||
mongoose = require('mongoose')
|
||||
textSearch = require('mongoose-text-search')
|
||||
log = require 'winston'
|
||||
utils = require '../lib/utils'
|
||||
|
||||
module.exports.MigrationPlugin = (schema, migrations) ->
|
||||
# Property name migrations made EZ
|
||||
|
@ -31,9 +32,13 @@ module.exports.NamedPlugin = (schema) ->
|
|||
schema.add({name: String, slug: String})
|
||||
schema.index({'slug': 1}, {unique: true, sparse: true, name: 'slug index'})
|
||||
|
||||
schema.statics.getBySlug = (slug, done) ->
|
||||
schema.statics.findBySlug = (slug, done) ->
|
||||
@findOne {slug: slug}, done
|
||||
|
||||
schema.statics.findBySlugOrId = (slugOrID, done) ->
|
||||
return @findById slugOrID, done if utils.isID slugOrID
|
||||
@findOne {slug: slugOrID}, done
|
||||
|
||||
schema.pre('save', (next) ->
|
||||
if schema.uses_coco_versions
|
||||
v = @get('version')
|
||||
|
|
|
@ -208,7 +208,7 @@ UserHandler = class UserHandler extends Handler
|
|||
@sendSuccess(res, {result: 'success'})
|
||||
|
||||
avatar: (req, res, id) ->
|
||||
@modelClass.findById(id).exec (err, document) =>
|
||||
@modelClass.findBySlugOrId(id).exec (err, document) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless document
|
||||
photoURL = document?.get('photoURL')
|
||||
|
@ -232,7 +232,7 @@ UserHandler = class UserHandler extends Handler
|
|||
|
||||
IDify: (idOrSlug, done) ->
|
||||
return done null, idOrSlug if Handler.isID idOrSlug
|
||||
User.getBySlug idOrSlug, (err, user) -> done err, user?.get '_id'
|
||||
User.findBySlug idOrSlug, (err, user) -> done err, user?.get '_id'
|
||||
|
||||
getLevelSessions: (req, res, userIDOrSlug) ->
|
||||
@IDify userIDOrSlug, (err, userID) =>
|
||||
|
|
Loading…
Reference in a new issue