Skip to content

Commit

Permalink
Close #3001 Improve user add from admin
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marceloschmidt committed Apr 22, 2016
1 parent 96c83b4 commit 814c97c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 12 deletions.
8 changes: 7 additions & 1 deletion packages/rocketchat-lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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: <br /><ul><li>[name], [fname], [lname] for the user's full name, first name or last name, respectively.</li><li>[email] for the user's email.</li><li>[password] for the user's password.</li><li>[Site_Name] and [Site_URL] for the Application Name and URL respectively.</li></ul>",
"Activate" : "Activate",
"Activity" : "Activity",
"Add" : "Add",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
41 changes: 39 additions & 2 deletions packages/rocketchat-lib/server/methods/insertOrUpdateUser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ RocketChat.settings.addGroup 'SMTP', ->
@add 'Invitation_HTML', '<h2>You have been invited to <h1>Rocket.Chat</h1></h2><p>Go to ' + __meteor_runtime_config__?.ROOT_URL + ' and try the best open source chat solution available today!</p>', { 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 }
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-theme/assets/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -3238,6 +3238,10 @@ body:not(.is-cordova) {
}
> .input-line {
margin-top: 20px;

#password {
width: 70%;
}
}
nav {
padding: 0;
Expand Down
12 changes: 12 additions & 0 deletions packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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 = =>
Expand Down
39 changes: 30 additions & 9 deletions packages/rocketchat-ui-flextab/flex-tab/tabs/userEdit.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>{{_ "You_are_not_authorized_to_view_this_page"}}</p>
{{else}}
<div class="about clearfix">
<form class="edit-form">
<form class="edit-form" autocomplete="off">
{{#if user}}
<h3>{{user.name}}</h3>
{{else}}
Expand All @@ -21,18 +21,39 @@ <h3>{{_ "Add_User"}}</h3>
<label for="email">{{_ "E-mail"}}</label>
<input type="email" id="email" autocomplete="off" value="{{user.emails.[0].address}}">
</div>
{{#if hasPermission 'edit-other-user-password'}}
<div class="input-line">
<label for="password">{{_ "Password"}}</label>
<input type="password" id="password" autocomplete="off" value="">
</div>
<div class="input-line">
<label for="changePassword">
<input type="checkbox" id="changePassword" value="1" checked="{{user.requirePasswordChange}}">
{{_ "Require_password_change"}}
<label for="verified">
<input type="checkbox" id="verified" value="1" checked="{{user.emails.[0].verified}}">
{{_ "Verified"}}
</label>
</div>
{{#if hasPermission 'edit-other-user-password'}}
<div class="input-line">
<label for="password">{{_ "Password"}}</label>
<input type="password" id="password" autocomplete="off" value="">
<input type="button" id="randomPassword" class="button" value="{{_ "Random"}}">
</div>
<div class="input-line">
<label for="changePassword">
<input type="checkbox" id="changePassword" value="1" checked="{{requirePasswordChange}}">
{{_ "Require_password_change"}}
</label>
</div>
{{/if}}
{{#unless user}}
<div class="input-line">
<label for="joinDefaultChannels">
<input type="checkbox" id="joinDefaultChannels" value="1" checked="true">
{{_ "Join_default_channels"}}
</label>
</div>
<div class="input-line">
<label for="sendWelcomeEmail">
<input type="checkbox" id="sendWelcomeEmail" value="1" checked="true">
{{_ "Send_welcome_email"}}
</label>
</div>
{{/unless}}
<nav>
<button class='button button-block blue save'><span>{{_ "Save"}}</span></button>
<button class='button button-block cancel secondary' type="button"><span>{{_ "Cancel"}}</span></button>
Expand Down

0 comments on commit 814c97c

Please sign in to comment.