Skip to content

Commit

Permalink
Change when UserStatus diffs are cleared
Browse files Browse the repository at this point in the history
To show "Changes saved" when signing out of concurrent sessions.
  • Loading branch information
kohler committed Nov 25, 2024
1 parent 82084e2 commit c966baa
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 33 deletions.
4 changes: 2 additions & 2 deletions batch/saveusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ private function parse_csvp(CsvParser $csv) {
while (($line = $csv->next_row())) {
$this->ustatus->set_user(Contact::make($this->conf));
$this->ustatus->clear_messages();
$this->ustatus->start_update((object) ["id" => null]);
$this->ustatus->csvreq = $line;
$this->ustatus->jval = (object) ["id" => null];
$this->ustatus->parse_csv_group("");
if (($acct = $this->ustatus->save_user($this->ustatus->jval))) {
if (($acct = $this->ustatus->save_update())) {
if ($this->quiet) {
// print nothing
} else if (empty($this->ustatus->diffs)) {
Expand Down
4 changes: 2 additions & 2 deletions etc/profilegroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"save_members": true,
"inputs": false },
{ "name": "security/reauthenticate",
"order": 1, "alias": "__reauthenticate" },
"order": 999999, "alias": "__reauthenticate" },
{ "name": "security/newpassword", "order": 100,
"title": "Change password",
"print_function": "*Security_UserInfo::print_new_password",
Expand All @@ -72,7 +72,7 @@
"request_function": "*Developer_UserInfo::request",
"save_members": true },
{ "name": "developer/reauthenticate",
"order": 1, "alias": "__reauthenticate" },
"order": 999999, "alias": "__reauthenticate" },
{ "name": "developer/tokens", "title": "API tokens", "order": 10,
"print_function": "*Developer_UserInfo::print_bearer_tokens",
"inputs": false },
Expand Down
5 changes: 3 additions & 2 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -3257,7 +3257,8 @@ function unparse_time_iso8601($timestamp) {
* @param int $now
* @return string */
function unparse_time_relative($timestamp, $now = 0, $format = 0) {
$d = abs($timestamp - ($now ? : Conf::$now));
$now = $now ? : Conf::$now;
$d = abs($timestamp - $now);
if ($d >= 5227200) {
if (!($format & 1)) {
return ($format & 8 ? "on " : "") . $this->_date_unparse($timestamp, "obscure");
Expand Down Expand Up @@ -3291,7 +3292,7 @@ function unparse_time_relative($timestamp, $now = 0, $format = 0) {
if ($format & 2) {
return $d;
} else {
return $timestamp < ($now ? : Conf::$now) ? $d . " ago" : "in " . $d;
return $timestamp < $now ? $d . " ago" : "in " . $d;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/p_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private function save_user($ustatus, $acct) {
}

// save account
return $ustatus->save_user($ustatus->jval, $acct);
return $ustatus->save_update($acct);
}


Expand Down Expand Up @@ -312,7 +312,7 @@ private function save_bulk($text, $filename) {
while (($line = $csv->next_row())) {
$ustatus->set_user(Contact::make_placeholder($this->conf));
$ustatus->clear_messages();
$ustatus->jval = (object) ["id" => null];
$ustatus->start_update((object) ["id" => null]);
$ustatus->csvreq = $line;
$ustatus->parse_csv_group("");
$ustatus->notify = friendly_boolean($line["notify"]) ?? true;
Expand Down Expand Up @@ -367,7 +367,7 @@ private function handle_save() {

// prepare UserStatus
$this->ustatus->set_user($this->user);
$this->ustatus->jval = (object) ["id" => $this->user->has_account_here() ? $this->user->contactId : "new"];
$this->ustatus->start_update((object) ["id" => $this->user->has_account_here() ? $this->user->contactId : "new"]);
$this->ustatus->no_deprivilege_self = true;
if ($this->page_type !== 0) {
$this->ustatus->update_profile_if_empty = true;
Expand Down
4 changes: 2 additions & 2 deletions src/userinfo/u_security.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static function print_reauthenticate(UserStatus $us) {
}
$us->cs()->add_section_class("form-outline-section tag-yellow w-text")
->print_start_section("Confirm account", "reauth");
echo '<p>You must confirm your signin credentials before changing sensitive security settings.</p>';
echo '<p>Please re-enter your signin credentials to change sensitive security settings.</p>';
$original_ignore_msgs = $us->swap_ignore_messages(false);
$us->swap_ignore_messages($original_ignore_msgs);
echo '<div class="', $us->control_class("reauth:password", "f-i w-text"), '">',
Expand All @@ -75,7 +75,7 @@ static function print_reauthenticate(UserStatus $us) {
'</label>',
$us->feedback_html_at("reauth:password"),
Ht::entry("reauth:email", $us->viewer->email, ["autocomplete" => "username", "class" => "hidden ignore-diff", "readonly" => true]),
Ht::password("reauth:password", "", ["size" => 52, "autocomplete" => "current-password", "class" => "ignore-diff", "id" => "reauth:password", "autofocus" => true]),
Ht::password("reauth:password", "", ["size" => 52, "autocomplete" => "current-password", "class" => "ignore-diff", "id" => "reauth:password"]),
'</div>',
'<div class="aab aabig mb-0">',
Ht::submit("reauth", "Confirm account", ["class" => "btn-success mt-0"]),
Expand Down
40 changes: 28 additions & 12 deletions src/userstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,18 @@ static function unparse_json_main(UserStatus $us) {
}

function user_json() {
if ($this->user) {
$this->jval = (object) [];
if ($this->user->contactId > 0) {
$this->jval->id = $this->user->contactId;
}
$cs = $this->cs();
foreach ($cs->members("", "unparse_json_function") as $gj) {
$cs->call_function($gj, $gj->unparse_json_function, $gj);
}
return $this->jval;
} else {
if (!$this->user) {
return null;
}
$this->jval = (object) [];
if ($this->user->contactId > 0) {
$this->jval->id = $this->user->contactId;
}
$cs = $this->cs();
foreach ($cs->members("", "unparse_json_function") as $gj) {
$cs->call_function($gj, $gj->unparse_json_function, $gj);
}
return $this->jval;
}


Expand Down Expand Up @@ -893,14 +892,31 @@ static function crosscheck_main(UserStatus $us) {
}


/** @param object $cj */
function start_update($cj) {
assert(is_object($cj));
$this->jval = $cj;
$this->diffs = [];
$this->created = $this->notified = false;
}

/** @param object $cj
* @param ?Contact $old_user
* @return ?Contact */
function save_user($cj, $old_user = null) {
assert(is_object($cj));
assert(!$old_user || (!$this->no_create && !$this->no_modify));
$this->jval = $cj;
$this->diffs = [];
$this->created = $this->notified = false;
$this->save_update($old_user);
}

/** @param ?Contact $old_user
* @return ?Contact */
function save_update($cj, $old_user = null) {
assert(is_object($this->jval));
assert(!$old_user || (!$this->no_create && !$this->no_modify));
$cj = $this->jval;

// normalize name, including email
self::normalize_name($cj);
Expand Down
25 changes: 15 additions & 10 deletions stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1468,9 +1468,19 @@ button:hover, button:focus, button:active, button:focus-within,
border-color: #005f00;
background-image: linear-gradient(#00a200, #007f00);
}
.btn-danger {
color: #cc0000;
}
.btn-danger:hover, .btn-danger:active {
border: 1px solid #b00000;
background: #ff0000;
background-image: linear-gradient(#ee0000, #cc0000);
color: white;
}
.differs .btn-default,
.differs .btn-primary,
.btn-highlight {
.btn-highlight,
.btn-highlight.btn-danger {
border-color: #cc0000;
background: #ff0000;
background-image: linear-gradient(#ff4040, #ff0000);
Expand All @@ -1482,15 +1492,6 @@ button:hover, button:focus, button:active, button:focus-within,
border: 1px solid #b00000;
background-image: linear-gradient(#ee0000, #cc0000);
}
.btn-danger {
color: #cc0000;
}
.btn-danger:hover, .btn-danger:active {
border: 1px solid #b00000;
background: #ff0000;
background-image: linear-gradient(#ee0000, #cc0000);
color: white;
}
a.btn-default, a.btn-primary, a.btn-success, a.btn-highlight,
a.btn-default:hover, a.btn-primary:hover, a.btn-success:hover,
a.btn-highlight:hover, a.btn-danger:hover, a.btn-danger:active {
Expand Down Expand Up @@ -1690,6 +1691,10 @@ button > .licon, .btn > .licon {
position: absolute;
left: 100%;
}
.checkmark-before::before {
content: "\2713";
padding-right: 0.25em;
}
.is-mf.mf-success::after {
content: "\2713";
color: #00bb00;
Expand Down

0 comments on commit c966baa

Please sign in to comment.