From 814c97cfda72d2f20d3e55bdc71d562a676812b7 Mon Sep 17 00:00:00 2001 From: Marcelo Schmidt Date: Fri, 22 Apr 2016 10:51:46 -0300 Subject: [PATCH] Close #3001 Improve user add from admin Set autocomplete off in form tag http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off Make newly created user join default channels Improvements to create user via admin. Option to send welcome email with login details and password Buttons to generate random password Make password change on login default to YES Change enrollment to welcome Enable checkboxes after save or cancel Set e-mail verified/not verified --- packages/rocketchat-lib/i18n/en.i18n.json | 8 +++- .../server/methods/insertOrUpdateUser.coffee | 41 ++++++++++++++++++- .../server/startup/settings.coffee | 4 ++ .../assets/stylesheets/base.less | 4 ++ .../flex-tab/tabs/userEdit.coffee | 12 ++++++ .../flex-tab/tabs/userEdit.html | 39 ++++++++++++++---- 6 files changed, 96 insertions(+), 12 deletions(-) diff --git a/packages/rocketchat-lib/i18n/en.i18n.json b/packages/rocketchat-lib/i18n/en.i18n.json index 61c754de6b6..bc6bbaedc39 100644 --- a/packages/rocketchat-lib/i18n/en.i18n.json +++ b/packages/rocketchat-lib/i18n/en.i18n.json @@ -99,6 +99,8 @@ "Accounts_ShowFormLogin" : "Show form-based Login", "Accounts_UseDefaultBlockedDomainsList" : "Use Default Blocked Domains List", "Accounts_UseDNSDomainCheck" : "Use DNS Domain Check", + "Accounts_UserAddedEmail_Subject" : "User Added Welcome Email", + "Accounts_UserAddedEmail_Description" : "You may use the following placeholders:
", "Activate" : "Activate", "Activity" : "Activity", "Add" : "Add", @@ -475,6 +477,7 @@ "italics" : "italics", "join" : "Join", "Join_audio_call" : "Join audio call", + "Join_default_channels" : "Join default channels", "Join_the_Community" : "Join the Community", "Join_the_given_channel" : "Join the given channel", "Join_video_call" : "Join video call", @@ -783,6 +786,7 @@ "Query_description" : "Additional conditions for determining which users to send the email to. Unsubscribed users are automatically removed from the query. It must be a valid JSON. Example: \"{\"createdAt\":{\"$gt\":{\"$date\": \"2015-01-01T00:00:00.000Z\"}}}\"", "Quick_Search" : "Quick Search", "quote" : "quote", + "Random" : "Random", "Reactions" : "Reactions", "Recents" : "Recents", "Record" : "Record", @@ -878,6 +882,7 @@ "Send_invitation_email_success" : "You have successfully sent an invitation email to the following addresses:", "Send_invitation_email_warning" : "In order to send invitation emails, you must first configure SMTP settings.", "Send_Message" : "Send Message", + "Send_welcome_email" : "Send welcome email", "Send_your_JSON_payloads_to_this_URL" : "Send your JSON payloads to this URL.", "Sending" : "Sending...", "Service" : "Service", @@ -1084,6 +1089,7 @@ "UTF8_Names_Validation" : "UTF8 Names Validation", "UTF8_Names_Validation_Description" : "Do not allow special characters and spaces. You can use - _ and . but not at the end of the name", "Verification_email_sent" : "Verification email sent", + "Verified" : "Verified", "View_All" : "View All", "View_Logs" : "View Logs", "Viewing_room_administration" : "Viewing room administration", @@ -1137,4 +1143,4 @@ "Your_Open_Source_solution" : "Your own Open Source chat solution", "Your_password_is_wrong" : "Your password is wrong!", "Your_push_was_sent_to_s_devices" : "Your push was sent to %s devices" -} \ No newline at end of file +} diff --git a/packages/rocketchat-lib/server/methods/insertOrUpdateUser.coffee b/packages/rocketchat-lib/server/methods/insertOrUpdateUser.coffee index f74f40d1c21..84eafffc4b8 100644 --- a/packages/rocketchat-lib/server/methods/insertOrUpdateUser.coffee +++ b/packages/rocketchat-lib/server/methods/insertOrUpdateUser.coffee @@ -26,7 +26,7 @@ Meteor.methods nameValidation = new RegExp '^[0-9a-zA-Z-_.]+$' if not nameValidation.test userData.username - throw new Meteor.Error 'error-input-is-not-a-valid-field', "#{username} is not a valid username", { method: 'insertOrUpdateUser', input: username, field: 'Username' } + throw new Meteor.Error 'error-input-is-not-a-valid-field', "#{userData.username} is not a valid username", { method: 'insertOrUpdateUser', input: userData.username, field: 'Username' } if not userData._id and not userData.password throw new Meteor.Error 'error-the-field-is-required', 'The field Password is required', { method: 'insertOrUpdateUser', field: 'Password' } @@ -54,12 +54,49 @@ Meteor.methods if userData.requirePasswordChange updateUser.$set.requirePasswordChange = userData.requirePasswordChange + if userData.verified + updateUser.$set['emails.0.verified'] = true + Meteor.users.update { _id: _id }, updateUser + if userData.joinDefaultChannels + Meteor.runAsUser _id, -> + Meteor.call('joinDefaultChannels'); + + if userData.sendWelcomeEmail + html = RocketChat.settings.get('Accounts_UserAddedEmail'); + html = html.replace /\[name\]/g, userData.name or '' + html = html.replace /\[fname\]/g, _.strLeft(userData.name, ' ') or '' + html = html.replace /\[lname\]/g, _.strRightBack(userData.name, ' ') or '' + html = html.replace /\[email\]/g, userData.email or '' + html = html.replace /\[password\]/g, userData.password or '' + html = html.replace /\[Site_Name\]/g, RocketChat.settings.get("Site_Name") or '' + html = html.replace /\[Site_URL\]/g, RocketChat.settings.get("Site_Url") or '' + + email = { + to: userData.email + from: RocketChat.settings.get('From_Email'), + subject: RocketChat.settings.get('Accounts_UserAddedEmail_Subject') || TAPi18n.__("Welcome_to_the", { lng: RocketChat.settings.get('Language') || "en" }) + (RocketChat.settings.get('Site_Name') || ""), + html: html + }; + + Email.send(email); + return _id else #update user - Meteor.users.update { _id: userData._id }, { $set: { name: userData.name, requirePasswordChange: userData.requirePasswordChange } } + updateUser = { + $set: { + name: userData.name, + requirePasswordChange: userData.requirePasswordChange + } + } + if userData.verified + updateUser.$set['emails.0.verified'] = true + else + updateUser.$set['emails.0.verified'] = false + + Meteor.users.update { _id: userData._id }, updateUser RocketChat.setUsername userData._id, userData.username RocketChat.setEmail userData._id, userData.email diff --git a/packages/rocketchat-lib/server/startup/settings.coffee b/packages/rocketchat-lib/server/startup/settings.coffee index c4e39803bf7..b3ba1f01865 100644 --- a/packages/rocketchat-lib/server/startup/settings.coffee +++ b/packages/rocketchat-lib/server/startup/settings.coffee @@ -117,6 +117,10 @@ RocketChat.settings.addGroup 'SMTP', -> @add 'Invitation_HTML', '

You have been invited to

Rocket.Chat

Go to ' + __meteor_runtime_config__?.ROOT_URL + ' and try the best open source chat solution available today!

', { type: 'string', multiline: true } @add 'Accounts_Enrollment_Email', '', { type: 'string', multiline: true } + @section 'Registration via Admin', -> + @add 'Accounts_UserAddedEmail', '', { type: 'string', multiline: true, i18nLabel: 'E-mail', i18nDescription: 'Accounts_UserAddedEmail_Description' } + @add 'Accounts_UserAddedEmailSubject', '', { type: 'string', i18nLabel: "Subject" } + RocketChat.settings.addGroup 'Message', -> @add 'Message_AllowEditing', true, { type: 'boolean', public: true } diff --git a/packages/rocketchat-theme/assets/stylesheets/base.less b/packages/rocketchat-theme/assets/stylesheets/base.less index 79323a2bfc0..5dec0f1e5b8 100644 --- a/packages/rocketchat-theme/assets/stylesheets/base.less +++ b/packages/rocketchat-theme/assets/stylesheets/base.less @@ -3238,6 +3238,10 @@ body:not(.is-cordova) { } > .input-line { margin-top: 20px; + + #password { + width: 70%; + } } nav { padding: 0; diff --git a/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.coffee b/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.coffee index 2f9afcdd8de..3c5a7456c53 100644 --- a/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.coffee +++ b/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.coffee @@ -5,12 +5,20 @@ Template.userEdit.helpers user: -> return Template.instance().user + requirePasswordChange: -> + return !Template.instance().user || Template.instance().user.requirePasswordChange + Template.userEdit.events 'click .cancel': (e, t) -> e.stopPropagation() e.preventDefault() t.cancel(t.find('form')) + 'click #randomPassword': (e, t) -> + e.stopPropagation() + e.preventDefault() + $('#password').val(Random.id()) + 'submit form': (e, t) -> e.stopPropagation() e.preventDefault() @@ -22,6 +30,7 @@ Template.userEdit.onCreated -> @cancel = (form, username) => form.reset() + this.$('input[type=checkbox]').prop('checked', true); if @user @data.back(username) else @@ -32,8 +41,11 @@ Template.userEdit.onCreated -> userData.name = s.trim(this.$("#name").val()) userData.username = s.trim(this.$("#username").val()) userData.email = s.trim(this.$("#email").val()) + userData.verified = this.$("#verified:checked").length > 0 userData.password = s.trim(this.$("#password").val()) userData.requirePasswordChange = this.$("#changePassword:checked").length > 0 + userData.joinDefaultChannels = this.$("#joinDefaultChannels:checked").length > 0 + userData.sendWelcomeEmail = this.$("#sendWelcomeEmail:checked").length > 0 return userData @validate = => diff --git a/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.html b/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.html index edf6e5704ca..793b4ef8ccb 100644 --- a/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.html +++ b/packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.html @@ -3,7 +3,7 @@

{{_ "You_are_not_authorized_to_view_this_page"}}

{{else}}
-
+ {{#if user}}

{{user.name}}

{{else}} @@ -21,18 +21,39 @@
- {{#if hasPermission 'edit-other-user-password'}} -
- - -
-
+ {{#if hasPermission 'edit-other-user-password'}} +
+ + + +
+
+ +
{{/if}} + {{#unless user}} +
+ +
+
+ +
+ {{/unless}}