Airship\Cabin\Bridge\Blueprint\UserAccounts::toggleTwoFactor PHP Method

toggleTwoFactor() public method

Save the user's two-factor-authentication preferences
public toggleTwoFactor ( integer $userID, array $post ) : boolean
$userID integer
$post array
return boolean
    public function toggleTwoFactor(int $userID, array $post) : bool
    {
        if (!empty($post['reset_secret'])) {
            $this->resetTwoFactorSecret($userID);
        }
        $this->db->beginTransaction();
        $this->db->update('airship_users', ['enable_2factor' => !empty($post['enable_two_factor'])], ['userid' => $userID]);
        return $this->db->commit();
    }

Usage Example

Beispiel #1
0
 /**
  * @route my/account/2-factor
  */
 public function twoFactorSetup()
 {
     if (!$this->isLoggedIn()) {
         \Airship\redirect($this->airship_cabin_prefix);
     }
     $this->twoFactorPreamble();
     $userID = $this->getActiveUserId();
     $post = $this->post(new TwoFactorFilter());
     if ($post) {
         if ($this->acct->toggleTwoFactor($userID, $post)) {
             \Airship\redirect($this->airship_cabin_prefix . '/my/account/2-factor');
         }
     }
     $user = $this->acct->getUserAccount($userID);
     $this->lens('two_factor', ['active_link' => 'bridge-link-two-factor', 'enabled' => $user['enable_2factor'] ?? false]);
 }