Shows user when password last changed

main
Ashelyn Dawn 4 years ago
parent c777651ce0
commit 587b4173d4

@ -8,6 +8,7 @@ module.exports = [
'email_confirmed', 'email_confirmed',
'time_registered', 'time_registered',
'time_email_confirmed', 'time_email_confirmed',
'time_password_changed',
'last_active', 'last_active',
'num_orders', 'num_orders',
'is_admin' 'is_admin'
@ -21,6 +22,7 @@ module.exports = [
'email_confirmed', 'email_confirmed',
'time_registered', 'time_registered',
'time_email_confirmed', 'time_email_confirmed',
'time_password_changed',
'is_admin' 'is_admin'
], ],
collections: [ collections: [

@ -9,6 +9,7 @@ create table sos."user" (
user_email citext unique not null, user_email citext unique not null,
user_email_confirmed boolean not null default false, user_email_confirmed boolean not null default false,
user_password_hash varchar(60), user_password_hash varchar(60),
user_time_password_changed timestamptz not null default now(),
user_time_registered timestamptz not null default now(), user_time_registered timestamptz not null default now(),
user_time_email_confirmed timestamptz, user_time_email_confirmed timestamptz,
user_is_admin bool not null default false user_is_admin bool not null default false

@ -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_password_hash as session_user_password_hash,
"session_user".user_time_registered as session_user_time_registered, "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_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, "session_user".user_is_admin as session_user_is_admin,
v_cart.* v_cart.*
from sos."session" from sos."session"

@ -22,7 +22,13 @@ create or replace function sos.change_password(_user_uuid uuid, _new_hash text)
as $function$ as $function$
begin begin
update sos."user" 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; where user_uuid = _user_uuid;
return query select * from sos."user" where user_uuid = _user_uuid; return query select * from sos."user" where user_uuid = _user_uuid;

@ -41,10 +41,14 @@ export default function AccountPage({orders}) {
<h3>Email and Password</h3> <h3>Email and Password</h3>
<div style={{maxWidth: 700, margin: '0 auto'}}> <div style={{maxWidth: 700, margin: '0 auto'}}>
<p><strong>Email:</strong> {user.email} <button className="buttonLink">Change</button></p> <p><strong>Email:</strong> {user.email} <Link href="/account/change-email"><a>Change</a></Link></p>
{/* TODO: Store date password was set so we can show "Set on [date]"? */} {/* TODO: Store date password was set so we can show "Set on [date]"? */}
<p><strong>Password:</strong> {!user.password_hash ? 'Unset' : <>Set. <Link href="/account/change-password"><a>Change</a></Link></>}</p> <p><strong>Password:</strong> {
!user.password_hash
? 'Unset'
: <>Last changed {DateTime.fromISO(user.time_password_changed).toFormat('LLLL dd yyyy, h:mm a')}. <Link href="/account/change-password"><a>Change</a></Link></>
}</p>
</div> </div>
<h3>Your Orders</h3> <h3>Your Orders</h3>

Loading…
Cancel
Save