Developer forum

Forum » Development » User create flow

User create flow

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

We have recently tried to implement a scenario where users should be defined as inactive and the admin would have to activate the users from the back-end

The scope was to run some code after the user is activated by the admin.

What we have noticed though (with the above setting), is that the user is created in the database initially with Active = true, then another save is performed on the user to set the Active = false. Hence it is impossible to determine when the user moved from Inactive to Active.

Solution is 9.15.7.

Is this the correct behavior? Is there any other way to determine from a notification when the user was actually activated by the admin? All our attempts so far have been unsuccessful.

We have tried several notifications, the last ones used are UserOnBeforeSave and UserSaved and we tried to compare the values for Active before and after save.

Thank you,
Adrian


Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Adrian,

You could easily expect for UserOnBeforeSave to present the "old" values, but it does not. It holds the new values and it is meant as a state where you have a chance to intervene and toggle values before saving the user to the database.

At the point of UserOnBeforeSave the new values have not yet been written to the database. So you can use it for picking the value from the database (old value) and compare it with the (new) value from the user object.  In example below I have from UI toggled Active on a user from false to true:

Alternatively, if you need to evaluate several properties you could instanciate a second user object like shown below, rather than retrieving values from the database. Like

Dynamicweb.Security.UserManagement.User.GetUserByID(user.ID);

As the user has not been saved to database, you would have a second user object with the old values, as the line above would be based on the data from the database.

I think this should give you what you need.

BR
Snedker

 

You must be logged in to post in the forum