Skip to content
Snippets Groups Projects
Commit 117904c7 authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Adds ability for users to delete their own accounts

parent 1c48009c
No related branches found
No related tags found
No related merge requests found
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
"are_also_typing" : "are also typing", "are_also_typing" : "are also typing",
"are_typing" : "are typing", "are_typing" : "are typing",
"Are_you_sure" : "Are you sure?", "Are_you_sure" : "Are you sure?",
"Are_you_sure_you_want_to_delete_your_account" : "Are you sure you want to delete your account?",
"Authorization_URL" : "Authorization URL", "Authorization_URL" : "Authorization URL",
"Authorize" : "Authorize", "Authorize" : "Authorize",
"Auto_Load_Images" : "Auto Load Images", "Auto_Load_Images" : "Auto Load Images",
...@@ -146,6 +147,7 @@ ...@@ -146,6 +147,7 @@
"days" : "days", "days" : "days",
"Deactivate" : "Deactivate", "Deactivate" : "Deactivate",
"Default" : "Default", "Default" : "Default",
"Delete_my_account" : "Delete my account",
"Delete_Room_Warning" : "Deleting a room will delete all messages posted within the room. This cannot be undone.", "Delete_Room_Warning" : "Deleting a room will delete all messages posted within the room. This cannot be undone.",
"Delete_User_Warning" : "Deleting a user will delete all messages from that user as well. This cannot be undone.", "Delete_User_Warning" : "Deleting a user will delete all messages from that user as well. This cannot be undone.",
"Deleted" : "Deleted!", "Deleted" : "Deleted!",
...@@ -214,6 +216,7 @@ ...@@ -214,6 +216,7 @@
"Highlights_List" : "Highlight words", "Highlights_List" : "Highlight words",
"History" : "History", "History" : "History",
"hours" : "hours", "hours" : "hours",
"If_you_are_sure_type_in_your_password" : "If you are sure type in your password:",
"Incorrect_Password" : "Incorrect Password", "Incorrect_Password" : "Incorrect Password",
"inline_code" : "inline_code", "inline_code" : "inline_code",
"Install_Extension" : "Install Extension", "Install_Extension" : "Install Extension",
...@@ -434,6 +437,7 @@ ...@@ -434,6 +437,7 @@
"Please_wait" : "Please wait", "Please_wait" : "Please wait",
"Please_wait_activation" : "Please wait, this can take some time.", "Please_wait_activation" : "Please wait, this can take some time.",
"Please_wait_statistics" : "Please wait, statistics are being generated.", "Please_wait_statistics" : "Please wait, statistics are being generated.",
"Please_wait_while_your_account_is_being_deleted" : "Please wait while your account is being deleted...",
"Post_as" : "Post as", "Post_as" : "Post as",
"Post_to_Channel" : "Post to Channel", "Post_to_Channel" : "Post to Channel",
"Post_to_s_as_s" : "Post to <strong>%s</strong> as <strong>%s</strong>", "Post_to_s_as_s" : "Post to <strong>%s</strong> as <strong>%s</strong>",
...@@ -686,6 +690,7 @@ ...@@ -686,6 +690,7 @@
"You_need_confirm_email" : "You need to confirm your email to login!", "You_need_confirm_email" : "You need to confirm your email to login!",
"You_need_install_an_extension_to_allow_screen_sharing" : "You need install an extension to allow screen sharing", "You_need_install_an_extension_to_allow_screen_sharing" : "You need install an extension to allow screen sharing",
"You_need_to_change_your_password" : "You need to change your password", "You_need_to_change_your_password" : "You need to change your password",
"You_need_to_type_in_your_password_in_order_to_do_this" : "You need to type in your password in order to do this!",
"You_should_name_it_to_easily_manage_your_integrations" : "You should name it to easily manage your integrations.", "You_should_name_it_to_easily_manage_your_integrations" : "You should name it to easily manage your integrations.",
"You_will_not_be_able_to_recover" : "You will not be able to recover this message!", "You_will_not_be_able_to_recover" : "You will not be able to recover this message!",
"You_will_not_be_able_to_recover_file" : "You will not be able to recover this file!", "You_will_not_be_able_to_recover_file" : "You will not be able to recover this file!",
...@@ -693,5 +698,6 @@ ...@@ -693,5 +698,6 @@
"Your_file_has_been_deleted" : "Your file has been deleted.", "Your_file_has_been_deleted" : "Your file has been deleted.",
"Your_mail_was_sent_to_s" : "Your mail was sent to %s", "Your_mail_was_sent_to_s" : "Your mail was sent to %s",
"Your_Open_Source_solution" : "Your own Open Source chat solution", "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" "Your_push_was_sent_to_s_devices" : "Your push was sent to %s devices"
} }
\ No newline at end of file
...@@ -75,6 +75,7 @@ Package.onUse(function(api) { ...@@ -75,6 +75,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/addOAuthService.coffee', 'server'); api.addFiles('server/methods/addOAuthService.coffee', 'server');
api.addFiles('server/methods/checkRegistrationSecretURL.coffee', 'server'); api.addFiles('server/methods/checkRegistrationSecretURL.coffee', 'server');
api.addFiles('server/methods/clearRequirePasswordChange.js', 'server'); api.addFiles('server/methods/clearRequirePasswordChange.js', 'server');
api.addFiles('server/methods/deleteUserOwnAccount.js', 'server');
api.addFiles('server/methods/joinDefaultChannels.coffee', 'server'); api.addFiles('server/methods/joinDefaultChannels.coffee', 'server');
api.addFiles('server/methods/removeOAuthService.coffee', 'server'); api.addFiles('server/methods/removeOAuthService.coffee', 'server');
api.addFiles('server/methods/robotMethods.coffee', 'server'); api.addFiles('server/methods/robotMethods.coffee', 'server');
......
Meteor.methods({
deleteUserOwnAccount: function(password) {
if (!Meteor.userId()) {
throw new Meteor.Error('invalid-user', "[methods] deleteUserOwnAccount -> Invalid user");
}
const user = RocketChat.models.Users.findOneById(Meteor.userId());
result = Accounts._checkPassword(user, { digest: password, algorithm: 'sha-256' });
if (result.error) {
throw new Meteor.Error('invalid-password', "[methods] deleteUserOwnAccount -> Invalid password");
}
RocketChat.models.Messages.removeByUserId(Meteor.userId()); // Remove user messages
RocketChat.models.Subscriptions.findByUserId(Meteor.userId()).forEach((subscription) => {
let room = RocketChat.models.Rooms.findOneById(subscription.rid);
if (room) {
if (room.t !== 'c' && room.usernames.length === 1) {
RocketChat.models.Rooms.removeById(subscription.rid); // Remove non-channel rooms with only 1 user (the one being deleted)
}
if (room.t === 'd') {
RocketChat.models.Subscriptions.removeByRoomId(subscription.rid);
RocketChat.models.Messages.removeByRoomId(subscription.rid);
}
}
});
RocketChat.models.Subscriptions.removeByUserId(Meteor.userId()); // Remove user subscriptions
RocketChat.models.Rooms.removeByTypeContainingUsername('d', user.username); // Remove direct rooms with the user
RocketChat.models.Rooms.removeUsernameFromAll(user.username); // Remove user from all other rooms
RocketChat.models.Users.removeById(Meteor.userId()); // Remove user from users database
return true;
}
})
\ No newline at end of file
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
user-select: text; user-select: text;
} }
.text-right {
text-align: right;
}
.no-scroll { .no-scroll {
overflow: hidden !important; overflow: hidden !important;
} }
......
...@@ -84,3 +84,28 @@ Template.accountPreferences.events ...@@ -84,3 +84,28 @@ Template.accountPreferences.events
username: 'rocket.cat' username: 'rocket.cat'
title: TAPi18n.__('Desktop_Notification_Test') title: TAPi18n.__('Desktop_Notification_Test')
text: TAPi18n.__('This_is_a_desktop_notification') text: TAPi18n.__('This_is_a_desktop_notification')
'click .delete-account button': (e) ->
e.preventDefault();
swal
title: t("Are_you_sure_you_want_to_delete_your_account"),
text: t("If_you_are_sure_type_in_your_password"),
type: "input",
inputType: "password",
showCancelButton: true,
closeOnConfirm: false
, (typedPassword) =>
if typedPassword
toastr.warning(t("Please_wait_while_your_account_is_being_deleted"));
Meteor.call 'deleteUserOwnAccount', SHA256(typedPassword), (error, results) ->
if error
toastr.remove();
swal.showInputError(t("Your_password_is_wrong"));
else
swal.close();
toastr.remove();
else
swal.showInputError(t("You_need_to_type_in_your_password_in_order_to_do_this"));
return false;
...@@ -115,6 +115,9 @@ ...@@ -115,6 +115,9 @@
<div class="submit"> <div class="submit">
<button class="button"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button> <button class="button"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button>
</div> </div>
<div class="delete-account text-right">
<button class="button red"><i class="icon-trash"></i><span>{{_ "Delete_my_account"}}</span></button>
</div>
</div> </div>
</div> </div>
</section> </section>
......
...@@ -18,7 +18,8 @@ Package.onUse(function(api) { ...@@ -18,7 +18,8 @@ Package.onUse(function(api) {
'templating', 'templating',
'coffeescript', 'coffeescript',
'underscore', 'underscore',
'rocketchat:lib' 'rocketchat:lib',
'sha'
]); ]);
api.addFiles('account/account.html', 'client'); api.addFiles('account/account.html', 'client');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment