I returned to serious DotNetNuke development this year after a gap of more than a couple of years probably. And I must say, I did not see much changes as far as the public API of DotNetNuke is concerned. Yes, there have been good UI changes, some new capabilities but the underlying framework feels the same (this was in stark comparison to my last year’s experience with migration from Drupal 6 to Drupal 7, where the entire Drupal API was overhauled, and here in DotNetNuke, the framework had notched up by 2 major versions).
Anyways, a very common requirement clients demand when we deploy DotNetNuke for them is to customize DNN’s user handling capabilities specific for them (e.g. in iMLM product we developed for Multi-Level Marketing companies, the requirement was to bypass DNN’s user handling completely and create custom UI allowing managing users as “Distributors”).
So this time, I was working on ICSI’s student management website, where we were completely re-coding the site using DotNetNuke 6. And the client was not at all interested in DNN’s user concept, they were only concerned about a “Student” registered on their site. And so, we were creating custom modules for them which would allow them to manage Students.
One aspect of these module was to delete Students from our module, which I thought should have been pretty easy, as we had done this multiple times before (removing a DNN user programatically), simply invoke the following:
UserController.DeleteUser(ref u, false, false);
So, I created a test Student (aka a user), played with the profile and finally deleted it using our custom module. So far so good.
Then I went ahead and tried to create another user with the same username as the one I had just deleted, guess what, I got a “a user with the same Username already exists” error.
Caught unawares, I looked into the database and the user I had deleted was there in the tables. What the heck I thought, I just deleted this user. I was aware that DNN had introduced a soft-delete feature for users somewhere in between but I was using the API and not the UI, so the “DeleteUser” function should do what it is supposed to do, remove that user permanently.
As this was not happening, I started poking around in the UserController API, and found a new public method, the “RemoveUser” method.
So I updated my code and added a call to “RemoveUser” method after the call to “DeleteUser” method, and the next time I deleted a user using our modules, it was gone for good from the database too.
To cut the long story short, here are 2 easy lines to remove a DNN user permanently in your code:
UserController.DeleteUser(ref u, false, false); UserController.RemoveUser(u);
Here “u” is a reference to the UserInfo object you are trying to delete.
The DNN API is seeing some massive changes over the next year, up to this point you are correct, it hasn’t changed all that much.
I can’t find Usercontroller.Removeruser(userinfo) to delete user permanently. I am using DNN 5.5.1
Thanks in advance.
I want to delete user permanently so that username will be available for future use. But I can’t find Usercontroller.RemoverUser(userinfo) in my DNN version 5.5.1.
How can I use?
Thanks in advance.
I am trying to soft delete the current user if the user is not the administrator, submit his survey, after that he cant come back again and resubmit his survey. Basically in this code I am trying after the btnSubmit_Click() to do a soft delete to the user and redirect him out the system and sign him out. I am using the community version for DNN 6.x.x
This is the code
UserInfo currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
int x = currentUser.UserID;
//Get current loged user id
public int GetUserId(int currentUser)
UserInfo _currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
delete = _currentUser.IsDeleted = true;
How can I updarte the user informations after deleting?