Skip to content

Commit 3aeca39

Browse files
committed
last-login: Add abstracted way to update custom fields
1 parent 1be9a98 commit 3aeca39

3 files changed

Lines changed: 47 additions & 10 deletions

File tree

data/settings.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ last_login {
26002600
plugin: 'last-login',
26012601
values: setting_types.STRING,
26022602
text: `
2603-
The key that is updated in the dictionary with the last login information.`
2603+
The key that is updated in the dictionary with the last login timestamp.`
26042604
},
26052605

26062606
last_login_precision: {
@@ -2611,6 +2611,18 @@ The key that is updated in the dictionary with the last login information.`
26112611
text: `Precision for last login timestamp.`
26122612
},
26132613

2614+
last_login_dict_fields: {
2615+
default: '',
2616+
added: {
2617+
settings_last_login_dict_fields_added: false
2618+
},
2619+
plugin: 'last-login',
2620+
values: setting_types.STRING,
2621+
text: `
2622+
Space-separated list of additional \`key=value\` pairs to be updated in the
2623+
dictionary. Both keys and values support variable expansion.`
2624+
},
2625+
26142626
/* lazy-expunge plugin */
26152627

26162628
lazy_expunge_mailbox: {

data/updates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export const updates = {
155155
settings_imapc_ssl_verify_removed: '2.4.0',
156156
settings_inet_listener_type_added: '2.4.0',
157157
settings_lazy_expunge_only_last_instance_changed: '2.4.3',
158+
settings_last_login_dict_fields_added: '2.4.X',
158159
settings_login_socket_path_added: '2.4.0',
159160
settings_lmtp_user_concurrency_limit_changed: '2.4.1',
160161
settings_mail_access_groups_changed: '2.4.3',

docs/core/plugins/last_login.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ to include `%{service}`.
6060

6161
### MySQL Example
6262

63-
This includes the service and remote IP address as well.
63+
This includes the service and remote IP address as well. Using
64+
`last_login_dict_fields` ensures that both the timestamp and the IP address are
65+
updated if a login record for that user/service already exists.
6466

6567
::: code-group
6668

@@ -69,7 +71,8 @@ last_login {
6971
dict proxy {
7072
name = sql
7173
}
72-
key = last-login/%{service}/%{user}/%{remote_ip}
74+
key = last-login/%{service}/%{user}/access
75+
last_login_dict_fields = last-login/%{service}/%{user}/ip=%{remote_ip}
7376
precision = ms
7477
}
7578
@@ -82,7 +85,7 @@ dict_server {
8285
password = pass
8386
}
8487
85-
dict_map shared/last-login/$service/$user/$remote_ip {
88+
dict_map shared/last-login/$service/$user/access {
8689
sql_table = last_login
8790
value_field last_access {
8891
type = uint
@@ -94,8 +97,18 @@ dict_server {
9497
key_field service {
9598
value = $service
9699
}
97-
key_field last_ip {
98-
value = $remote_ip
100+
}
101+
102+
dict_map shared/last-login/$service/$user/ip {
103+
sql_table = last_login
104+
value_field last_ip {
105+
}
106+
107+
key_field userid {
108+
value = $user
109+
}
110+
key_field service {
111+
value = $service
99112
}
100113
}
101114
}
@@ -125,7 +138,8 @@ last_login {
125138
name = cassandra
126139
socket_path = dict-async
127140
}
128-
key = last-login/%{service}/%{user}/%{remote_ip}
141+
key = last-login/%{service}/%{user}/access
142+
last_login_dict_fields = last-login/%{service}/%{user}/ip=%{remote_ip}
129143
precision = ms
130144
}
131145
@@ -140,7 +154,7 @@ dict_server {
140154
password = pass
141155
}
142156
143-
dict_map shared/last-login/$service/$user/$remote_ip {
157+
dict_map shared/last-login/$service/$user/access {
144158
sql_table = last_login
145159
value_field last_access {
146160
type = uint
@@ -152,8 +166,18 @@ dict_server {
152166
key_field service {
153167
value = $service
154168
}
155-
key_field last_ip {
156-
value = $remote_ip
169+
}
170+
171+
dict_map shared/last-login/$service/$user/ip {
172+
sql_table = last_login
173+
value_field last_ip {
174+
}
175+
176+
key_field userid {
177+
value = $user
178+
}
179+
key_field service {
180+
value = $service
157181
}
158182
}
159183
}

0 commit comments

Comments
 (0)