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

changing username by admin #699

Merged
merged 4 commits into from
Sep 7, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion client/views/admin/users/adminUserEdit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ Template.adminUserEdit.onCreated ->
@save = ->
userData = { _id: Template.currentData()._id }
userData.name = $("#name", ".edit-form").val()
userData.username = $("#username", ".edit-form").val()

unless userData._id and userData.name
toastr.error TAPi18next.t 'project:The_field_is_required', TAPi18next.t 'project:Name'
else
Meteor.call 'updateUser', userData, (error, result) ->
if result
if result
toastr.success t('User_updated_successfully')
instance.cancel()
if error
Expand Down
4 changes: 4 additions & 0 deletions client/views/admin/users/adminUserEdit.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ <h3>{{name}}</h3>
<label for="name">{{_ "Name"}}</label>
<input type="text" id="name" autocomplete="off" value="{{name}}">
</div>
<div class="input-line">
<label for="username">{{_ "Username"}}</label>
<input type="text" id="username" autocomplete="off" value="{{username}}">
</div>
</form>
</div>
<nav>
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-lib/server/methods/updateUser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ Meteor.methods
unless userData.name
throw new Meteor.Error 'name-is-required', 'Name field is required'

unless userData.username
throw new Meteor.Error 'user-name-is-required', 'Username field is required'

Meteor.users.update { _id: userData._id }, { $set: { name: userData.name } }

Meteor.runAsUser userData._id, ->
Meteor.call 'setUsername', userData.username

return true