Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Confirm password on set new password user profile #11095

Merged
merged 4 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,8 @@
"New_messages": "New messages",
"New_password": "New Password",
"New_Password_Placeholder": "Please enter new password...",
"Confirm_new_password": "Confirm New Password",
"Confirm_New_Password_Placeholder": "Please re-enter new password...",
"New_role": "New role",
"New_Room_Notification": "New Room Notification",
"New_Trigger": "New Trigger",
Expand Down Expand Up @@ -2701,4 +2703,4 @@
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices",
"Your_server_link": "Your server link",
"Your_workspace_is_ready": "Your workspace is ready to use 🎉"
}
}
10 changes: 9 additions & 1 deletion packages/rocketchat-ui-account/client/accountProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,22 @@
{{/unless}}
</div>
{{/with}}
<div class="rc-input rc-w50 padded">
<div class="rc-input {{#if confirmPasswordInvalid}}rc-input--error{{/if}} rc-w50 padded">
{{#with canChange=allowPasswordChange}}
<label class="rc-input__label">
<div class="rc-input__title">{{_ "New_password"}}</div>
<div class="rc-input__wrapper">
<input name="password" type="password" class="rc-input__element" placeholder="{{_ "New_Password_Placeholder"}}" autocomplete="new-password" {{ifThenElse canChange '' 'disabled'}}>
</div>
</label>
{{#if canConfirmNewPassword}}
<label class="rc-input__label">
<div class="rc-input__title">{{_ "Confirm_new_password"}}</div>
<div class="rc-input__wrapper">
<input name="confirm-password" type="password" class="rc-input__element" placeholder="{{_ "Confirm_New_Password_Placeholder"}}" autocomplete="confirm-new-password">
</div>
</label>
{{/if}}
{{# unless canChange}}
<div class="rc-input__description">{{_ 'Password_Change_Disabled'}}</div>
{{/unless}}
Expand Down
22 changes: 21 additions & 1 deletion packages/rocketchat-ui-account/client/accountProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const validateUsername = (username) => {
return reg.test(username);
};
const validateName = (name) => name.length;
const validatePassword = (password, confirmPassword) => {
if (!confirmPassword) {
return true;
}

return password === confirmPassword;
};
const filterNames = (old) => {
const reg = new RegExp(`^${ RocketChat.settings.get('UTF8_Names_Validation') }$`);
return [...old.replace(' ', '')].filter(f => reg.test(f)).join('');
Expand Down Expand Up @@ -51,6 +58,10 @@ Template.accountProfile.helpers({
nameInvalid() {
return !validateName(Template.instance().realname.get());
},
confirmPasswordInvalid() {
const { password, confirmPassword } = Template.instance();
return !validatePassword(password.get(), confirmPassword.get());
},
selectUrl() {
return Template.instance().url.get().trim() ? '' : 'disabled';
},
Expand Down Expand Up @@ -86,6 +97,7 @@ Template.accountProfile.helpers({
const realname = instance.realname.get();
const username = instance.username.get();
const password = instance.password.get();
const confirmPassword = instance.confirmPassword.get();
const email = instance.email.get();
const usernameAvaliable = instance.usernameAvaliable.get();
const avatar = instance.avatar.get();
Expand All @@ -100,7 +112,7 @@ Template.accountProfile.helpers({
return;
}
}
if (!avatar && user.name === realname && user.username === username && user.emails[0].address === email && !password) {
if (!avatar && user.name === realname && user.username === username && user.emails[0].address === email && (!password || password !== confirmPassword)) {
return ret;
}
if (!validateEmail(email) || (!validateUsername(username) || usernameAvaliable !== true) || !validateName(realname)) {
Expand Down Expand Up @@ -138,6 +150,10 @@ Template.accountProfile.helpers({
allowPasswordChange() {
return RocketChat.settings.get('Accounts_AllowPasswordChange');
},
canConfirmNewPassword() {
const password = Template.instance().password.get();
return RocketChat.settings.get('Accounts_AllowPasswordChange') && password && password !== '';
},
allowAvatarChange() {
return RocketChat.settings.get('Accounts_AllowUserAvatarChange');
},
Expand All @@ -154,6 +170,7 @@ Template.accountProfile.onCreated(function() {
self.email = new ReactiveVar(user.emails[0].address);
self.username = new ReactiveVar(user.username);
self.password = new ReactiveVar;
self.confirmPassword = new ReactiveVar;
self.suggestions = new ReactiveVar;
self.avatar = new ReactiveVar;
self.url = new ReactiveVar('');
Expand Down Expand Up @@ -348,6 +365,9 @@ Template.accountProfile.events({
'input [name=password]'(e, instance) {
instance.password.set(e.target.value);
},
'input [name=confirm-password]'(e, instance) {
instance.confirmPassword.set(e.target.value);
},
'submit form'(e, instance) {
e.preventDefault();
const user = Meteor.user();
Expand Down