public function createUser(array $credential, $confirmed = null) { /* @var User $user */ $user = new $this->userModel(); if ($email = filter_var($login = $credential['login'], FILTER_VALIDATE_EMAIL)) { $user->setData('email', $email); $confirmed === null and $confirmed = !$this->options['register']['confirm_email']; $confirmed or $user->setData('confirmation_code', Text::token())->setData('confirm_method', 'sendConfirmationEmail'); } elseif (I18n::checkMobile($login)) { $user->setData('mobile', $login); $confirmed === null and $confirmed = !$this->options['register']['confirm_mobile']; $confirmed or $user->setData('confirmation_code', mt_rand(100000, 999999))->setData('confirm_method', 'sendConfirmationSms'); } else { throw new Exception(__($this->options['hints']['invalid_user_credential'])); } $user->setData('password', $this->hasher->hash($credential['password']))->setData('confirmed', $confirmed)->generateDistributedId(); if ($confirmed) { if (!$user->save()) { throw new Exception(__($this->options['hints']['unable_to_save_user']), 0, $user->getStringMessages()); } } else { $this->pushPendingConfirmation($user, $credential); } return $user; }
public function __call($method, $arguments) { if (($prefix = substr($method, 0, 3)) == 'get') { $property = Text::uncamelize(substr($method, 3)); return $this->getData($property); } elseif ($prefix == 'set') { $property = Text::uncamelize(substr($method, 3)); return $this->setData($property, fnGet($arguments, 0)); } throw new ErrorException('Call to undefined method ' . get_class($this) . '::' . $method . '()'); }
function _e($string, $newLineToBr = true) { return PhwoolconText::escapeHtml($string, $newLineToBr); }
public function login(array $credential) { if (empty($credential['login']) || empty($credential['password'])) { throw new Exception(__($this->options['hints']['invalid_user_credential'])); } if (!($user = $this->findUser($credential))) { throw new Exception(__($this->options['hints']['invalid_user_credential'])); } if (!$this->hasher->checkHash($credential['password'], $user->getData($this->options['user_fields']['password_field']))) { throw new Exception(__($this->options['hints']['invalid_password'])); } if (!empty($credential['remember']) && method_exists($user, 'setRememberToken')) { $rememberToken = Text::token() . $user->getId(); $user->setRememberToken($rememberToken); Cookies::set($cookieName = $this->options['remember_login']['cookie_key'], $rememberToken, time() + $this->options['remember_login']['ttl'], null, null, null, true); Cookies::get($cookieName)->useEncryption(false); } $this->setUserAsLoggedIn($user); return $user; }
public function generateDistributedId() { $prefix = time() - static::$_distributedOptions['start_time']; $suffix = Text::padOrTruncate(Counter::increment($this->_table), '0', 4); $id = $prefix . static::$_distributedOptions['node_id'] . $suffix; return $this->setId($id); }
public function regenerateId($deleteOldSession = true) { $this->setId(Text::token()); $this->cookieRenewedAt = 0; return $this; }