/**
  * Registers a new user.
  *
  * @param array $data          user data
  * @param bool  $verifiedEmail true if the email has been verified
  *
  * @return bool success
  */
 public static function registerUser(array $data, $verifiedEmail = false)
 {
     $app = Application::getDefault();
     $email = array_value($data, 'email');
     $tempUser = static::getTemporaryUser($email);
     // upgrade temporary account
     if ($tempUser && $tempUser->upgradeTemporaryAccount($data)) {
         return $tempUser;
     }
     $user = new static();
     if ($user->create($data)) {
         if (!$verifiedEmail) {
             $app['auth']->sendVerificationEmail($user);
         } else {
             // send the user a welcome message
             $user->sendEmail('welcome');
         }
         return $user;
     }
     return false;
 }
 /**
  * Hashes a token.
  *
  * @param string $token
  *
  * @return string hashed token
  */
 private function hash($token)
 {
     $app = Application::getDefault();
     $salt = $app['config']->get('app.salt');
     return hash_hmac('sha512', $token, $salt);
 }