From 94e3c5a2b57b179fdb83a2159cb0634787e55388 Mon Sep 17 00:00:00 2001 From: phoenixeliot Date: Mon, 1 Aug 2016 14:12:35 -0700 Subject: [PATCH] Add first/last names to Account Settings --- app/styles/account/account-settings-view.sass | 6 +++--- .../account/account-settings-view.jade | 21 +++++++++++++++---- app/views/account/AccountSettingsView.coffee | 2 ++ server/models/User.coffee | 5 +++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/styles/account/account-settings-view.sass b/app/styles/account/account-settings-view.sass index ae8cd31de..1aa995013 100644 --- a/app/styles/account/account-settings-view.sass +++ b/app/styles/account/account-settings-view.sass @@ -2,6 +2,8 @@ //- Fixed save button #site-content-area + width: auto + max-width: 1024px padding-bottom: 44px #save-button-container @@ -20,9 +22,7 @@ opacity: 1.0 #account-settings-view - - .row - padding-top: 20px + padding-top: 20px //- Panels .panel-heading diff --git a/app/templates/account/account-settings-view.jade b/app/templates/account/account-settings-view.jade index ca424511f..beb395b4d 100644 --- a/app/templates/account/account-settings-view.jade +++ b/app/templates/account/account-settings-view.jade @@ -10,15 +10,17 @@ else .panel-body .form - var name = me.get('name') || ''; + - var firstName = me.get('firstName') || ''; + - var lastName = me.get('lastName') || ''; - var email = me.get('email') || ''; - var admin = me.get('permissions', true).indexOf('admin') != -1; - var godmode = me.get('permissions', true).indexOf('godmode') != -1; .form-group - label.control-label(for="name", data-i18n="general.name") Name + label.control-label(for="name", data-i18n="general.username") input#name-input.form-control(name="name", type="text", value="#{name}") .form-group label.control-label(for="email") - span(data-i18n="general.email") Email + span(data-i18n="general.email") unless me.get('emailVerified') span.spl ( span.spr(data-i18n="account.not_yet_verified") @@ -27,12 +29,23 @@ else span.sent-text.hide(data-i18n="account.email_sent") span ) input#email.form-control(name="email", type="text", value="#{email}") + .row + .form-group.col-sm-6 + label.control-label(for="firstName", data-i18n="general.first_name") + input#first-name-input.form-control(name="firstName", type="text", value="#{firstName}") + .form-group.col-sm-6 + if me.isStudent() + label.control-label(for="lastName", data-i18n="general.last_initial") + input#last-name-input.form-control(name="lastName", type="text", value="#{lastName}", maxlength="1") + else + label.control-label(for="lastName", data-i18n="general.last_name") + input#last-name-input.form-control(name="lastName", type="text", value="#{lastName}") if !isProduction .form-group.checkbox - label(for="admin", data-i18n="account_settings.admin") Admin + label(for="admin", data-i18n="account_settings.admin") input#admin(name="admin", type="checkbox", checked=admin) .form-group.checkbox - label(for="godmode", data-i18n="account_settings.god_mode") God Mode + label(for="godmode", data-i18n="account_settings.god_mode") input#godmode(name="godmode", type="checkbox", checked=godmode) if me.hasSubscription() .form-group diff --git a/app/views/account/AccountSettingsView.coffee b/app/views/account/AccountSettingsView.coffee index 70c945b8c..e8e70ac7b 100644 --- a/app/views/account/AccountSettingsView.coffee +++ b/app/views/account/AccountSettingsView.coffee @@ -266,6 +266,8 @@ module.exports = class AccountSettingsView extends CocoView grabOtherData: -> @$el.find('#name-input').val @suggestedName if @suggestedName me.set 'name', @$el.find('#name-input').val() + me.set 'firstName', @$el.find('#first-name-input').val() + me.set 'lastName', @$el.find('#last-name-input').val() me.set 'email', @$el.find('#email').val() for emailName, enabled of @getSubscriptions() me.setEmailSubscription emailName, enabled diff --git a/server/models/User.coffee b/server/models/User.coffee index 0ed8aab85..3d843d00e 100644 --- a/server/models/User.coffee +++ b/server/models/User.coffee @@ -369,6 +369,11 @@ UserSchema.pre('save', (next) -> else @set('name', undefined) @set('nameLower', undefined) + + if _.isEmpty(@get('firstName')) + @set('firstName', undefined) + if _.isEmpty(@get('lastName')) + @set('lastName', undefined) unless email or name or @get('anonymous') or @get('deleted') return next(new errors.UnprocessableEntity('User needs a username or email address'))