diff --git a/db/mappings/user.js b/db/mappings/user.js index 554e324..55b1007 100644 --- a/db/mappings/user.js +++ b/db/mappings/user.js @@ -8,6 +8,7 @@ module.exports = [ 'email_confirmed', 'time_registered', 'time_email_confirmed', + 'time_password_changed', 'last_active', 'num_orders', 'is_admin' @@ -21,6 +22,7 @@ module.exports = [ 'email_confirmed', 'time_registered', 'time_email_confirmed', + 'time_password_changed', 'is_admin' ], collections: [ diff --git a/db/sql/1-tables.sql b/db/sql/1-tables.sql index 2eabe9a..3d8ec4c 100644 --- a/db/sql/1-tables.sql +++ b/db/sql/1-tables.sql @@ -9,6 +9,7 @@ create table sos."user" ( user_email citext unique not null, user_email_confirmed boolean not null default false, user_password_hash varchar(60), + user_time_password_changed timestamptz not null default now(), user_time_registered timestamptz not null default now(), user_time_email_confirmed timestamptz, user_is_admin bool not null default false diff --git a/db/sql/2-views.sql b/db/sql/2-views.sql index b227b0c..84ffe4e 100644 --- a/db/sql/2-views.sql +++ b/db/sql/2-views.sql @@ -41,6 +41,7 @@ create or replace view sos.v_session as "session_user".user_password_hash as session_user_password_hash, "session_user".user_time_registered as session_user_time_registered, "session_user".user_time_email_confirmed as session_user_time_email_confirmed, + "session_user".user_time_password_changed as session_user_time_password_changed, "session_user".user_is_admin as session_user_is_admin, v_cart.* from sos."session" diff --git a/db/sql/3-functions.sql b/db/sql/3-functions.sql index 8f3abbc..a265184 100644 --- a/db/sql/3-functions.sql +++ b/db/sql/3-functions.sql @@ -22,7 +22,13 @@ create or replace function sos.change_password(_user_uuid uuid, _new_hash text) as $function$ begin update sos."user" - set user_password_hash = _new_hash + set ( + user_password_hash, + user_time_password_changed + ) = ( + _new_hash, + now() + ) where user_uuid = _user_uuid; return query select * from sos."user" where user_uuid = _user_uuid; diff --git a/pages/account/index.js b/pages/account/index.js index 8ea397d..390c8e8 100644 --- a/pages/account/index.js +++ b/pages/account/index.js @@ -41,10 +41,14 @@ export default function AccountPage({orders}) {
Email: {user.email}
+Email: {user.email} Change
{/* TODO: Store date password was set so we can show "Set on [date]"? */} -Password: {!user.password_hash ? 'Unset' : <>Set. Change>}
+Password: { + !user.password_hash + ? 'Unset' + : <>Last changed {DateTime.fromISO(user.time_password_changed).toFormat('LLLL dd yyyy, h:mm a')}. Change> + }