saltcorn icon indicating copy to clipboard operation
saltcorn copied to clipboard

Feature Request: Users overview

Open Txikivasco opened this issue 1 year ago • 7 comments

I've been thinking that the users panel is kind of lacking default features. For instance, I would like to see when registered users log in the app.

The solution could be something like a join table for each user that automatically registers a "date" field on a log in/log off event and maybe display on the users pannel the last time a user logged in.

Txikivasco avatar Aug 29 '23 07:08 Txikivasco

@Txikivasco You can do something very similar with Events and on "Login" action triggers.

serge402 avatar Aug 29 '23 13:08 serge402

But I have to add an event for each user manually?

Txikivasco avatar Aug 29 '23 15:08 Txikivasco

@Txikivasco No, you can use the user.id for the context. Here is my trigger.

	var date = new Date();
	var current_date = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+ date.getDate();
	var current_time = date.getHours()+":"+date.getMinutes()+":"+ date.getSeconds();
	var date_time = current_date+", "+current_time;	
console.log(date_time); // 👉️ "7-25-2023"
for (var i = 0; i < 1; i++) {
    await Table.findOne({name: 'users'}).tryUpdateRow(({lastlogin: date_time}), user.id);
}

cfredericksen avatar Aug 29 '23 17:08 cfredericksen

@cfredericksen Please don't do like this. Just define lastlogin field type as Date and insert new Date() there.

@glutamate Catching (and logging) of Login event will work on your own saltcorn instance, but not on saltcorn.com tenant.

pyhedgehog avatar Sep 09 '23 21:09 pyhedgehog

@cfredericksen Please don't do like this. Just define lastlogin field type as Date and insert new Date() there.

@glutamate Catching (and logging) of Login event will work on your own saltcorn instance, but not on saltcorn.com tenant.

@pyhedgehog I couldn't get it working on my self-hosted Saltcorn tenant. Is there a reason I shouldn't do it this way? I have an update and an insert event that occurs during login.

cfredericksen avatar Sep 09 '23 23:09 cfredericksen

@glutamate Catching (and logging) of Login event will work on your own saltcorn instance, but not on saltcorn.com tenant.

And that's precisely the reason why it needs to be a default feature, so we don't need any workaround, event or trigger.

Txikivasco avatar Sep 10 '23 04:09 Txikivasco

@pyhedgehog I updated the login trigger. I ran into search errors with the previous code.

var now = Date()
var current = new Date(now).toISOString();
for (var i = 0; i < 1; i++) {
    await Table.findOne({name: 'users'}).tryUpdateRow(({lastlogin: current}), user.id);
}

cfredericksen avatar Jan 02 '24 13:01 cfredericksen