@@ -21,6 +21,7 @@ const EditUserProfileForm = ({
2121 invalid,
2222 allowChangePassword,
2323 emptyLocalPassword,
24+ canForceChangePassword,
2425 disabledNameChange,
2526 reset,
2627} ) => (
@@ -135,12 +136,14 @@ const EditUserProfileForm = ({
135136 </ p >
136137 </ div >
137138 ) : (
138- < Field
139- name = "oldPassword"
140- component = { PasswordField }
141- autoComplete = "off"
142- label = { < FormattedMessage id = "app.changePasswordForm.oldPassword" defaultMessage = "Old Password:" /> }
143- />
139+ ! canForceChangePassword && (
140+ < Field
141+ name = "oldPassword"
142+ component = { PasswordField }
143+ autoComplete = "off"
144+ label = { < FormattedMessage id = "app.changePasswordForm.oldPassword" defaultMessage = "Old Password:" /> }
145+ />
146+ )
144147 ) }
145148
146149 < Field
@@ -181,14 +184,18 @@ EditUserProfileForm.propTypes = {
181184 reset : PropTypes . func ,
182185 allowChangePassword : PropTypes . bool . isRequired ,
183186 emptyLocalPassword : PropTypes . bool . isRequired ,
187+ canForceChangePassword : PropTypes . bool . isRequired ,
184188 disabledNameChange : PropTypes . bool ,
185189} ;
186190
187- const validate = ( { firstName, lastName, email, oldPassword, password, passwordConfirm } , { allowChangePassword } ) => {
191+ const validate = (
192+ { firstName, lastName, email, oldPassword, password, passwordConfirm } ,
193+ { disabledNameChange, allowChangePassword, emptyLocalPassword, canForceChangePassword }
194+ ) => {
188195 const errors = { } ;
189196
190- if ( ! firstName ) {
191- errors [ ' firstName' ] = (
197+ if ( ! firstName && ! disabledNameChange ) {
198+ errors . firstName = (
192199 < FormattedMessage
193200 id = "app.editUserProfile.validation.emptyFirstName"
194201 defaultMessage = "First name cannot be empty."
@@ -197,22 +204,22 @@ const validate = ({ firstName, lastName, email, oldPassword, password, passwordC
197204 }
198205
199206 if ( firstName && firstName . length < 2 ) {
200- errors [ ' firstName' ] = (
207+ errors . firstName = (
201208 < FormattedMessage
202209 id = "app.editUserProfile.validation.shortFirstName"
203210 defaultMessage = "First name must contain at least 2 characters."
204211 />
205212 ) ;
206213 }
207214
208- if ( ! lastName ) {
209- errors [ ' lastName' ] = (
215+ if ( ! lastName && ! disabledNameChange ) {
216+ errors . lastName = (
210217 < FormattedMessage id = "app.editUserProfile.validation.emptyLastName" defaultMessage = "Last name cannot be empty." />
211218 ) ;
212219 }
213220
214221 if ( lastName && lastName . length < 2 ) {
215- errors [ ' lastName' ] = (
222+ errors . lastName = (
216223 < FormattedMessage
217224 id = "app.editUserProfile.validation.shortLastName"
218225 defaultMessage = "Last name must contain at least 2 characters."
@@ -221,14 +228,14 @@ const validate = ({ firstName, lastName, email, oldPassword, password, passwordC
221228 }
222229
223230 if ( email && isEmail ( email ) === false ) {
224- errors [ ' email' ] = (
231+ errors . email = (
225232 < FormattedMessage
226233 id = "app.editUserProfile.validation.emailNotValid"
227234 defaultMessage = "E-mail address is not valid."
228235 />
229236 ) ;
230237 } else if ( ! email ) {
231- errors [ ' email' ] = (
238+ errors . email = (
232239 < FormattedMessage
233240 id = "app.editUserProfile.validation.emptyEmail"
234241 defaultMessage = "E-mail address cannot be empty."
@@ -238,8 +245,17 @@ const validate = ({ firstName, lastName, email, oldPassword, password, passwordC
238245
239246 if ( allowChangePassword ) {
240247 if ( oldPassword || password || passwordConfirm ) {
248+ if ( ! oldPassword && ! emptyLocalPassword && ! canForceChangePassword ) {
249+ errors . oldPassword = (
250+ < FormattedMessage
251+ id = "app.editUserProfile.validation.emptyOldPassword"
252+ defaultMessage = "Current password has to be verified before it can be changed."
253+ />
254+ ) ;
255+ }
256+
241257 if ( ! password || password . length === 0 ) {
242- errors [ ' password' ] = (
258+ errors . password = (
243259 < FormattedMessage
244260 id = "app.editUserProfile.validation.emptyNewPassword"
245261 defaultMessage = "New password cannot be empty if you want to change your password."
@@ -248,7 +264,7 @@ const validate = ({ firstName, lastName, email, oldPassword, password, passwordC
248264 }
249265
250266 if ( password !== passwordConfirm ) {
251- errors [ ' passwordConfirm' ] = (
267+ errors . passwordConfirm = (
252268 < FormattedMessage
253269 id = "app.editUserProfile.validation.passwordsDontMatch"
254270 defaultMessage = "Passwords do not match."
@@ -257,7 +273,7 @@ const validate = ({ firstName, lastName, email, oldPassword, password, passwordC
257273 }
258274
259275 if ( password && password . length > 0 && oldPassword && oldPassword . length > 0 && password === oldPassword ) {
260- errors [ ' password' ] = (
276+ errors . password = (
261277 < FormattedMessage
262278 id = "app.editUserProfile.validation.samePasswords"
263279 defaultMessage = "Changing your password to the same password does not make any sense."
0 commit comments