repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
vgrem/phpSPO | src/SharePoint/GroupCollection.php | GroupCollection.removeByLoginName | public function removeByLoginName($groupName)
{
$qry = new InvokePostMethodQuery($this->getResourcePath(), "removeByLoginName", array($groupName));
$this->getContext()->addQuery($qry);
} | php | public function removeByLoginName($groupName)
{
$qry = new InvokePostMethodQuery($this->getResourcePath(), "removeByLoginName", array($groupName));
$this->getContext()->addQuery($qry);
} | [
"public",
"function",
"removeByLoginName",
"(",
"$",
"groupName",
")",
"{",
"$",
"qry",
"=",
"new",
"InvokePostMethodQuery",
"(",
"$",
"this",
"->",
"getResourcePath",
"(",
")",
",",
"\"removeByLoginName\"",
",",
"array",
"(",
"$",
"groupName",
")",
")",
";",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"addQuery",
"(",
"$",
"qry",
")",
";",
"}"
] | Removes the cross-site group with the specified name from the collection.
@param string $groupName The name of the group to remove. The group name is specified in its LoginName property.
@throws \Exception | [
"Removes",
"the",
"cross",
"-",
"site",
"group",
"with",
"the",
"specified",
"name",
"from",
"the",
"collection",
"."
] | train | https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/GroupCollection.php#L78-L82 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Context/Context.php | Context.execute | public function execute()
{
// step 1 - 5
$this->startStemmingProcess();
// step 6
if ($this->dictionary->contains($this->getCurrentWord())) {
$this->result = $this->getCurrentWord();
} else {
$this->result = $this->originalWord;
}
} | php | public function execute()
{
// step 1 - 5
$this->startStemmingProcess();
// step 6
if ($this->dictionary->contains($this->getCurrentWord())) {
$this->result = $this->getCurrentWord();
} else {
$this->result = $this->originalWord;
}
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"// step 1 - 5",
"$",
"this",
"->",
"startStemmingProcess",
"(",
")",
";",
"// step 6",
"if",
"(",
"$",
"this",
"->",
"dictionary",
"->",
"contains",
"(",
"$",
"this",
"->",
"getCurrentWord",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"result",
"=",
"$",
"this",
"->",
"getCurrentWord",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"result",
"=",
"$",
"this",
"->",
"originalWord",
";",
"}",
"}"
] | Execute stemming process; the result can be retrieved with getResult()
@return void | [
"Execute",
"stemming",
"process",
";",
"the",
"result",
"can",
"be",
"retrieved",
"with",
"getResult",
"()"
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Context/Context.php#L151-L162 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Context/Context.php | Context.loopPengembalianAkhiran | public function loopPengembalianAkhiran()
{
// restore prefix to form [DP+[DP+[DP]]] + Root word
$this->restorePrefix();
$removals = $this->removals;
$reversedRemovals = array_reverse($removals);
$currentWord = $this->getCurrentWord();
foreach ($reversedRemovals as $removal) {
if (!$this->isSuffixRemoval($removal)) {
continue;
}
if ($removal->getRemovedPart() == 'kan') {
$this->setCurrentWord($removal->getResult() . 'k');
// step 4, 5
$this->removePrefixes();
if ($this->dictionary->contains($this->getCurrentWord())) {
return;
}
$this->setCurrentWord($removal->getResult() . 'kan');
} else {
$this->setCurrentWord($removal->getSubject());
}
// step 4, 5
$this->removePrefixes();
if ($this->dictionary->contains($this->getCurrentWord())) {
return;
}
$this->removals = $removals;
$this->setCurrentWord($currentWord);
}
} | php | public function loopPengembalianAkhiran()
{
// restore prefix to form [DP+[DP+[DP]]] + Root word
$this->restorePrefix();
$removals = $this->removals;
$reversedRemovals = array_reverse($removals);
$currentWord = $this->getCurrentWord();
foreach ($reversedRemovals as $removal) {
if (!$this->isSuffixRemoval($removal)) {
continue;
}
if ($removal->getRemovedPart() == 'kan') {
$this->setCurrentWord($removal->getResult() . 'k');
// step 4, 5
$this->removePrefixes();
if ($this->dictionary->contains($this->getCurrentWord())) {
return;
}
$this->setCurrentWord($removal->getResult() . 'kan');
} else {
$this->setCurrentWord($removal->getSubject());
}
// step 4, 5
$this->removePrefixes();
if ($this->dictionary->contains($this->getCurrentWord())) {
return;
}
$this->removals = $removals;
$this->setCurrentWord($currentWord);
}
} | [
"public",
"function",
"loopPengembalianAkhiran",
"(",
")",
"{",
"// restore prefix to form [DP+[DP+[DP]]] + Root word",
"$",
"this",
"->",
"restorePrefix",
"(",
")",
";",
"$",
"removals",
"=",
"$",
"this",
"->",
"removals",
";",
"$",
"reversedRemovals",
"=",
"array_reverse",
"(",
"$",
"removals",
")",
";",
"$",
"currentWord",
"=",
"$",
"this",
"->",
"getCurrentWord",
"(",
")",
";",
"foreach",
"(",
"$",
"reversedRemovals",
"as",
"$",
"removal",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isSuffixRemoval",
"(",
"$",
"removal",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"removal",
"->",
"getRemovedPart",
"(",
")",
"==",
"'kan'",
")",
"{",
"$",
"this",
"->",
"setCurrentWord",
"(",
"$",
"removal",
"->",
"getResult",
"(",
")",
".",
"'k'",
")",
";",
"// step 4, 5",
"$",
"this",
"->",
"removePrefixes",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dictionary",
"->",
"contains",
"(",
"$",
"this",
"->",
"getCurrentWord",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"setCurrentWord",
"(",
"$",
"removal",
"->",
"getResult",
"(",
")",
".",
"'kan'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setCurrentWord",
"(",
"$",
"removal",
"->",
"getSubject",
"(",
")",
")",
";",
"}",
"// step 4, 5",
"$",
"this",
"->",
"removePrefixes",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dictionary",
"->",
"contains",
"(",
"$",
"this",
"->",
"getCurrentWord",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"removals",
"=",
"$",
"removals",
";",
"$",
"this",
"->",
"setCurrentWord",
"(",
"$",
"currentWord",
")",
";",
"}",
"}"
] | ECS Loop Pengembalian Akhiran | [
"ECS",
"Loop",
"Pengembalian",
"Akhiran"
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Context/Context.php#L279-L316 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Context/Context.php | Context.restorePrefix | public function restorePrefix()
{
foreach ($this->removals as $i => $removal) {
if ($removal->getAffixType() == 'DP') {
// return the word before precoding (the subject of first prefix removal)
$this->setCurrentWord($removal->getSubject());
break;
}
}
foreach ($this->removals as $i => $removal) {
if ($removal->getAffixType() == 'DP') {
unset($this->removals[$i]);
}
}
} | php | public function restorePrefix()
{
foreach ($this->removals as $i => $removal) {
if ($removal->getAffixType() == 'DP') {
// return the word before precoding (the subject of first prefix removal)
$this->setCurrentWord($removal->getSubject());
break;
}
}
foreach ($this->removals as $i => $removal) {
if ($removal->getAffixType() == 'DP') {
unset($this->removals[$i]);
}
}
} | [
"public",
"function",
"restorePrefix",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"removals",
"as",
"$",
"i",
"=>",
"$",
"removal",
")",
"{",
"if",
"(",
"$",
"removal",
"->",
"getAffixType",
"(",
")",
"==",
"'DP'",
")",
"{",
"// return the word before precoding (the subject of first prefix removal)",
"$",
"this",
"->",
"setCurrentWord",
"(",
"$",
"removal",
"->",
"getSubject",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"removals",
"as",
"$",
"i",
"=>",
"$",
"removal",
")",
"{",
"if",
"(",
"$",
"removal",
"->",
"getAffixType",
"(",
")",
"==",
"'DP'",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"removals",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}"
] | Restore prefix to proceed with ECS loop pengembalian akhiran
@return void | [
"Restore",
"prefix",
"to",
"proceed",
"with",
"ECS",
"loop",
"pengembalian",
"akhiran"
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Context/Context.php#L336-L351 |
sastrawi/sastrawi | src/Sastrawi/Morphology/Disambiguator/DisambiguatorPrefixRule15a.php | DisambiguatorPrefixRule15a.disambiguate | public function disambiguate($word)
{
$matches = null;
$contains = preg_match('/^men([aiueo])(.*)$/', $word, $matches);
if ($contains === 1) {
return 'n' . $matches[1] . $matches[2];
}
} | php | public function disambiguate($word)
{
$matches = null;
$contains = preg_match('/^men([aiueo])(.*)$/', $word, $matches);
if ($contains === 1) {
return 'n' . $matches[1] . $matches[2];
}
} | [
"public",
"function",
"disambiguate",
"(",
"$",
"word",
")",
"{",
"$",
"matches",
"=",
"null",
";",
"$",
"contains",
"=",
"preg_match",
"(",
"'/^men([aiueo])(.*)$/'",
",",
"$",
"word",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"contains",
"===",
"1",
")",
"{",
"return",
"'n'",
".",
"$",
"matches",
"[",
"1",
"]",
".",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"}"
] | Disambiguate Prefix Rule 15a
Rule 15a : men{V} -> me-n{V} | [
"Disambiguate",
"Prefix",
"Rule",
"15a",
"Rule",
"15a",
":",
"men",
"{",
"V",
"}",
"-",
">",
"me",
"-",
"n",
"{",
"V",
"}"
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Morphology/Disambiguator/DisambiguatorPrefixRule15a.php#L21-L29 |
sastrawi/sastrawi | src/Sastrawi/Dictionary/ArrayDictionary.php | ArrayDictionary.addWordsFromTextFile | public function addWordsFromTextFile($filePath, $delimiter = "\n")
{
$words = explode($delimiter, file_get_contents($filePath));
$this->addWords($words);
} | php | public function addWordsFromTextFile($filePath, $delimiter = "\n")
{
$words = explode($delimiter, file_get_contents($filePath));
$this->addWords($words);
} | [
"public",
"function",
"addWordsFromTextFile",
"(",
"$",
"filePath",
",",
"$",
"delimiter",
"=",
"\"\\n\"",
")",
"{",
"$",
"words",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"file_get_contents",
"(",
"$",
"filePath",
")",
")",
";",
"$",
"this",
"->",
"addWords",
"(",
"$",
"words",
")",
";",
"}"
] | Add words from a text file to the dictionary
@param string $word
@return void | [
"Add",
"words",
"from",
"a",
"text",
"file",
"to",
"the",
"dictionary"
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Dictionary/ArrayDictionary.php#L87-L91 |
sastrawi/sastrawi | src/Sastrawi/StopWordRemover/StopWordRemover.php | StopWordRemover.remove | public function remove($text)
{
$words = explode(' ', $text);
foreach ($words as $i => $word) {
if ($this->dictionary->contains($word)) {
unset($words[$i]);
}
}
return implode(' ', $words);
} | php | public function remove($text)
{
$words = explode(' ', $text);
foreach ($words as $i => $word) {
if ($this->dictionary->contains($word)) {
unset($words[$i]);
}
}
return implode(' ', $words);
} | [
"public",
"function",
"remove",
"(",
"$",
"text",
")",
"{",
"$",
"words",
"=",
"explode",
"(",
"' '",
",",
"$",
"text",
")",
";",
"foreach",
"(",
"$",
"words",
"as",
"$",
"i",
"=>",
"$",
"word",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dictionary",
"->",
"contains",
"(",
"$",
"word",
")",
")",
"{",
"unset",
"(",
"$",
"words",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"words",
")",
";",
"}"
] | Remove stop words.
@param string $text The text which stop words to be removed
@return string The text after removal | [
"Remove",
"stop",
"words",
"."
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/StopWordRemover/StopWordRemover.php#L33-L44 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Stemmer.php | Stemmer.stem | public function stem($text)
{
$normalizedText = Filter\TextNormalizer::normalizeText($text);
$words = explode(' ', $normalizedText);
$stems = array();
foreach ($words as $word) {
$stems[] = $this->stemWord($word);
}
return implode(' ', $stems);
} | php | public function stem($text)
{
$normalizedText = Filter\TextNormalizer::normalizeText($text);
$words = explode(' ', $normalizedText);
$stems = array();
foreach ($words as $word) {
$stems[] = $this->stemWord($word);
}
return implode(' ', $stems);
} | [
"public",
"function",
"stem",
"(",
"$",
"text",
")",
"{",
"$",
"normalizedText",
"=",
"Filter",
"\\",
"TextNormalizer",
"::",
"normalizeText",
"(",
"$",
"text",
")",
";",
"$",
"words",
"=",
"explode",
"(",
"' '",
",",
"$",
"normalizedText",
")",
";",
"$",
"stems",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"words",
"as",
"$",
"word",
")",
"{",
"$",
"stems",
"[",
"]",
"=",
"$",
"this",
"->",
"stemWord",
"(",
"$",
"word",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"stems",
")",
";",
"}"
] | Stem a text string to its common stem form.
@param string $text the text string to stem, e.g : memberdayakan pembangunan
@return string common stem form, e.g : daya bangun | [
"Stem",
"a",
"text",
"string",
"to",
"its",
"common",
"stem",
"form",
"."
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Stemmer.php#L57-L69 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Stemmer.php | Stemmer.stemWord | protected function stemWord($word)
{
if ($this->isPlural($word)) {
return $this->stemPluralWord($word);
} else {
return $this->stemSingularWord($word);
}
} | php | protected function stemWord($word)
{
if ($this->isPlural($word)) {
return $this->stemPluralWord($word);
} else {
return $this->stemSingularWord($word);
}
} | [
"protected",
"function",
"stemWord",
"(",
"$",
"word",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isPlural",
"(",
"$",
"word",
")",
")",
"{",
"return",
"$",
"this",
"->",
"stemPluralWord",
"(",
"$",
"word",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"stemSingularWord",
"(",
"$",
"word",
")",
";",
"}",
"}"
] | Stem a word to its common stem form.
@param string $word the word to stem, e.g : memberdayakan
@return string common stem form, e.g : daya | [
"Stem",
"a",
"word",
"to",
"its",
"common",
"stem",
"form",
"."
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Stemmer.php#L77-L84 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Stemmer.php | Stemmer.stemPluralWord | protected function stemPluralWord($plural)
{
preg_match('/^(.*)-(.*)$/', $plural, $words);
if (!isset($words[1]) || !isset($words[2])) {
return $plural;
}
// malaikat-malaikat-nya -> malaikat malaikat-nya
$suffix = $words[2];
if (in_array($suffix, array('ku', 'mu', 'nya', 'lah', 'kah', 'tah', 'pun')) &&
preg_match('/^(.*)-(.*)$/', $words[1], $words)) {
$words[2] .= '-' . $suffix;
}
// berbalas-balasan -> balas
$rootWord1 = $this->stemSingularWord($words[1]);
$rootWord2 = $this->stemSingularWord($words[2]);
// meniru-nirukan -> tiru
if (!$this->dictionary->contains($words[2]) && $rootWord2 === $words[2]) {
$rootWord2 = $this->stemSingularWord('me' . $words[2]);
}
if ($rootWord1 == $rootWord2) {
return $rootWord1;
} else {
return $plural;
}
} | php | protected function stemPluralWord($plural)
{
preg_match('/^(.*)-(.*)$/', $plural, $words);
if (!isset($words[1]) || !isset($words[2])) {
return $plural;
}
// malaikat-malaikat-nya -> malaikat malaikat-nya
$suffix = $words[2];
if (in_array($suffix, array('ku', 'mu', 'nya', 'lah', 'kah', 'tah', 'pun')) &&
preg_match('/^(.*)-(.*)$/', $words[1], $words)) {
$words[2] .= '-' . $suffix;
}
// berbalas-balasan -> balas
$rootWord1 = $this->stemSingularWord($words[1]);
$rootWord2 = $this->stemSingularWord($words[2]);
// meniru-nirukan -> tiru
if (!$this->dictionary->contains($words[2]) && $rootWord2 === $words[2]) {
$rootWord2 = $this->stemSingularWord('me' . $words[2]);
}
if ($rootWord1 == $rootWord2) {
return $rootWord1;
} else {
return $plural;
}
} | [
"protected",
"function",
"stemPluralWord",
"(",
"$",
"plural",
")",
"{",
"preg_match",
"(",
"'/^(.*)-(.*)$/'",
",",
"$",
"plural",
",",
"$",
"words",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"words",
"[",
"1",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"words",
"[",
"2",
"]",
")",
")",
"{",
"return",
"$",
"plural",
";",
"}",
"// malaikat-malaikat-nya -> malaikat malaikat-nya",
"$",
"suffix",
"=",
"$",
"words",
"[",
"2",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"suffix",
",",
"array",
"(",
"'ku'",
",",
"'mu'",
",",
"'nya'",
",",
"'lah'",
",",
"'kah'",
",",
"'tah'",
",",
"'pun'",
")",
")",
"&&",
"preg_match",
"(",
"'/^(.*)-(.*)$/'",
",",
"$",
"words",
"[",
"1",
"]",
",",
"$",
"words",
")",
")",
"{",
"$",
"words",
"[",
"2",
"]",
".=",
"'-'",
".",
"$",
"suffix",
";",
"}",
"// berbalas-balasan -> balas",
"$",
"rootWord1",
"=",
"$",
"this",
"->",
"stemSingularWord",
"(",
"$",
"words",
"[",
"1",
"]",
")",
";",
"$",
"rootWord2",
"=",
"$",
"this",
"->",
"stemSingularWord",
"(",
"$",
"words",
"[",
"2",
"]",
")",
";",
"// meniru-nirukan -> tiru",
"if",
"(",
"!",
"$",
"this",
"->",
"dictionary",
"->",
"contains",
"(",
"$",
"words",
"[",
"2",
"]",
")",
"&&",
"$",
"rootWord2",
"===",
"$",
"words",
"[",
"2",
"]",
")",
"{",
"$",
"rootWord2",
"=",
"$",
"this",
"->",
"stemSingularWord",
"(",
"'me'",
".",
"$",
"words",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"$",
"rootWord1",
"==",
"$",
"rootWord2",
")",
"{",
"return",
"$",
"rootWord1",
";",
"}",
"else",
"{",
"return",
"$",
"plural",
";",
"}",
"}"
] | Stem a plural word to its common stem form.
Asian J. (2007) “Effective Techniques for Indonesian Text Retrieval” page 76-77.
@param string $plural the word to stem, e.g : bersama-sama
@return string common stem form, e.g : sama
@link http://researchbank.rmit.edu.au/eserv/rmit:6312/Asian.pdf | [
"Stem",
"a",
"plural",
"word",
"to",
"its",
"common",
"stem",
"form",
".",
"Asian",
"J",
".",
"(",
"2007",
")",
"“Effective",
"Techniques",
"for",
"Indonesian",
"Text",
"Retrieval”",
"page",
"76",
"-",
"77",
"."
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Stemmer.php#L109-L138 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Stemmer.php | Stemmer.stemSingularWord | protected function stemSingularWord($word)
{
$context = new Context($word, $this->dictionary, $this->visitorProvider);
$context->execute();
return $context->getResult();
} | php | protected function stemSingularWord($word)
{
$context = new Context($word, $this->dictionary, $this->visitorProvider);
$context->execute();
return $context->getResult();
} | [
"protected",
"function",
"stemSingularWord",
"(",
"$",
"word",
")",
"{",
"$",
"context",
"=",
"new",
"Context",
"(",
"$",
"word",
",",
"$",
"this",
"->",
"dictionary",
",",
"$",
"this",
"->",
"visitorProvider",
")",
";",
"$",
"context",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"context",
"->",
"getResult",
"(",
")",
";",
"}"
] | Stem a singular word to its common stem form.
@param string $word the word to stem, e.g : mengalahkan
@return string common stem form, e.g : kalah | [
"Stem",
"a",
"singular",
"word",
"to",
"its",
"common",
"stem",
"form",
"."
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Stemmer.php#L146-L152 |
sastrawi/sastrawi | src/Sastrawi/Stemmer/Filter/TextNormalizer.php | TextNormalizer.normalizeText | public static function normalizeText($text)
{
$text = strtolower($text);
$text = preg_replace('/[^a-z0-9 -]/im', ' ', $text);
$text = preg_replace('/( +)/im', ' ', $text);
return trim($text);
} | php | public static function normalizeText($text)
{
$text = strtolower($text);
$text = preg_replace('/[^a-z0-9 -]/im', ' ', $text);
$text = preg_replace('/( +)/im', ' ', $text);
return trim($text);
} | [
"public",
"static",
"function",
"normalizeText",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"strtolower",
"(",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/[^a-z0-9 -]/im'",
",",
"' '",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/( +)/im'",
",",
"' '",
",",
"$",
"text",
")",
";",
"return",
"trim",
"(",
"$",
"text",
")",
";",
"}"
] | Removes symbols & characters other than alphabetics
@param string $text
@return string normalized text | [
"Removes",
"symbols",
"&",
"characters",
"other",
"than",
"alphabetics"
] | train | https://github.com/sastrawi/sastrawi/blob/09db1bda7756fae740767ed7eb8de1b01ae859d5/src/Sastrawi/Stemmer/Filter/TextNormalizer.php#L22-L29 |
davispeixoto/Laravel-5-Salesforce | src/Davispeixoto/Laravel5Salesforce/SalesforceServiceProvider.php | SalesforceServiceProvider.register | public function register()
{
$config = __DIR__ . '/config/config.php';
$this->mergeConfigFrom($config, 'salesforce');
$this->publishes([$config => config_path('salesforce.php')]);
$this->app->singleton('salesforce', function ($app) {
$sf = new Salesforce(new Client());
$sf->connect($app['config']);
return $sf;
});
} | php | public function register()
{
$config = __DIR__ . '/config/config.php';
$this->mergeConfigFrom($config, 'salesforce');
$this->publishes([$config => config_path('salesforce.php')]);
$this->app->singleton('salesforce', function ($app) {
$sf = new Salesforce(new Client());
$sf->connect($app['config']);
return $sf;
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"config",
"=",
"__DIR__",
".",
"'/config/config.php'",
";",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"$",
"config",
",",
"'salesforce'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"config",
"=>",
"config_path",
"(",
"'salesforce.php'",
")",
"]",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'salesforce'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"sf",
"=",
"new",
"Salesforce",
"(",
"new",
"Client",
"(",
")",
")",
";",
"$",
"sf",
"->",
"connect",
"(",
"$",
"app",
"[",
"'config'",
"]",
")",
";",
"return",
"$",
"sf",
";",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/davispeixoto/Laravel-5-Salesforce/blob/e2b34e7292ecc6ecb8d5f7acbfd2cb7c1c966d0a/src/Davispeixoto/Laravel5Salesforce/SalesforceServiceProvider.php#L31-L43 |
davispeixoto/Laravel-5-Salesforce | src/Davispeixoto/Laravel5Salesforce/Salesforce.php | Salesforce.connect | public function connect($configExternal)
{
$wsdl = $configExternal->get('salesforce.wsdl');
if (empty($wsdl)) {
$wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml';
}
$user = $configExternal->get('salesforce.username');
$pass = $configExternal->get('salesforce.password');
$token = $configExternal->get('salesforce.token');
try {
$this->sfh->createConnection($wsdl);
$this->sfh->login($user, $pass . $token);
} catch (Exception $e) {
throw new SalesforceException('Exception at Constructor' . $e->getMessage() . "\n\n" . $e->getTraceAsString());
}
} | php | public function connect($configExternal)
{
$wsdl = $configExternal->get('salesforce.wsdl');
if (empty($wsdl)) {
$wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml';
}
$user = $configExternal->get('salesforce.username');
$pass = $configExternal->get('salesforce.password');
$token = $configExternal->get('salesforce.token');
try {
$this->sfh->createConnection($wsdl);
$this->sfh->login($user, $pass . $token);
} catch (Exception $e) {
throw new SalesforceException('Exception at Constructor' . $e->getMessage() . "\n\n" . $e->getTraceAsString());
}
} | [
"public",
"function",
"connect",
"(",
"$",
"configExternal",
")",
"{",
"$",
"wsdl",
"=",
"$",
"configExternal",
"->",
"get",
"(",
"'salesforce.wsdl'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"wsdl",
")",
")",
"{",
"$",
"wsdl",
"=",
"__DIR__",
".",
"'/Wsdl/enterprise.wsdl.xml'",
";",
"}",
"$",
"user",
"=",
"$",
"configExternal",
"->",
"get",
"(",
"'salesforce.username'",
")",
";",
"$",
"pass",
"=",
"$",
"configExternal",
"->",
"get",
"(",
"'salesforce.password'",
")",
";",
"$",
"token",
"=",
"$",
"configExternal",
"->",
"get",
"(",
"'salesforce.token'",
")",
";",
"try",
"{",
"$",
"this",
"->",
"sfh",
"->",
"createConnection",
"(",
"$",
"wsdl",
")",
";",
"$",
"this",
"->",
"sfh",
"->",
"login",
"(",
"$",
"user",
",",
"$",
"pass",
".",
"$",
"token",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SalesforceException",
"(",
"'Exception at Constructor'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"\"\\n\\n\"",
".",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"}",
"}"
] | Connect user into salesforce
@param $configExternal
@throws SalesforceException | [
"Connect",
"user",
"into",
"salesforce"
] | train | https://github.com/davispeixoto/Laravel-5-Salesforce/blob/e2b34e7292ecc6ecb8d5f7acbfd2cb7c1c966d0a/src/Davispeixoto/Laravel5Salesforce/Salesforce.php#L44-L62 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Provider.php | Provider.findById | public function findById($id)
{
$model = $this->createModel();
$group = $model->where('id', '=', $id)->find();
if ( ! $group->loaded() )
{
throw new GroupNotFoundException("A group could not be found with ID [$id].");
}
return $group;
} | php | public function findById($id)
{
$model = $this->createModel();
$group = $model->where('id', '=', $id)->find();
if ( ! $group->loaded() )
{
throw new GroupNotFoundException("A group could not be found with ID [$id].");
}
return $group;
} | [
"public",
"function",
"findById",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"group",
"=",
"$",
"model",
"->",
"where",
"(",
"'id'",
",",
"'='",
",",
"$",
"id",
")",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"group",
"->",
"loaded",
"(",
")",
")",
"{",
"throw",
"new",
"GroupNotFoundException",
"(",
"\"A group could not be found with ID [$id].\"",
")",
";",
"}",
"return",
"$",
"group",
";",
"}"
] | Find the group by ID.
@param int $id
@return \Cartalyst\Sentry\Groups\GroupInterface $group
@throws \Cartalyst\Sentry\Groups\GroupNotFoundException | [
"Find",
"the",
"group",
"by",
"ID",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Provider.php#L55-L67 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Provider.php | Provider.findByName | public function findByName($name)
{
$model = $this->createModel();
$group = $model->where('name', '=', $name)->find();
if ( ! $group->loaded() )
{
throw new GroupNotFoundException("A group could not be found with the name [$name].");
}
return $group;
} | php | public function findByName($name)
{
$model = $this->createModel();
$group = $model->where('name', '=', $name)->find();
if ( ! $group->loaded() )
{
throw new GroupNotFoundException("A group could not be found with the name [$name].");
}
return $group;
} | [
"public",
"function",
"findByName",
"(",
"$",
"name",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"group",
"=",
"$",
"model",
"->",
"where",
"(",
"'name'",
",",
"'='",
",",
"$",
"name",
")",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"group",
"->",
"loaded",
"(",
")",
")",
"{",
"throw",
"new",
"GroupNotFoundException",
"(",
"\"A group could not be found with the name [$name].\"",
")",
";",
"}",
"return",
"$",
"group",
";",
"}"
] | Find the group by name.
@param string $name
@return \Cartalyst\Sentry\Groups\GroupInterface $group
@throws \Cartalyst\Sentry\Groups\GroupNotFoundException | [
"Find",
"the",
"group",
"by",
"name",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Provider.php#L76-L88 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Provider.php | Provider.create | public function create(array $attributes)
{
if ( ! isset($credentials['permissions']) )
{
$credentials['permissions'] = array();
}
$group = $this->createModel();
$group->values($attributes, array('name', 'permissions'));
$group->save();
return $group;
} | php | public function create(array $attributes)
{
if ( ! isset($credentials['permissions']) )
{
$credentials['permissions'] = array();
}
$group = $this->createModel();
$group->values($attributes, array('name', 'permissions'));
$group->save();
return $group;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"credentials",
"[",
"'permissions'",
"]",
")",
")",
"{",
"$",
"credentials",
"[",
"'permissions'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"group",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"group",
"->",
"values",
"(",
"$",
"attributes",
",",
"array",
"(",
"'name'",
",",
"'permissions'",
")",
")",
";",
"$",
"group",
"->",
"save",
"(",
")",
";",
"return",
"$",
"group",
";",
"}"
] | Creates a group.
@param array $attributes
@return \Cartalyst\Sentry\Groups\GroupInterface | [
"Creates",
"a",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Provider.php#L108-L120 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.getPermissionsAttribute | public function getPermissionsAttribute($permissions)
{
if ( ! $permissions)
{
return array();
}
if (is_array($permissions))
{
return $permissions;
}
if ( ! $_permissions = json_decode($permissions, true))
{
throw new \InvalidArgumentException("Cannot JSON decode permissions [$permissions].");
}
return $_permissions;
} | php | public function getPermissionsAttribute($permissions)
{
if ( ! $permissions)
{
return array();
}
if (is_array($permissions))
{
return $permissions;
}
if ( ! $_permissions = json_decode($permissions, true))
{
throw new \InvalidArgumentException("Cannot JSON decode permissions [$permissions].");
}
return $_permissions;
} | [
"public",
"function",
"getPermissionsAttribute",
"(",
"$",
"permissions",
")",
"{",
"if",
"(",
"!",
"$",
"permissions",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"permissions",
")",
")",
"{",
"return",
"$",
"permissions",
";",
"}",
"if",
"(",
"!",
"$",
"_permissions",
"=",
"json_decode",
"(",
"$",
"permissions",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot JSON decode permissions [$permissions].\"",
")",
";",
"}",
"return",
"$",
"_permissions",
";",
"}"
] | Mutator for giving permissions.
@param mixed $permissions
@return array $_permissions | [
"Mutator",
"for",
"giving",
"permissions",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L213-L231 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.validate | public function validate()
{
if ( ! $login = $this->{static::$loginAttribute})
{
throw new LoginRequiredException("A login is required for a user, none given.");
}
if ( ! $password = $this->getPassword())
{
throw new PasswordRequiredException("A password is required for user [$login], none given.");
}
// Check if the user already exists
$query = $this->newQuery();
$persistedUser = $query->where($this->getLoginName(), '=', $login)->first();
if ($persistedUser and $persistedUser->getId() != $this->getId())
{
throw new UserExistsException("A user already exists with login [$login], logins must be unique for users.");
}
return true;
} | php | public function validate()
{
if ( ! $login = $this->{static::$loginAttribute})
{
throw new LoginRequiredException("A login is required for a user, none given.");
}
if ( ! $password = $this->getPassword())
{
throw new PasswordRequiredException("A password is required for user [$login], none given.");
}
// Check if the user already exists
$query = $this->newQuery();
$persistedUser = $query->where($this->getLoginName(), '=', $login)->first();
if ($persistedUser and $persistedUser->getId() != $this->getId())
{
throw new UserExistsException("A user already exists with login [$login], logins must be unique for users.");
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"login",
"=",
"$",
"this",
"->",
"{",
"static",
"::",
"$",
"loginAttribute",
"}",
")",
"{",
"throw",
"new",
"LoginRequiredException",
"(",
"\"A login is required for a user, none given.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"password",
"=",
"$",
"this",
"->",
"getPassword",
"(",
")",
")",
"{",
"throw",
"new",
"PasswordRequiredException",
"(",
"\"A password is required for user [$login], none given.\"",
")",
";",
"}",
"// Check if the user already exists",
"$",
"query",
"=",
"$",
"this",
"->",
"newQuery",
"(",
")",
";",
"$",
"persistedUser",
"=",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"getLoginName",
"(",
")",
",",
"'='",
",",
"$",
"login",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"persistedUser",
"and",
"$",
"persistedUser",
"->",
"getId",
"(",
")",
"!=",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"{",
"throw",
"new",
"UserExistsException",
"(",
"\"A user already exists with login [$login], logins must be unique for users.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validates the user and throws a number of
Exceptions if validation fails.
@return bool
@throws \Cartalyst\Sentry\Users\LoginRequiredException
@throws \Cartalyst\Sentry\Users\PasswordRequiredException
@throws \Cartalyst\Sentry\Users\UserExistsException | [
"Validates",
"the",
"user",
"and",
"throws",
"a",
"number",
"of",
"Exceptions",
"if",
"validation",
"fails",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L283-L305 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.getPersistCode | public function getPersistCode()
{
$this->persist_code = $this->getRandomString();
// Our code got hashed
$persistCode = $this->persist_code;
$this->save();
return $persistCode;
} | php | public function getPersistCode()
{
$this->persist_code = $this->getRandomString();
// Our code got hashed
$persistCode = $this->persist_code;
$this->save();
return $persistCode;
} | [
"public",
"function",
"getPersistCode",
"(",
")",
"{",
"$",
"this",
"->",
"persist_code",
"=",
"$",
"this",
"->",
"getRandomString",
"(",
")",
";",
"// Our code got hashed",
"$",
"persistCode",
"=",
"$",
"this",
"->",
"persist_code",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"return",
"$",
"persistCode",
";",
"}"
] | Gets a code for when the user is
persisted to a cookie or session which
identifies the user.
@return string | [
"Gets",
"a",
"code",
"for",
"when",
"the",
"user",
"is",
"persisted",
"to",
"a",
"cookie",
"or",
"session",
"which",
"identifies",
"the",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L338-L348 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.attemptResetPassword | public function attemptResetPassword($resetCode, $newPassword)
{
if ($this->checkResetPasswordCode($resetCode))
{
$this->password = $newPassword;
$this->reset_password_code = null;
return $this->save();
}
return false;
} | php | public function attemptResetPassword($resetCode, $newPassword)
{
if ($this->checkResetPasswordCode($resetCode))
{
$this->password = $newPassword;
$this->reset_password_code = null;
return $this->save();
}
return false;
} | [
"public",
"function",
"attemptResetPassword",
"(",
"$",
"resetCode",
",",
"$",
"newPassword",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"checkResetPasswordCode",
"(",
"$",
"resetCode",
")",
")",
"{",
"$",
"this",
"->",
"password",
"=",
"$",
"newPassword",
";",
"$",
"this",
"->",
"reset_password_code",
"=",
"null",
";",
"return",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Attempts to reset a user's password by matching
the reset code generated with the user's.
@param string $resetCode
@param string $newPassword
@return bool | [
"Attempts",
"to",
"reset",
"a",
"user",
"s",
"password",
"by",
"matching",
"the",
"reset",
"code",
"generated",
"with",
"the",
"user",
"s",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L456-L466 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.getGroups | public function getGroups()
{
if ( ! $this->userGroups)
{
$this->userGroups = $this->groups()->get();
}
return $this->userGroups;
} | php | public function getGroups()
{
if ( ! $this->userGroups)
{
$this->userGroups = $this->groups()->get();
}
return $this->userGroups;
} | [
"public",
"function",
"getGroups",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"userGroups",
")",
"{",
"$",
"this",
"->",
"userGroups",
"=",
"$",
"this",
"->",
"groups",
"(",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"userGroups",
";",
"}"
] | Returns an array of groups which the given
user belongs to.
@return array | [
"Returns",
"an",
"array",
"of",
"groups",
"which",
"the",
"given",
"user",
"belongs",
"to",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L489-L497 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.addGroup | public function addGroup(GroupInterface $group)
{
if ( ! $this->inGroup($group))
{
$this->groups()->attach($group);
$this->invalidateUserGroupsCache();
$this->invalidateMergedPermissionsCache();
}
return true;
} | php | public function addGroup(GroupInterface $group)
{
if ( ! $this->inGroup($group))
{
$this->groups()->attach($group);
$this->invalidateUserGroupsCache();
$this->invalidateMergedPermissionsCache();
}
return true;
} | [
"public",
"function",
"addGroup",
"(",
"GroupInterface",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"inGroup",
"(",
"$",
"group",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"(",
")",
"->",
"attach",
"(",
"$",
"group",
")",
";",
"$",
"this",
"->",
"invalidateUserGroupsCache",
"(",
")",
";",
"$",
"this",
"->",
"invalidateMergedPermissionsCache",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Adds the user to the given group.
@param \Cartalyst\Sentry\Groups\GroupInterface $group
@return bool | [
"Adds",
"the",
"user",
"to",
"the",
"given",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L521-L531 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.removeGroup | public function removeGroup(GroupInterface $group)
{
if ($this->inGroup($group))
{
$this->groups()->detach($group);
$this->invalidateUserGroupsCache();
$this->invalidateMergedPermissionsCache();
}
return true;
} | php | public function removeGroup(GroupInterface $group)
{
if ($this->inGroup($group))
{
$this->groups()->detach($group);
$this->invalidateUserGroupsCache();
$this->invalidateMergedPermissionsCache();
}
return true;
} | [
"public",
"function",
"removeGroup",
"(",
"GroupInterface",
"$",
"group",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"inGroup",
"(",
"$",
"group",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"(",
")",
"->",
"detach",
"(",
"$",
"group",
")",
";",
"$",
"this",
"->",
"invalidateUserGroupsCache",
"(",
")",
";",
"$",
"this",
"->",
"invalidateMergedPermissionsCache",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Removes the user from the given group.
@param \Cartalyst\Sentry\Groups\GroupInterface $group
@return bool | [
"Removes",
"the",
"user",
"from",
"the",
"given",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L539-L549 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.inGroup | public function inGroup(GroupInterface $group)
{
foreach ($this->getGroups() as $_group)
{
if ($_group->getId() == $group->getId())
{
return true;
}
}
return false;
} | php | public function inGroup(GroupInterface $group)
{
foreach ($this->getGroups() as $_group)
{
if ($_group->getId() == $group->getId())
{
return true;
}
}
return false;
} | [
"public",
"function",
"inGroup",
"(",
"GroupInterface",
"$",
"group",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getGroups",
"(",
")",
"as",
"$",
"_group",
")",
"{",
"if",
"(",
"$",
"_group",
"->",
"getId",
"(",
")",
"==",
"$",
"group",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | See if the user is in the given group.
@param \Cartalyst\Sentry\Groups\GroupInterface $group
@return bool | [
"See",
"if",
"the",
"user",
"is",
"in",
"the",
"given",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L557-L568 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.getMergedPermissions | public function getMergedPermissions()
{
if ( ! $this->mergedPermissions)
{
$permissions = array();
foreach ($this->getGroups() as $group)
{
$permissions = array_merge($permissions, $group->getPermissions());
}
$this->mergedPermissions = array_merge($permissions, $this->getPermissions());
}
return $this->mergedPermissions;
} | php | public function getMergedPermissions()
{
if ( ! $this->mergedPermissions)
{
$permissions = array();
foreach ($this->getGroups() as $group)
{
$permissions = array_merge($permissions, $group->getPermissions());
}
$this->mergedPermissions = array_merge($permissions, $this->getPermissions());
}
return $this->mergedPermissions;
} | [
"public",
"function",
"getMergedPermissions",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"mergedPermissions",
")",
"{",
"$",
"permissions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getGroups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"$",
"permissions",
"=",
"array_merge",
"(",
"$",
"permissions",
",",
"$",
"group",
"->",
"getPermissions",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"mergedPermissions",
"=",
"array_merge",
"(",
"$",
"permissions",
",",
"$",
"this",
"->",
"getPermissions",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"mergedPermissions",
";",
"}"
] | Returns an array of merged permissions for each
group the user is in.
@return array | [
"Returns",
"an",
"array",
"of",
"merged",
"permissions",
"for",
"each",
"group",
"the",
"user",
"is",
"in",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L576-L591 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.hasAccess | public function hasAccess($permissions, $all = true)
{
if ($this->isSuperUser())
{
return true;
}
return $this->hasPermission($permissions, $all);
} | php | public function hasAccess($permissions, $all = true)
{
if ($this->isSuperUser())
{
return true;
}
return $this->hasPermission($permissions, $all);
} | [
"public",
"function",
"hasAccess",
"(",
"$",
"permissions",
",",
"$",
"all",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSuperUser",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"hasPermission",
"(",
"$",
"permissions",
",",
"$",
"all",
")",
";",
"}"
] | See if a user has access to the passed permission(s).
Permissions are merged from all groups the user belongs to
and then are checked against the passed permission(s).
If multiple permissions are passed, the user must
have access to all permissions passed through, unless the
"all" flag is set to false.
Super users have access no matter what.
@param string|array $permissions
@param bool $all
@return bool | [
"See",
"if",
"a",
"user",
"has",
"access",
"to",
"the",
"passed",
"permission",
"(",
"s",
")",
".",
"Permissions",
"are",
"merged",
"from",
"all",
"groups",
"the",
"user",
"belongs",
"to",
"and",
"then",
"are",
"checked",
"against",
"the",
"passed",
"permission",
"(",
"s",
")",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L608-L616 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.getRandomString | public function getRandomString($length = 42)
{
// We'll check if the user has OpenSSL installed with PHP. If they do
// we'll use a better method of getting a random string. Otherwise, we'll
// fallback to a reasonably reliable method.
if (function_exists('openssl_random_pseudo_bytes'))
{
// We generate twice as many bytes here because we want to ensure we have
// enough after we base64 encode it to get the length we need because we
// take out the "/", "+", and "=" characters.
$bytes = openssl_random_pseudo_bytes($length * 2);
// We want to stop execution if the key fails because, well, that is bad.
if ($bytes === false)
{
throw new \RuntimeException('Unable to generate random string.');
}
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
}
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
} | php | public function getRandomString($length = 42)
{
// We'll check if the user has OpenSSL installed with PHP. If they do
// we'll use a better method of getting a random string. Otherwise, we'll
// fallback to a reasonably reliable method.
if (function_exists('openssl_random_pseudo_bytes'))
{
// We generate twice as many bytes here because we want to ensure we have
// enough after we base64 encode it to get the length we need because we
// take out the "/", "+", and "=" characters.
$bytes = openssl_random_pseudo_bytes($length * 2);
// We want to stop execution if the key fails because, well, that is bad.
if ($bytes === false)
{
throw new \RuntimeException('Unable to generate random string.');
}
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
}
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
} | [
"public",
"function",
"getRandomString",
"(",
"$",
"length",
"=",
"42",
")",
"{",
"// We'll check if the user has OpenSSL installed with PHP. If they do",
"// we'll use a better method of getting a random string. Otherwise, we'll",
"// fallback to a reasonably reliable method.",
"if",
"(",
"function_exists",
"(",
"'openssl_random_pseudo_bytes'",
")",
")",
"{",
"// We generate twice as many bytes here because we want to ensure we have",
"// enough after we base64 encode it to get the length we need because we",
"// take out the \"/\", \"+\", and \"=\" characters.",
"$",
"bytes",
"=",
"openssl_random_pseudo_bytes",
"(",
"$",
"length",
"*",
"2",
")",
";",
"// We want to stop execution if the key fails because, well, that is bad.",
"if",
"(",
"$",
"bytes",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to generate random string.'",
")",
";",
"}",
"return",
"substr",
"(",
"str_replace",
"(",
"array",
"(",
"'/'",
",",
"'+'",
",",
"'='",
")",
",",
"''",
",",
"base64_encode",
"(",
"$",
"bytes",
")",
")",
",",
"0",
",",
"$",
"length",
")",
";",
"}",
"$",
"pool",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'",
";",
"return",
"substr",
"(",
"str_shuffle",
"(",
"str_repeat",
"(",
"$",
"pool",
",",
"5",
")",
")",
",",
"0",
",",
"$",
"length",
")",
";",
"}"
] | Generate a random string.
@return string | [
"Generate",
"a",
"random",
"string",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L833-L857 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.setAttribute | public function setAttribute($key, $value)
{
// Hash required fields when necessary
if (in_array($key, $this->hashableAttributes) and ! empty($value))
{
$value = $this->hash($value);
}
return parent::setAttribute($key, $value);
} | php | public function setAttribute($key, $value)
{
// Hash required fields when necessary
if (in_array($key, $this->hashableAttributes) and ! empty($value))
{
$value = $this->hash($value);
}
return parent::setAttribute($key, $value);
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// Hash required fields when necessary",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"hashableAttributes",
")",
"and",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"hash",
"(",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Set a given attribute on the model.
@param string $key
@param mixed $value
@return void | [
"Set",
"a",
"given",
"attribute",
"on",
"the",
"model",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L876-L885 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/User.php | User.toArray | public function toArray()
{
$result = parent::toArray();
if (isset($result['activated']))
{
$result['activated'] = $this->getActivatedAttribute($result['activated']);
}
if (isset($result['permissions']))
{
$result['permissions'] = $this->getPermissionsAttribute($result['permissions']);
}
if (isset($result['suspended_at']))
{
$result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s');
}
return $result;
} | php | public function toArray()
{
$result = parent::toArray();
if (isset($result['activated']))
{
$result['activated'] = $this->getActivatedAttribute($result['activated']);
}
if (isset($result['permissions']))
{
$result['permissions'] = $this->getPermissionsAttribute($result['permissions']);
}
if (isset($result['suspended_at']))
{
$result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s');
}
return $result;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"toArray",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'activated'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'activated'",
"]",
"=",
"$",
"this",
"->",
"getActivatedAttribute",
"(",
"$",
"result",
"[",
"'activated'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'permissions'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'permissions'",
"]",
"=",
"$",
"this",
"->",
"getPermissionsAttribute",
"(",
"$",
"result",
"[",
"'permissions'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'suspended_at'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'suspended_at'",
"]",
"=",
"$",
"result",
"[",
"'suspended_at'",
"]",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Convert the model instance to an array.
@return array | [
"Convert",
"the",
"model",
"instance",
"to",
"an",
"array",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/User.php#L902-L920 |
cartalyst/sentry | src/Cartalyst/Sentry/Facades/ConnectionResolver.php | ConnectionResolver.getConnection | public function getConnection()
{
if ($this->connection === null)
{
$connection = null;
// We will now provide the query grammar to the connection.
switch ($this->driverName)
{
case 'mysql':
$connection = '\Illuminate\Database\MySqlConnection';
break;
case 'pgsql':
$connection = '\Illuminate\Database\PostgresConnection';
break;
case 'sqlsrv':
$connection = '\Illuminate\Database\SqlServerConnection';
break;
case 'sqlite':
$connection = '\Illuminate\Database\SQLiteConnection';
break;
default:
throw new \InvalidArgumentException("Cannot determine grammar to use based on {$this->driverName}.");
break;
}
$this->connection = new $connection($this->pdo, '', $this->tablePrefix);
}
return $this->connection;
} | php | public function getConnection()
{
if ($this->connection === null)
{
$connection = null;
// We will now provide the query grammar to the connection.
switch ($this->driverName)
{
case 'mysql':
$connection = '\Illuminate\Database\MySqlConnection';
break;
case 'pgsql':
$connection = '\Illuminate\Database\PostgresConnection';
break;
case 'sqlsrv':
$connection = '\Illuminate\Database\SqlServerConnection';
break;
case 'sqlite':
$connection = '\Illuminate\Database\SQLiteConnection';
break;
default:
throw new \InvalidArgumentException("Cannot determine grammar to use based on {$this->driverName}.");
break;
}
$this->connection = new $connection($this->pdo, '', $this->tablePrefix);
}
return $this->connection;
} | [
"public",
"function",
"getConnection",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
"===",
"null",
")",
"{",
"$",
"connection",
"=",
"null",
";",
"// We will now provide the query grammar to the connection.",
"switch",
"(",
"$",
"this",
"->",
"driverName",
")",
"{",
"case",
"'mysql'",
":",
"$",
"connection",
"=",
"'\\Illuminate\\Database\\MySqlConnection'",
";",
"break",
";",
"case",
"'pgsql'",
":",
"$",
"connection",
"=",
"'\\Illuminate\\Database\\PostgresConnection'",
";",
"break",
";",
"case",
"'sqlsrv'",
":",
"$",
"connection",
"=",
"'\\Illuminate\\Database\\SqlServerConnection'",
";",
"break",
";",
"case",
"'sqlite'",
":",
"$",
"connection",
"=",
"'\\Illuminate\\Database\\SQLiteConnection'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot determine grammar to use based on {$this->driverName}.\"",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"connection",
"=",
"new",
"$",
"connection",
"(",
"$",
"this",
"->",
"pdo",
",",
"''",
",",
"$",
"this",
"->",
"tablePrefix",
")",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
";",
"}"
] | Returns the database connection.
@return \Illuminate\Database\Connection
@throws \InvalidArgumentException | [
"Returns",
"the",
"database",
"connection",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/ConnectionResolver.php#L115-L149 |
cartalyst/sentry | src/Cartalyst/Sentry/Facades/CI/Sentry.php | Sentry.createSentry | public static function createSentry()
{
// Get some resources
$ci =& get_instance();
$ci->load->driver('session');
// If Eloquent doesn't exist, then we must assume they are using their own providers.
if (class_exists('Illuminate\Database\Eloquent\Model'))
{
$ci->load->database();
// Let's connect and get the PDO instance
$method = $ci->db->pconnect ? 'db_pconnect' : 'db_connect';
$pdo = $ci->db->{$method}();
// Validate PDO
if ( ! $pdo instanceof PDO)
{
throw new \RuntimeException("Sentry will only work with PDO database connections.");
}
// Setup PDO
foreach (static::$pdoOptions as $key => $value)
{
$pdo->setAttribute($key, $value);
}
$driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
$tablePrefix = substr($ci->db->dbprefix('.'), 0, -1);
Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
}
return new BaseSentry(
$userProvider = new UserProvider(new NativeHasher),
new GroupProvider,
new ThrottleProvider($userProvider),
new CISession($ci->session),
new CICookie($ci->input),
$ci->input->ip_address()
);
} | php | public static function createSentry()
{
// Get some resources
$ci =& get_instance();
$ci->load->driver('session');
// If Eloquent doesn't exist, then we must assume they are using their own providers.
if (class_exists('Illuminate\Database\Eloquent\Model'))
{
$ci->load->database();
// Let's connect and get the PDO instance
$method = $ci->db->pconnect ? 'db_pconnect' : 'db_connect';
$pdo = $ci->db->{$method}();
// Validate PDO
if ( ! $pdo instanceof PDO)
{
throw new \RuntimeException("Sentry will only work with PDO database connections.");
}
// Setup PDO
foreach (static::$pdoOptions as $key => $value)
{
$pdo->setAttribute($key, $value);
}
$driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
$tablePrefix = substr($ci->db->dbprefix('.'), 0, -1);
Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
}
return new BaseSentry(
$userProvider = new UserProvider(new NativeHasher),
new GroupProvider,
new ThrottleProvider($userProvider),
new CISession($ci->session),
new CICookie($ci->input),
$ci->input->ip_address()
);
} | [
"public",
"static",
"function",
"createSentry",
"(",
")",
"{",
"// Get some resources",
"$",
"ci",
"=",
"&",
"get_instance",
"(",
")",
";",
"$",
"ci",
"->",
"load",
"->",
"driver",
"(",
"'session'",
")",
";",
"// If Eloquent doesn't exist, then we must assume they are using their own providers.",
"if",
"(",
"class_exists",
"(",
"'Illuminate\\Database\\Eloquent\\Model'",
")",
")",
"{",
"$",
"ci",
"->",
"load",
"->",
"database",
"(",
")",
";",
"// Let's connect and get the PDO instance",
"$",
"method",
"=",
"$",
"ci",
"->",
"db",
"->",
"pconnect",
"?",
"'db_pconnect'",
":",
"'db_connect'",
";",
"$",
"pdo",
"=",
"$",
"ci",
"->",
"db",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"// Validate PDO",
"if",
"(",
"!",
"$",
"pdo",
"instanceof",
"PDO",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Sentry will only work with PDO database connections.\"",
")",
";",
"}",
"// Setup PDO",
"foreach",
"(",
"static",
"::",
"$",
"pdoOptions",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"pdo",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"driverName",
"=",
"$",
"pdo",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
";",
"$",
"tablePrefix",
"=",
"substr",
"(",
"$",
"ci",
"->",
"db",
"->",
"dbprefix",
"(",
"'.'",
")",
",",
"0",
",",
"-",
"1",
")",
";",
"Eloquent",
"::",
"setConnectionResolver",
"(",
"new",
"ConnectionResolver",
"(",
"$",
"pdo",
",",
"$",
"driverName",
",",
"$",
"tablePrefix",
")",
")",
";",
"}",
"return",
"new",
"BaseSentry",
"(",
"$",
"userProvider",
"=",
"new",
"UserProvider",
"(",
"new",
"NativeHasher",
")",
",",
"new",
"GroupProvider",
",",
"new",
"ThrottleProvider",
"(",
"$",
"userProvider",
")",
",",
"new",
"CISession",
"(",
"$",
"ci",
"->",
"session",
")",
",",
"new",
"CICookie",
"(",
"$",
"ci",
"->",
"input",
")",
",",
"$",
"ci",
"->",
"input",
"->",
"ip_address",
"(",
")",
")",
";",
"}"
] | Creates a new instance of Sentry.
@return \Cartalyst\Sentry\Sentry
@throws \RuntimeException | [
"Creates",
"a",
"new",
"instance",
"of",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/CI/Sentry.php#L56-L97 |
cartalyst/sentry | src/Cartalyst/Sentry/Cookies/FuelPHPCookie.php | FuelPHPCookie.put | public function put($value, $minutes)
{
\Cookie::set($this->getKey(), json_encode($value), $minutes);
} | php | public function put($value, $minutes)
{
\Cookie::set($this->getKey(), json_encode($value), $minutes);
} | [
"public",
"function",
"put",
"(",
"$",
"value",
",",
"$",
"minutes",
")",
"{",
"\\",
"Cookie",
"::",
"set",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"json_encode",
"(",
"$",
"value",
")",
",",
"$",
"minutes",
")",
";",
"}"
] | Put a value in the Sentry cookie.
@param mixed $value
@param int $minutes
@return void | [
"Put",
"a",
"value",
"in",
"the",
"Sentry",
"cookie",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Cookies/FuelPHPCookie.php#L60-L63 |
cartalyst/sentry | src/Cartalyst/Sentry/Hashing/NativeHasher.php | NativeHasher.hash | public function hash($string)
{
// Usually caused by an old PHP environment, see
// https://github.com/cartalyst/sentry/issues/98#issuecomment-12974603
// and https://github.com/ircmaxell/password_compat/issues/10
if ( ! function_exists('password_hash'))
{
throw new \RuntimeException('The function password_hash() does not exist, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.');
}
if (($hash = password_hash($string, PASSWORD_DEFAULT)) === false)
{
throw new \RuntimeException('Error generating hash from string, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.');
}
return $hash;
} | php | public function hash($string)
{
// Usually caused by an old PHP environment, see
// https://github.com/cartalyst/sentry/issues/98#issuecomment-12974603
// and https://github.com/ircmaxell/password_compat/issues/10
if ( ! function_exists('password_hash'))
{
throw new \RuntimeException('The function password_hash() does not exist, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.');
}
if (($hash = password_hash($string, PASSWORD_DEFAULT)) === false)
{
throw new \RuntimeException('Error generating hash from string, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.');
}
return $hash;
} | [
"public",
"function",
"hash",
"(",
"$",
"string",
")",
"{",
"// Usually caused by an old PHP environment, see",
"// https://github.com/cartalyst/sentry/issues/98#issuecomment-12974603",
"// and https://github.com/ircmaxell/password_compat/issues/10",
"if",
"(",
"!",
"function_exists",
"(",
"'password_hash'",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The function password_hash() does not exist, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.'",
")",
";",
"}",
"if",
"(",
"(",
"$",
"hash",
"=",
"password_hash",
"(",
"$",
"string",
",",
"PASSWORD_DEFAULT",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error generating hash from string, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.'",
")",
";",
"}",
"return",
"$",
"hash",
";",
"}"
] | Hash string.
@param string $string
@return string
@throws \RuntimeException | [
"Hash",
"string",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Hashing/NativeHasher.php#L52-L68 |
cartalyst/sentry | src/Cartalyst/Sentry/Hashing/NativeHasher.php | NativeHasher.checkhash | public function checkhash($string, $hashedString)
{
$verified = password_verify($string, $hashedString);
if ( ! $verified)
{
// Try the fallbacks
foreach (static::$fallbacks as $algo => $fallback)
{
$verified = $fallback['function']($string, $hashedString, $fallback['options']);
if ($verified) break;
}
}
return $verified;
} | php | public function checkhash($string, $hashedString)
{
$verified = password_verify($string, $hashedString);
if ( ! $verified)
{
// Try the fallbacks
foreach (static::$fallbacks as $algo => $fallback)
{
$verified = $fallback['function']($string, $hashedString, $fallback['options']);
if ($verified) break;
}
}
return $verified;
} | [
"public",
"function",
"checkhash",
"(",
"$",
"string",
",",
"$",
"hashedString",
")",
"{",
"$",
"verified",
"=",
"password_verify",
"(",
"$",
"string",
",",
"$",
"hashedString",
")",
";",
"if",
"(",
"!",
"$",
"verified",
")",
"{",
"// Try the fallbacks",
"foreach",
"(",
"static",
"::",
"$",
"fallbacks",
"as",
"$",
"algo",
"=>",
"$",
"fallback",
")",
"{",
"$",
"verified",
"=",
"$",
"fallback",
"[",
"'function'",
"]",
"(",
"$",
"string",
",",
"$",
"hashedString",
",",
"$",
"fallback",
"[",
"'options'",
"]",
")",
";",
"if",
"(",
"$",
"verified",
")",
"break",
";",
"}",
"}",
"return",
"$",
"verified",
";",
"}"
] | Check string against hashed string.
@param string $string
@param string $hashedString
@return bool | [
"Check",
"string",
"against",
"hashed",
"string",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Hashing/NativeHasher.php#L77-L90 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Eloquent/Group.php | Group.toArray | public function toArray()
{
$attributes = parent::toArray();
if (isset($attributes['permissions']))
{
$attributes['permissions'] = $this->getPermissionsAttribute($attributes['permissions']);
}
return $attributes;
} | php | public function toArray()
{
$attributes = parent::toArray();
if (isset($attributes['permissions']))
{
$attributes['permissions'] = $this->getPermissionsAttribute($attributes['permissions']);
}
return $attributes;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"attributes",
"=",
"parent",
"::",
"toArray",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'permissions'",
"]",
")",
")",
"{",
"$",
"attributes",
"[",
"'permissions'",
"]",
"=",
"$",
"this",
"->",
"getPermissionsAttribute",
"(",
"$",
"attributes",
"[",
"'permissions'",
"]",
")",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Convert the model instance to an array.
@return array | [
"Convert",
"the",
"model",
"instance",
"to",
"an",
"array",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Eloquent/Group.php#L342-L352 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Eloquent/Group.php | Group.validate | public function validate()
{
// Check if name field was passed
if ( ! $name = $this->name)
{
throw new NameRequiredException("A name is required for a group, none given.");
}
// Check if group already exists
$query = $this->newQuery();
$persistedGroup = $query->where('name', '=', $name)->first();
if ($persistedGroup and $persistedGroup->getId() != $this->getId())
{
throw new GroupExistsException("A group already exists with name [$name], names must be unique for groups.");
}
return true;
} | php | public function validate()
{
// Check if name field was passed
if ( ! $name = $this->name)
{
throw new NameRequiredException("A name is required for a group, none given.");
}
// Check if group already exists
$query = $this->newQuery();
$persistedGroup = $query->where('name', '=', $name)->first();
if ($persistedGroup and $persistedGroup->getId() != $this->getId())
{
throw new GroupExistsException("A group already exists with name [$name], names must be unique for groups.");
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"// Check if name field was passed",
"if",
"(",
"!",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
")",
"{",
"throw",
"new",
"NameRequiredException",
"(",
"\"A name is required for a group, none given.\"",
")",
";",
"}",
"// Check if group already exists",
"$",
"query",
"=",
"$",
"this",
"->",
"newQuery",
"(",
")",
";",
"$",
"persistedGroup",
"=",
"$",
"query",
"->",
"where",
"(",
"'name'",
",",
"'='",
",",
"$",
"name",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"persistedGroup",
"and",
"$",
"persistedGroup",
"->",
"getId",
"(",
")",
"!=",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"{",
"throw",
"new",
"GroupExistsException",
"(",
"\"A group already exists with name [$name], names must be unique for groups.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validates the group and throws a number of
Exceptions if validation fails.
@return bool
@throws \Cartalyst\Sentry\Groups\NameRequiredException
@throws \Cartalyst\Sentry\Groups\GroupExistsException | [
"Validates",
"the",
"group",
"and",
"throws",
"a",
"number",
"of",
"Exceptions",
"if",
"validation",
"fails",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Eloquent/Group.php#L362-L380 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Provider.php | Provider.findByUser | public function findByUser(UserInterface $user, $ipAddress = null)
{
$model = $this->createModel();
$query = $model->where('user_id', '=', ($userId = $user->getId()));
if ($ipAddress)
{
$query->where(function($query) use ($ipAddress) {
$query->where('ip_address', '=', $ipAddress);
$query->orWhere('ip_address', '=', NULL);
});
}
if ( ! $throttle = $query->first())
{
$throttle = $this->createModel();
$throttle->user_id = $userId;
if ($ipAddress) $throttle->ip_address = $ipAddress;
$throttle->save();
}
return $throttle;
} | php | public function findByUser(UserInterface $user, $ipAddress = null)
{
$model = $this->createModel();
$query = $model->where('user_id', '=', ($userId = $user->getId()));
if ($ipAddress)
{
$query->where(function($query) use ($ipAddress) {
$query->where('ip_address', '=', $ipAddress);
$query->orWhere('ip_address', '=', NULL);
});
}
if ( ! $throttle = $query->first())
{
$throttle = $this->createModel();
$throttle->user_id = $userId;
if ($ipAddress) $throttle->ip_address = $ipAddress;
$throttle->save();
}
return $throttle;
} | [
"public",
"function",
"findByUser",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"ipAddress",
"=",
"null",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"query",
"=",
"$",
"model",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"(",
"$",
"userId",
"=",
"$",
"user",
"->",
"getId",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"ipAddress",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"ipAddress",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'ip_address'",
",",
"'='",
",",
"$",
"ipAddress",
")",
";",
"$",
"query",
"->",
"orWhere",
"(",
"'ip_address'",
",",
"'='",
",",
"NULL",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"!",
"$",
"throttle",
"=",
"$",
"query",
"->",
"first",
"(",
")",
")",
"{",
"$",
"throttle",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"throttle",
"->",
"user_id",
"=",
"$",
"userId",
";",
"if",
"(",
"$",
"ipAddress",
")",
"$",
"throttle",
"->",
"ip_address",
"=",
"$",
"ipAddress",
";",
"$",
"throttle",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"throttle",
";",
"}"
] | Finds a throttler by the given Model.
@param \Cartalyst\Sentry\Users\UserInterface $user
@param string $ipAddress
@return \Cartalyst\Sentry\Throttling\ThrottleInterface | [
"Finds",
"a",
"throttler",
"by",
"the",
"given",
"Model",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Provider.php#L74-L96 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Provider.php | Provider.findByUserId | public function findByUserId($id, $ipAddress = null)
{
return $this->findByUser($this->userProvider->findById($id),$ipAddress);
} | php | public function findByUserId($id, $ipAddress = null)
{
return $this->findByUser($this->userProvider->findById($id),$ipAddress);
} | [
"public",
"function",
"findByUserId",
"(",
"$",
"id",
",",
"$",
"ipAddress",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"findByUser",
"(",
"$",
"this",
"->",
"userProvider",
"->",
"findById",
"(",
"$",
"id",
")",
",",
"$",
"ipAddress",
")",
";",
"}"
] | Finds a throttler by the given user ID.
@param mixed $id
@param string $ipAddress
@return \Cartalyst\Sentry\Throttling\ThrottleInterface | [
"Finds",
"a",
"throttler",
"by",
"the",
"given",
"user",
"ID",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Provider.php#L104-L107 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Provider.php | Provider.findByUserLogin | public function findByUserLogin($login, $ipAddress = null)
{
return $this->findByUser($this->userProvider->findByLogin($login),$ipAddress);
} | php | public function findByUserLogin($login, $ipAddress = null)
{
return $this->findByUser($this->userProvider->findByLogin($login),$ipAddress);
} | [
"public",
"function",
"findByUserLogin",
"(",
"$",
"login",
",",
"$",
"ipAddress",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"findByUser",
"(",
"$",
"this",
"->",
"userProvider",
"->",
"findByLogin",
"(",
"$",
"login",
")",
",",
"$",
"ipAddress",
")",
";",
"}"
] | Finds a throttling interface by the given user login.
@param string $login
@param string $ipAddress
@return \Cartalyst\Sentry\Throttling\ThrottleInterface | [
"Finds",
"a",
"throttling",
"interface",
"by",
"the",
"given",
"user",
"login",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Provider.php#L116-L119 |
cartalyst/sentry | src/Cartalyst/Sentry/Sentry.php | Sentry.register | public function register(array $credentials, $activate = false)
{
$user = $this->userProvider->create($credentials);
if ($activate)
{
$user->attemptActivation($user->getActivationCode());
}
return $this->user = $user;
} | php | public function register(array $credentials, $activate = false)
{
$user = $this->userProvider->create($credentials);
if ($activate)
{
$user->attemptActivation($user->getActivationCode());
}
return $this->user = $user;
} | [
"public",
"function",
"register",
"(",
"array",
"$",
"credentials",
",",
"$",
"activate",
"=",
"false",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"userProvider",
"->",
"create",
"(",
"$",
"credentials",
")",
";",
"if",
"(",
"$",
"activate",
")",
"{",
"$",
"user",
"->",
"attemptActivation",
"(",
"$",
"user",
"->",
"getActivationCode",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"user",
"=",
"$",
"user",
";",
"}"
] | Registers a user by giving the required credentials
and an optional flag for whether to activate the user.
@param array $credentials
@param bool $activate
@return \Cartalyst\Sentry\Users\UserInterface | [
"Registers",
"a",
"user",
"by",
"giving",
"the",
"required",
"credentials",
"and",
"an",
"optional",
"flag",
"for",
"whether",
"to",
"activate",
"the",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Sentry.php#L139-L149 |
cartalyst/sentry | src/Cartalyst/Sentry/Sentry.php | Sentry.authenticate | public function authenticate(array $credentials, $remember = false)
{
// We'll default to the login name field, but fallback to a hard-coded
// 'login' key in the array that was passed.
$loginName = $this->userProvider->getEmptyUser()->getLoginName();
$loginCredentialKey = (isset($credentials[$loginName])) ? $loginName : 'login';
if (empty($credentials[$loginCredentialKey]))
{
throw new LoginRequiredException("The [$loginCredentialKey] attribute is required.");
}
if (empty($credentials['password']))
{
throw new PasswordRequiredException('The password attribute is required.');
}
// If the user did the fallback 'login' key for the login code which
// did not match the actual login name, we'll adjust the array so the
// actual login name is provided.
if ($loginCredentialKey !== $loginName)
{
$credentials[$loginName] = $credentials[$loginCredentialKey];
unset($credentials[$loginCredentialKey]);
}
// If throttling is enabled, we'll firstly check the throttle.
// This will tell us if the user is banned before we even attempt
// to authenticate them
if ($throttlingEnabled = $this->throttleProvider->isEnabled())
{
if ($throttle = $this->throttleProvider->findByUserLogin($credentials[$loginName], $this->ipAddress))
{
$throttle->check();
}
}
try
{
$user = $this->userProvider->findByCredentials($credentials);
}
catch (UserNotFoundException $e)
{
if ($throttlingEnabled and isset($throttle))
{
$throttle->addLoginAttempt();
}
throw $e;
}
if ($throttlingEnabled and isset($throttle))
{
$throttle->clearLoginAttempts();
}
$user->clearResetPassword();
$this->login($user, $remember);
return $this->user;
} | php | public function authenticate(array $credentials, $remember = false)
{
// We'll default to the login name field, but fallback to a hard-coded
// 'login' key in the array that was passed.
$loginName = $this->userProvider->getEmptyUser()->getLoginName();
$loginCredentialKey = (isset($credentials[$loginName])) ? $loginName : 'login';
if (empty($credentials[$loginCredentialKey]))
{
throw new LoginRequiredException("The [$loginCredentialKey] attribute is required.");
}
if (empty($credentials['password']))
{
throw new PasswordRequiredException('The password attribute is required.');
}
// If the user did the fallback 'login' key for the login code which
// did not match the actual login name, we'll adjust the array so the
// actual login name is provided.
if ($loginCredentialKey !== $loginName)
{
$credentials[$loginName] = $credentials[$loginCredentialKey];
unset($credentials[$loginCredentialKey]);
}
// If throttling is enabled, we'll firstly check the throttle.
// This will tell us if the user is banned before we even attempt
// to authenticate them
if ($throttlingEnabled = $this->throttleProvider->isEnabled())
{
if ($throttle = $this->throttleProvider->findByUserLogin($credentials[$loginName], $this->ipAddress))
{
$throttle->check();
}
}
try
{
$user = $this->userProvider->findByCredentials($credentials);
}
catch (UserNotFoundException $e)
{
if ($throttlingEnabled and isset($throttle))
{
$throttle->addLoginAttempt();
}
throw $e;
}
if ($throttlingEnabled and isset($throttle))
{
$throttle->clearLoginAttempts();
}
$user->clearResetPassword();
$this->login($user, $remember);
return $this->user;
} | [
"public",
"function",
"authenticate",
"(",
"array",
"$",
"credentials",
",",
"$",
"remember",
"=",
"false",
")",
"{",
"// We'll default to the login name field, but fallback to a hard-coded",
"// 'login' key in the array that was passed.",
"$",
"loginName",
"=",
"$",
"this",
"->",
"userProvider",
"->",
"getEmptyUser",
"(",
")",
"->",
"getLoginName",
"(",
")",
";",
"$",
"loginCredentialKey",
"=",
"(",
"isset",
"(",
"$",
"credentials",
"[",
"$",
"loginName",
"]",
")",
")",
"?",
"$",
"loginName",
":",
"'login'",
";",
"if",
"(",
"empty",
"(",
"$",
"credentials",
"[",
"$",
"loginCredentialKey",
"]",
")",
")",
"{",
"throw",
"new",
"LoginRequiredException",
"(",
"\"The [$loginCredentialKey] attribute is required.\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"credentials",
"[",
"'password'",
"]",
")",
")",
"{",
"throw",
"new",
"PasswordRequiredException",
"(",
"'The password attribute is required.'",
")",
";",
"}",
"// If the user did the fallback 'login' key for the login code which",
"// did not match the actual login name, we'll adjust the array so the",
"// actual login name is provided.",
"if",
"(",
"$",
"loginCredentialKey",
"!==",
"$",
"loginName",
")",
"{",
"$",
"credentials",
"[",
"$",
"loginName",
"]",
"=",
"$",
"credentials",
"[",
"$",
"loginCredentialKey",
"]",
";",
"unset",
"(",
"$",
"credentials",
"[",
"$",
"loginCredentialKey",
"]",
")",
";",
"}",
"// If throttling is enabled, we'll firstly check the throttle.",
"// This will tell us if the user is banned before we even attempt",
"// to authenticate them",
"if",
"(",
"$",
"throttlingEnabled",
"=",
"$",
"this",
"->",
"throttleProvider",
"->",
"isEnabled",
"(",
")",
")",
"{",
"if",
"(",
"$",
"throttle",
"=",
"$",
"this",
"->",
"throttleProvider",
"->",
"findByUserLogin",
"(",
"$",
"credentials",
"[",
"$",
"loginName",
"]",
",",
"$",
"this",
"->",
"ipAddress",
")",
")",
"{",
"$",
"throttle",
"->",
"check",
"(",
")",
";",
"}",
"}",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"userProvider",
"->",
"findByCredentials",
"(",
"$",
"credentials",
")",
";",
"}",
"catch",
"(",
"UserNotFoundException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"throttlingEnabled",
"and",
"isset",
"(",
"$",
"throttle",
")",
")",
"{",
"$",
"throttle",
"->",
"addLoginAttempt",
"(",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"throttlingEnabled",
"and",
"isset",
"(",
"$",
"throttle",
")",
")",
"{",
"$",
"throttle",
"->",
"clearLoginAttempts",
"(",
")",
";",
"}",
"$",
"user",
"->",
"clearResetPassword",
"(",
")",
";",
"$",
"this",
"->",
"login",
"(",
"$",
"user",
",",
"$",
"remember",
")",
";",
"return",
"$",
"this",
"->",
"user",
";",
"}"
] | Attempts to authenticate the given user
according to the passed credentials.
@param array $credentials
@param bool $remember
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Throttling\UserBannedException
@throws \Cartalyst\Sentry\Throttling\UserSuspendedException
@throws \Cartalyst\Sentry\Users\LoginRequiredException
@throws \Cartalyst\Sentry\Users\PasswordRequiredException
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Attempts",
"to",
"authenticate",
"the",
"given",
"user",
"according",
"to",
"the",
"passed",
"credentials",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Sentry.php#L165-L226 |
cartalyst/sentry | src/Cartalyst/Sentry/Sentry.php | Sentry.check | public function check()
{
if (is_null($this->user))
{
// Check session first, follow by cookie
if ( ! $userArray = $this->session->get() and ! $userArray = $this->cookie->get())
{
return false;
}
// Now check our user is an array with two elements,
// the username followed by the persist code
if ( ! is_array($userArray) or count($userArray) !== 2)
{
return false;
}
list($id, $persistCode) = $userArray;
// Let's find our user
try
{
$user = $this->getUserProvider()->findById($id);
}
catch (UserNotFoundException $e)
{
return false;
}
// Great! Let's check the session's persist code
// against the user. If it fails, somebody has tampered
// with the cookie / session data and we're not allowing
// a login
if ( ! $user->checkPersistCode($persistCode))
{
return false;
}
// Now we'll set the user property on Sentry
$this->user = $user;
}
// Let's check our cached user is indeed activated
if ( ! $user = $this->getUser() or ! $user->isActivated())
{
return false;
}
// If throttling is enabled we check it's status
if( $this->getThrottleProvider()->isEnabled())
{
// Check the throttle status
$throttle = $this->getThrottleProvider()->findByUser( $user );
if( $throttle->isBanned() or $throttle->isSuspended())
{
$this->logout();
return false;
}
}
return true;
} | php | public function check()
{
if (is_null($this->user))
{
// Check session first, follow by cookie
if ( ! $userArray = $this->session->get() and ! $userArray = $this->cookie->get())
{
return false;
}
// Now check our user is an array with two elements,
// the username followed by the persist code
if ( ! is_array($userArray) or count($userArray) !== 2)
{
return false;
}
list($id, $persistCode) = $userArray;
// Let's find our user
try
{
$user = $this->getUserProvider()->findById($id);
}
catch (UserNotFoundException $e)
{
return false;
}
// Great! Let's check the session's persist code
// against the user. If it fails, somebody has tampered
// with the cookie / session data and we're not allowing
// a login
if ( ! $user->checkPersistCode($persistCode))
{
return false;
}
// Now we'll set the user property on Sentry
$this->user = $user;
}
// Let's check our cached user is indeed activated
if ( ! $user = $this->getUser() or ! $user->isActivated())
{
return false;
}
// If throttling is enabled we check it's status
if( $this->getThrottleProvider()->isEnabled())
{
// Check the throttle status
$throttle = $this->getThrottleProvider()->findByUser( $user );
if( $throttle->isBanned() or $throttle->isSuspended())
{
$this->logout();
return false;
}
}
return true;
} | [
"public",
"function",
"check",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"user",
")",
")",
"{",
"// Check session first, follow by cookie",
"if",
"(",
"!",
"$",
"userArray",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
")",
"and",
"!",
"$",
"userArray",
"=",
"$",
"this",
"->",
"cookie",
"->",
"get",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Now check our user is an array with two elements,",
"// the username followed by the persist code",
"if",
"(",
"!",
"is_array",
"(",
"$",
"userArray",
")",
"or",
"count",
"(",
"$",
"userArray",
")",
"!==",
"2",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"id",
",",
"$",
"persistCode",
")",
"=",
"$",
"userArray",
";",
"// Let's find our user",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserProvider",
"(",
")",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"UserNotFoundException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"// Great! Let's check the session's persist code",
"// against the user. If it fails, somebody has tampered",
"// with the cookie / session data and we're not allowing",
"// a login",
"if",
"(",
"!",
"$",
"user",
"->",
"checkPersistCode",
"(",
"$",
"persistCode",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Now we'll set the user property on Sentry",
"$",
"this",
"->",
"user",
"=",
"$",
"user",
";",
"}",
"// Let's check our cached user is indeed activated",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"or",
"!",
"$",
"user",
"->",
"isActivated",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// If throttling is enabled we check it's status",
"if",
"(",
"$",
"this",
"->",
"getThrottleProvider",
"(",
")",
"->",
"isEnabled",
"(",
")",
")",
"{",
"// Check the throttle status",
"$",
"throttle",
"=",
"$",
"this",
"->",
"getThrottleProvider",
"(",
")",
"->",
"findByUser",
"(",
"$",
"user",
")",
";",
"if",
"(",
"$",
"throttle",
"->",
"isBanned",
"(",
")",
"or",
"$",
"throttle",
"->",
"isSuspended",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logout",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check to see if the user is logged in and activated, and hasn't been banned or suspended.
@return bool | [
"Check",
"to",
"see",
"if",
"the",
"user",
"is",
"logged",
"in",
"and",
"activated",
"and",
"hasn",
"t",
"been",
"banned",
"or",
"suspended",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Sentry.php#L244-L305 |
cartalyst/sentry | src/Cartalyst/Sentry/Sentry.php | Sentry.login | public function login(UserInterface $user, $remember = false)
{
if ( ! $user->isActivated())
{
$login = $user->getLogin();
throw new UserNotActivatedException("Cannot login user [$login] as they are not activated.");
}
$this->user = $user;
// Create an array of data to persist to the session and / or cookie
$toPersist = array($user->getId(), $user->getPersistCode());
// Set sessions
$this->session->put($toPersist);
if ($remember)
{
$this->cookie->forever($toPersist);
}
// The user model can attach any handlers
// to the "recordLogin" event.
$user->recordLogin();
} | php | public function login(UserInterface $user, $remember = false)
{
if ( ! $user->isActivated())
{
$login = $user->getLogin();
throw new UserNotActivatedException("Cannot login user [$login] as they are not activated.");
}
$this->user = $user;
// Create an array of data to persist to the session and / or cookie
$toPersist = array($user->getId(), $user->getPersistCode());
// Set sessions
$this->session->put($toPersist);
if ($remember)
{
$this->cookie->forever($toPersist);
}
// The user model can attach any handlers
// to the "recordLogin" event.
$user->recordLogin();
} | [
"public",
"function",
"login",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"remember",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"user",
"->",
"isActivated",
"(",
")",
")",
"{",
"$",
"login",
"=",
"$",
"user",
"->",
"getLogin",
"(",
")",
";",
"throw",
"new",
"UserNotActivatedException",
"(",
"\"Cannot login user [$login] as they are not activated.\"",
")",
";",
"}",
"$",
"this",
"->",
"user",
"=",
"$",
"user",
";",
"// Create an array of data to persist to the session and / or cookie",
"$",
"toPersist",
"=",
"array",
"(",
"$",
"user",
"->",
"getId",
"(",
")",
",",
"$",
"user",
"->",
"getPersistCode",
"(",
")",
")",
";",
"// Set sessions",
"$",
"this",
"->",
"session",
"->",
"put",
"(",
"$",
"toPersist",
")",
";",
"if",
"(",
"$",
"remember",
")",
"{",
"$",
"this",
"->",
"cookie",
"->",
"forever",
"(",
"$",
"toPersist",
")",
";",
"}",
"// The user model can attach any handlers",
"// to the \"recordLogin\" event.",
"$",
"user",
"->",
"recordLogin",
"(",
")",
";",
"}"
] | Logs in the given user and sets properties
in the session.
@param \Cartalyst\Sentry\Users\UserInterface $user
@param bool $remember
@return void
@throws \Cartalyst\Sentry\Users\UserNotActivatedException | [
"Logs",
"in",
"the",
"given",
"user",
"and",
"sets",
"properties",
"in",
"the",
"session",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Sentry.php#L316-L340 |
cartalyst/sentry | src/Cartalyst/Sentry/Sentry.php | Sentry.logout | public function logout()
{
$this->user = null;
$this->session->forget();
$this->cookie->forget();
} | php | public function logout()
{
$this->user = null;
$this->session->forget();
$this->cookie->forget();
} | [
"public",
"function",
"logout",
"(",
")",
"{",
"$",
"this",
"->",
"user",
"=",
"null",
";",
"$",
"this",
"->",
"session",
"->",
"forget",
"(",
")",
";",
"$",
"this",
"->",
"cookie",
"->",
"forget",
"(",
")",
";",
"}"
] | Logs the current user out.
@return void | [
"Logs",
"the",
"current",
"user",
"out",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Sentry.php#L357-L363 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.addLoginAttempt | public function addLoginAttempt()
{
$this->attempts++;
$this->last_attempt_at = new DateTime;
if ($this->getLoginAttempts() >= static::$attemptLimit)
{
$this->suspend();
}
else
{
$this->save();
}
} | php | public function addLoginAttempt()
{
$this->attempts++;
$this->last_attempt_at = new DateTime;
if ($this->getLoginAttempts() >= static::$attemptLimit)
{
$this->suspend();
}
else
{
$this->save();
}
} | [
"public",
"function",
"addLoginAttempt",
"(",
")",
"{",
"$",
"this",
"->",
"attempts",
"++",
";",
"$",
"this",
"->",
"last_attempt_at",
"=",
"new",
"DateTime",
";",
"if",
"(",
"$",
"this",
"->",
"getLoginAttempts",
"(",
")",
">=",
"static",
"::",
"$",
"attemptLimit",
")",
"{",
"$",
"this",
"->",
"suspend",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Add a new login attempt.
@return void | [
"Add",
"a",
"new",
"login",
"attempt",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L115-L128 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.clearLoginAttempts | public function clearLoginAttempts()
{
// If our login attempts is already at zero
// we do not need to do anything. Additionally,
// if we are suspended, we are not going to do
// anything either as clearing login attempts
// makes us unsuspended. We need to manually
// call unsuspend() in order to unsuspend.
if ($this->getLoginAttempts() == 0 or $this->suspended)
{
return;
}
$this->attempts = 0;
$this->last_attempt_at = null;
$this->suspended = false;
$this->suspended_at = null;
$this->save();
} | php | public function clearLoginAttempts()
{
// If our login attempts is already at zero
// we do not need to do anything. Additionally,
// if we are suspended, we are not going to do
// anything either as clearing login attempts
// makes us unsuspended. We need to manually
// call unsuspend() in order to unsuspend.
if ($this->getLoginAttempts() == 0 or $this->suspended)
{
return;
}
$this->attempts = 0;
$this->last_attempt_at = null;
$this->suspended = false;
$this->suspended_at = null;
$this->save();
} | [
"public",
"function",
"clearLoginAttempts",
"(",
")",
"{",
"// If our login attempts is already at zero",
"// we do not need to do anything. Additionally,",
"// if we are suspended, we are not going to do",
"// anything either as clearing login attempts",
"// makes us unsuspended. We need to manually",
"// call unsuspend() in order to unsuspend.",
"if",
"(",
"$",
"this",
"->",
"getLoginAttempts",
"(",
")",
"==",
"0",
"or",
"$",
"this",
"->",
"suspended",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"attempts",
"=",
"0",
";",
"$",
"this",
"->",
"last_attempt_at",
"=",
"null",
";",
"$",
"this",
"->",
"suspended",
"=",
"false",
";",
"$",
"this",
"->",
"suspended_at",
"=",
"null",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Clear all login attempts
@return void | [
"Clear",
"all",
"login",
"attempts"
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L135-L153 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.suspend | public function suspend()
{
if ( ! $this->suspended)
{
$this->suspended = true;
$this->suspended_at = new DateTime;
$this->save();
}
} | php | public function suspend()
{
if ( ! $this->suspended)
{
$this->suspended = true;
$this->suspended_at = new DateTime;
$this->save();
}
} | [
"public",
"function",
"suspend",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"suspended",
")",
"{",
"$",
"this",
"->",
"suspended",
"=",
"true",
";",
"$",
"this",
"->",
"suspended_at",
"=",
"new",
"DateTime",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Suspend the user associated with the throttle
@return void | [
"Suspend",
"the",
"user",
"associated",
"with",
"the",
"throttle"
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L160-L168 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.unsuspend | public function unsuspend()
{
if ($this->suspended)
{
$this->attempts = 0;
$this->last_attempt_at = null;
$this->suspended = false;
$this->suspended_at = null;
$this->save();
}
} | php | public function unsuspend()
{
if ($this->suspended)
{
$this->attempts = 0;
$this->last_attempt_at = null;
$this->suspended = false;
$this->suspended_at = null;
$this->save();
}
} | [
"public",
"function",
"unsuspend",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"suspended",
")",
"{",
"$",
"this",
"->",
"attempts",
"=",
"0",
";",
"$",
"this",
"->",
"last_attempt_at",
"=",
"null",
";",
"$",
"this",
"->",
"suspended",
"=",
"false",
";",
"$",
"this",
"->",
"suspended_at",
"=",
"null",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Unsuspend the user.
@return void | [
"Unsuspend",
"the",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L175-L185 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.isSuspended | public function isSuspended()
{
if ($this->suspended and $this->suspended_at)
{
$this->removeSuspensionIfAllowed();
return (bool) $this->suspended;
}
return false;
} | php | public function isSuspended()
{
if ($this->suspended and $this->suspended_at)
{
$this->removeSuspensionIfAllowed();
return (bool) $this->suspended;
}
return false;
} | [
"public",
"function",
"isSuspended",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"suspended",
"and",
"$",
"this",
"->",
"suspended_at",
")",
"{",
"$",
"this",
"->",
"removeSuspensionIfAllowed",
"(",
")",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"suspended",
";",
"}",
"return",
"false",
";",
"}"
] | Check if the user is suspended.
@return bool | [
"Check",
"if",
"the",
"user",
"is",
"suspended",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L192-L201 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.ban | public function ban()
{
if ( ! $this->banned)
{
$this->banned = true;
$this->banned_at = new DateTime;
$this->save();
}
} | php | public function ban()
{
if ( ! $this->banned)
{
$this->banned = true;
$this->banned_at = new DateTime;
$this->save();
}
} | [
"public",
"function",
"ban",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"banned",
")",
"{",
"$",
"this",
"->",
"banned",
"=",
"true",
";",
"$",
"this",
"->",
"banned_at",
"=",
"new",
"DateTime",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Ban the user.
@return void | [
"Ban",
"the",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L208-L216 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.unban | public function unban()
{
if ($this->banned)
{
$this->banned = false;
$this->banned_at = null;
$this->save();
}
} | php | public function unban()
{
if ($this->banned)
{
$this->banned = false;
$this->banned_at = null;
$this->save();
}
} | [
"public",
"function",
"unban",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"banned",
")",
"{",
"$",
"this",
"->",
"banned",
"=",
"false",
";",
"$",
"this",
"->",
"banned_at",
"=",
"null",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Unban the user.
@return void | [
"Unban",
"the",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L223-L231 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.check | public function check(\Validation $extra_validation = NULL)
{
if ($this->isBanned())
{
throw new UserBannedException(sprintf(
'User [%s] has been banned.',
$this->getUser()->getLogin()
));
}
else if ($this->isSuspended())
{
throw new UserSuspendedException(sprintf(
'User [%s] has been suspended.',
$this->getUser()->getLogin()
));
}
return parent::check($extra_validation);
} | php | public function check(\Validation $extra_validation = NULL)
{
if ($this->isBanned())
{
throw new UserBannedException(sprintf(
'User [%s] has been banned.',
$this->getUser()->getLogin()
));
}
else if ($this->isSuspended())
{
throw new UserSuspendedException(sprintf(
'User [%s] has been suspended.',
$this->getUser()->getLogin()
));
}
return parent::check($extra_validation);
} | [
"public",
"function",
"check",
"(",
"\\",
"Validation",
"$",
"extra_validation",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBanned",
"(",
")",
")",
"{",
"throw",
"new",
"UserBannedException",
"(",
"sprintf",
"(",
"'User [%s] has been banned.'",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLogin",
"(",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"isSuspended",
"(",
")",
")",
"{",
"throw",
"new",
"UserSuspendedException",
"(",
"sprintf",
"(",
"'User [%s] has been suspended.'",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLogin",
"(",
")",
")",
")",
";",
"}",
"return",
"parent",
"::",
"check",
"(",
"$",
"extra_validation",
")",
";",
"}"
] | Check user throttle status.
@param \Validation $extra_validation
@return bool
@throws \Cartalyst\Sentry\Throttling\UserBannedException
@throws \Cartalyst\Sentry\Throttling\UserSuspendedException | [
"Check",
"user",
"throttle",
"status",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L251-L269 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.clearLoginAttemptsIfAllowed | public function clearLoginAttemptsIfAllowed()
{
$lastAttempt = new DateTime($this->last_attempt_at);
$suspensionTime = static::$suspensionTime;
$clearAttemptsAt = $lastAttempt->modify("+{$suspensionTime} minutes");
$now = new DateTime;
if ($clearAttemptsAt <= $now)
{
$this->attempts = 0;
$this->save();
}
unset($lastAttempt);
unset($clearAttemptsAt);
unset($now);
} | php | public function clearLoginAttemptsIfAllowed()
{
$lastAttempt = new DateTime($this->last_attempt_at);
$suspensionTime = static::$suspensionTime;
$clearAttemptsAt = $lastAttempt->modify("+{$suspensionTime} minutes");
$now = new DateTime;
if ($clearAttemptsAt <= $now)
{
$this->attempts = 0;
$this->save();
}
unset($lastAttempt);
unset($clearAttemptsAt);
unset($now);
} | [
"public",
"function",
"clearLoginAttemptsIfAllowed",
"(",
")",
"{",
"$",
"lastAttempt",
"=",
"new",
"DateTime",
"(",
"$",
"this",
"->",
"last_attempt_at",
")",
";",
"$",
"suspensionTime",
"=",
"static",
"::",
"$",
"suspensionTime",
";",
"$",
"clearAttemptsAt",
"=",
"$",
"lastAttempt",
"->",
"modify",
"(",
"\"+{$suspensionTime} minutes\"",
")",
";",
"$",
"now",
"=",
"new",
"DateTime",
";",
"if",
"(",
"$",
"clearAttemptsAt",
"<=",
"$",
"now",
")",
"{",
"$",
"this",
"->",
"attempts",
"=",
"0",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"lastAttempt",
")",
";",
"unset",
"(",
"$",
"clearAttemptsAt",
")",
";",
"unset",
"(",
"$",
"now",
")",
";",
"}"
] | Inspects the last attempt vs the suspension time
(the time in which attempts must space before the
account is suspended). If we can clear our attempts
now, we'll do so and save.
@return void | [
"Inspects",
"the",
"last",
"attempt",
"vs",
"the",
"suspension",
"time",
"(",
"the",
"time",
"in",
"which",
"attempts",
"must",
"space",
"before",
"the",
"account",
"is",
"suspended",
")",
".",
"If",
"we",
"can",
"clear",
"our",
"attempts",
"now",
"we",
"ll",
"do",
"so",
"and",
"save",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L279-L296 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.removeSuspensionIfAllowed | public function removeSuspensionIfAllowed()
{
$suspended = new DateTime($this->suspended_at);
$suspensionTime = static::$suspensionTime;
$unsuspendAt = $suspended->modify("+{$suspensionTime} minutes");
$now = new DateTime;
if ($unsuspendAt <= $now)
{
$this->unsuspend();
}
unset($suspended);
unset($unsuspendAt);
unset($now);
} | php | public function removeSuspensionIfAllowed()
{
$suspended = new DateTime($this->suspended_at);
$suspensionTime = static::$suspensionTime;
$unsuspendAt = $suspended->modify("+{$suspensionTime} minutes");
$now = new DateTime;
if ($unsuspendAt <= $now)
{
$this->unsuspend();
}
unset($suspended);
unset($unsuspendAt);
unset($now);
} | [
"public",
"function",
"removeSuspensionIfAllowed",
"(",
")",
"{",
"$",
"suspended",
"=",
"new",
"DateTime",
"(",
"$",
"this",
"->",
"suspended_at",
")",
";",
"$",
"suspensionTime",
"=",
"static",
"::",
"$",
"suspensionTime",
";",
"$",
"unsuspendAt",
"=",
"$",
"suspended",
"->",
"modify",
"(",
"\"+{$suspensionTime} minutes\"",
")",
";",
"$",
"now",
"=",
"new",
"DateTime",
";",
"if",
"(",
"$",
"unsuspendAt",
"<=",
"$",
"now",
")",
"{",
"$",
"this",
"->",
"unsuspend",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"suspended",
")",
";",
"unset",
"(",
"$",
"unsuspendAt",
")",
";",
"unset",
"(",
"$",
"now",
")",
";",
"}"
] | Inspects to see if the user can become unsuspended
or not, based on the suspension time provided. If so,
unsuspends.
@return void | [
"Inspects",
"to",
"see",
"if",
"the",
"user",
"can",
"become",
"unsuspended",
"or",
"not",
"based",
"on",
"the",
"suspension",
"time",
"provided",
".",
"If",
"so",
"unsuspends",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L305-L321 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php | Throttle.getRemainingSuspensionTime | public function getRemainingSuspensionTime()
{
if(!$this->isSuspended())
return 0;
$lastAttempt = clone $this->last_attempt_at;
$suspensionTime = static::$suspensionTime;
$clearAttemptsAt = $lastAttempt->modify("+{$suspensionTime} minutes");
$now = new Datetime;
$timeLeft = $clearAttemptsAt->diff($now);
$minutesLeft = ($timeLeft->s != 0 ?
($timeLeft->days * 24 * 60) + ($timeLeft->h * 60) + ($timeLeft->i) + 1 :
($timeLeft->days * 24 * 60) + ($timeLeft->h * 60) + ($timeLeft->i));
return $minutesLeft;
} | php | public function getRemainingSuspensionTime()
{
if(!$this->isSuspended())
return 0;
$lastAttempt = clone $this->last_attempt_at;
$suspensionTime = static::$suspensionTime;
$clearAttemptsAt = $lastAttempt->modify("+{$suspensionTime} minutes");
$now = new Datetime;
$timeLeft = $clearAttemptsAt->diff($now);
$minutesLeft = ($timeLeft->s != 0 ?
($timeLeft->days * 24 * 60) + ($timeLeft->h * 60) + ($timeLeft->i) + 1 :
($timeLeft->days * 24 * 60) + ($timeLeft->h * 60) + ($timeLeft->i));
return $minutesLeft;
} | [
"public",
"function",
"getRemainingSuspensionTime",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isSuspended",
"(",
")",
")",
"return",
"0",
";",
"$",
"lastAttempt",
"=",
"clone",
"$",
"this",
"->",
"last_attempt_at",
";",
"$",
"suspensionTime",
"=",
"static",
"::",
"$",
"suspensionTime",
";",
"$",
"clearAttemptsAt",
"=",
"$",
"lastAttempt",
"->",
"modify",
"(",
"\"+{$suspensionTime} minutes\"",
")",
";",
"$",
"now",
"=",
"new",
"Datetime",
";",
"$",
"timeLeft",
"=",
"$",
"clearAttemptsAt",
"->",
"diff",
"(",
"$",
"now",
")",
";",
"$",
"minutesLeft",
"=",
"(",
"$",
"timeLeft",
"->",
"s",
"!=",
"0",
"?",
"(",
"$",
"timeLeft",
"->",
"days",
"*",
"24",
"*",
"60",
")",
"+",
"(",
"$",
"timeLeft",
"->",
"h",
"*",
"60",
")",
"+",
"(",
"$",
"timeLeft",
"->",
"i",
")",
"+",
"1",
":",
"(",
"$",
"timeLeft",
"->",
"days",
"*",
"24",
"*",
"60",
")",
"+",
"(",
"$",
"timeLeft",
"->",
"h",
"*",
"60",
")",
"+",
"(",
"$",
"timeLeft",
"->",
"i",
")",
")",
";",
"return",
"$",
"minutesLeft",
";",
"}"
] | Get the remaining time on a suspension in minutes rounded up. Returns
0 if user is not suspended.
@return int | [
"Get",
"the",
"remaining",
"time",
"on",
"a",
"suspension",
"in",
"minutes",
"rounded",
"up",
".",
"Returns",
"0",
"if",
"user",
"is",
"not",
"suspended",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Throttle.php#L403-L421 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findById | public function findById($id)
{
$model = $this->createModel();
$user = $model->where('id', '=', $id)->find();
if ( ! $user->loaded() )
{
throw new UserNotFoundException("A user could not be found with ID [$id].");
}
return $user;
} | php | public function findById($id)
{
$model = $this->createModel();
$user = $model->where('id', '=', $id)->find();
if ( ! $user->loaded() )
{
throw new UserNotFoundException("A user could not be found with ID [$id].");
}
return $user;
} | [
"public",
"function",
"findById",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"user",
"=",
"$",
"model",
"->",
"where",
"(",
"'id'",
",",
"'='",
",",
"$",
"id",
")",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"->",
"loaded",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user could not be found with ID [$id].\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the given user ID.
@param mixed $id
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"user",
"ID",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L71-L83 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findByLogin | public function findByLogin($login)
{
$model = $this->createModel();
$user = $model->where($model->getLoginName(), '=', $login)->find();
if ( ! $user->loaded() )
{
throw new UserNotFoundException("A user could not be found with a login value of [$login].");
}
return $user;
} | php | public function findByLogin($login)
{
$model = $this->createModel();
$user = $model->where($model->getLoginName(), '=', $login)->find();
if ( ! $user->loaded() )
{
throw new UserNotFoundException("A user could not be found with a login value of [$login].");
}
return $user;
} | [
"public",
"function",
"findByLogin",
"(",
"$",
"login",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"user",
"=",
"$",
"model",
"->",
"where",
"(",
"$",
"model",
"->",
"getLoginName",
"(",
")",
",",
"'='",
",",
"$",
"login",
")",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"->",
"loaded",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user could not be found with a login value of [$login].\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the login value.
@param string $login
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Finds",
"a",
"user",
"by",
"the",
"login",
"value",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L92-L104 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findByCredentials | public function findByCredentials(array $credentials)
{
$model = $this->createModel();
$loginName = $model->getLoginName();
if ( ! array_key_exists($loginName, $credentials))
{
throw new \InvalidArgumentException("Login attribute [$loginName] was not provided.");
}
$passwordName = $model->getPasswordName();
$query = $model;
$hashableAttributes = $model->getHashableAttributes();
$hashedCredentials = array();
// build query from given credentials
foreach ($credentials as $credential => $value)
{
// Remove hashed attributes to check later as we need to check these
// values after we retrieved them because of salts
if (in_array($credential, $hashableAttributes))
{
$hashedCredentials = array_merge($hashedCredentials, array($credential => $value));
}
else
{
$query = $query->where($credential, '=', $value);
}
}
$user = $query->find();
if ( ! $user->loaded() )
{
throw new UserNotFoundException("A user was not found with the given credentials.");
}
// Now check the hashed credentials match ours
foreach ($hashedCredentials as $credential => $value)
{
if ( ! $this->hasher->checkhash($value, $user->{$credential}))
{
$message = "A user was found to match all plain text credentials however hashed credential [$credential] did not match.";
if ($credential == $passwordName)
{
throw new WrongPasswordException($message);
}
throw new UserNotFoundException($message);
}
}
return $user;
} | php | public function findByCredentials(array $credentials)
{
$model = $this->createModel();
$loginName = $model->getLoginName();
if ( ! array_key_exists($loginName, $credentials))
{
throw new \InvalidArgumentException("Login attribute [$loginName] was not provided.");
}
$passwordName = $model->getPasswordName();
$query = $model;
$hashableAttributes = $model->getHashableAttributes();
$hashedCredentials = array();
// build query from given credentials
foreach ($credentials as $credential => $value)
{
// Remove hashed attributes to check later as we need to check these
// values after we retrieved them because of salts
if (in_array($credential, $hashableAttributes))
{
$hashedCredentials = array_merge($hashedCredentials, array($credential => $value));
}
else
{
$query = $query->where($credential, '=', $value);
}
}
$user = $query->find();
if ( ! $user->loaded() )
{
throw new UserNotFoundException("A user was not found with the given credentials.");
}
// Now check the hashed credentials match ours
foreach ($hashedCredentials as $credential => $value)
{
if ( ! $this->hasher->checkhash($value, $user->{$credential}))
{
$message = "A user was found to match all plain text credentials however hashed credential [$credential] did not match.";
if ($credential == $passwordName)
{
throw new WrongPasswordException($message);
}
throw new UserNotFoundException($message);
}
}
return $user;
} | [
"public",
"function",
"findByCredentials",
"(",
"array",
"$",
"credentials",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"loginName",
"=",
"$",
"model",
"->",
"getLoginName",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"loginName",
",",
"$",
"credentials",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Login attribute [$loginName] was not provided.\"",
")",
";",
"}",
"$",
"passwordName",
"=",
"$",
"model",
"->",
"getPasswordName",
"(",
")",
";",
"$",
"query",
"=",
"$",
"model",
";",
"$",
"hashableAttributes",
"=",
"$",
"model",
"->",
"getHashableAttributes",
"(",
")",
";",
"$",
"hashedCredentials",
"=",
"array",
"(",
")",
";",
"// build query from given credentials",
"foreach",
"(",
"$",
"credentials",
"as",
"$",
"credential",
"=>",
"$",
"value",
")",
"{",
"// Remove hashed attributes to check later as we need to check these",
"// values after we retrieved them because of salts",
"if",
"(",
"in_array",
"(",
"$",
"credential",
",",
"$",
"hashableAttributes",
")",
")",
"{",
"$",
"hashedCredentials",
"=",
"array_merge",
"(",
"$",
"hashedCredentials",
",",
"array",
"(",
"$",
"credential",
"=>",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"where",
"(",
"$",
"credential",
",",
"'='",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"user",
"=",
"$",
"query",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"->",
"loaded",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user was not found with the given credentials.\"",
")",
";",
"}",
"// Now check the hashed credentials match ours",
"foreach",
"(",
"$",
"hashedCredentials",
"as",
"$",
"credential",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasher",
"->",
"checkhash",
"(",
"$",
"value",
",",
"$",
"user",
"->",
"{",
"$",
"credential",
"}",
")",
")",
"{",
"$",
"message",
"=",
"\"A user was found to match all plain text credentials however hashed credential [$credential] did not match.\"",
";",
"if",
"(",
"$",
"credential",
"==",
"$",
"passwordName",
")",
"{",
"throw",
"new",
"WrongPasswordException",
"(",
"$",
"message",
")",
";",
"}",
"throw",
"new",
"UserNotFoundException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the given credentials.
@param array $credentials
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"credentials",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L113-L167 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findByActivationCode | public function findByActivationCode($code)
{
if ( ! $code)
{
throw new \InvalidArgumentException("No activation code passed.");
}
$model = $this->createModel();
$result = $model->where('activation_code', '=', $code)->get();
if (($count = $result->count()) > 1)
{
throw new \RuntimeException("Found [$count] users with the same activation code.");
}
$user = $result->find();
if ( !$user->loaded() )
{
throw new UserNotFoundException("A user was not found with the given activation code.");
}
return $user;
} | php | public function findByActivationCode($code)
{
if ( ! $code)
{
throw new \InvalidArgumentException("No activation code passed.");
}
$model = $this->createModel();
$result = $model->where('activation_code', '=', $code)->get();
if (($count = $result->count()) > 1)
{
throw new \RuntimeException("Found [$count] users with the same activation code.");
}
$user = $result->find();
if ( !$user->loaded() )
{
throw new UserNotFoundException("A user was not found with the given activation code.");
}
return $user;
} | [
"public",
"function",
"findByActivationCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"$",
"code",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No activation code passed.\"",
")",
";",
"}",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"result",
"=",
"$",
"model",
"->",
"where",
"(",
"'activation_code'",
",",
"'='",
",",
"$",
"code",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"(",
"$",
"count",
"=",
"$",
"result",
"->",
"count",
"(",
")",
")",
">",
"1",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Found [$count] users with the same activation code.\"",
")",
";",
"}",
"$",
"user",
"=",
"$",
"result",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"->",
"loaded",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user was not found with the given activation code.\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the given activation code.
@param string $code
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException
@throws InvalidArgumentException
@throws RuntimeException | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"activation",
"code",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L178-L202 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findAllInGroup | public function findAllInGroup(GroupInterface $group)
{
return array_filter($this->findAll(), function($user) use ($group)
{
return $user->inGroup($group);
});
} | php | public function findAllInGroup(GroupInterface $group)
{
return array_filter($this->findAll(), function($user) use ($group)
{
return $user->inGroup($group);
});
} | [
"public",
"function",
"findAllInGroup",
"(",
"GroupInterface",
"$",
"group",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"findAll",
"(",
")",
",",
"function",
"(",
"$",
"user",
")",
"use",
"(",
"$",
"group",
")",
"{",
"return",
"$",
"user",
"->",
"inGroup",
"(",
"$",
"group",
")",
";",
"}",
")",
";",
"}"
] | Returns all users who belong to
a group.
@param \Cartalyst\Sentry\Groups\GroupInterface $group
@return array | [
"Returns",
"all",
"users",
"who",
"belong",
"to",
"a",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L250-L256 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findAllWithAccess | public function findAllWithAccess($permissions)
{
return array_filter($this->findAll(), function($user) use ($permissions)
{
return $user->hasAccess($permissions);
});
} | php | public function findAllWithAccess($permissions)
{
return array_filter($this->findAll(), function($user) use ($permissions)
{
return $user->hasAccess($permissions);
});
} | [
"public",
"function",
"findAllWithAccess",
"(",
"$",
"permissions",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"findAll",
"(",
")",
",",
"function",
"(",
"$",
"user",
")",
"use",
"(",
"$",
"permissions",
")",
"{",
"return",
"$",
"user",
"->",
"hasAccess",
"(",
"$",
"permissions",
")",
";",
"}",
")",
";",
"}"
] | Returns all users with access to
a permission(s).
@param string|array $permissions
@return array | [
"Returns",
"all",
"users",
"with",
"access",
"to",
"a",
"permission",
"(",
"s",
")",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L265-L271 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.findAllWithAnyAccess | public function findAllWithAnyAccess(array $permissions)
{
return array_filter($this->findAll(), function($user) use ($permissions)
{
return $user->hasAnyAccess($permissions);
});
} | php | public function findAllWithAnyAccess(array $permissions)
{
return array_filter($this->findAll(), function($user) use ($permissions)
{
return $user->hasAnyAccess($permissions);
});
} | [
"public",
"function",
"findAllWithAnyAccess",
"(",
"array",
"$",
"permissions",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"findAll",
"(",
")",
",",
"function",
"(",
"$",
"user",
")",
"use",
"(",
"$",
"permissions",
")",
"{",
"return",
"$",
"user",
"->",
"hasAnyAccess",
"(",
"$",
"permissions",
")",
";",
"}",
")",
";",
"}"
] | Returns all users with access to
any given permission(s).
@param array $permissions
@return array | [
"Returns",
"all",
"users",
"with",
"access",
"to",
"any",
"given",
"permission",
"(",
"s",
")",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L280-L286 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/Provider.php | Provider.create | public function create(array $credentials)
{
if ( ! isset($credentials['permissions']) )
{
$credentials['permissions'] = array();
}
$user = $this->createModel();
$user->values($credentials);
$user->save();
return $user;
} | php | public function create(array $credentials)
{
if ( ! isset($credentials['permissions']) )
{
$credentials['permissions'] = array();
}
$user = $this->createModel();
$user->values($credentials);
$user->save();
return $user;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"credentials",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"credentials",
"[",
"'permissions'",
"]",
")",
")",
"{",
"$",
"credentials",
"[",
"'permissions'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"user",
"->",
"values",
"(",
"$",
"credentials",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Creates a user.
@param array $credentials
@return \Cartalyst\Sentry\Users\UserInterface | [
"Creates",
"a",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/Provider.php#L294-L306 |
cartalyst/sentry | src/Cartalyst/Sentry/Facades/FuelPHP/Sentry.php | Sentry.createSentry | public static function createSentry()
{
// If Eloquent doesn't exist, then we must assume they are using their own providers.
if (class_exists('Illuminate\Database\Eloquent\Model'))
{
// Retrieve what we need for our resolver
$database = Database_Connection::instance();
$pdo = $database->connection();
$driverName = $database->driver_name();
$tablePrefix = $database->table_prefix();
// Make sure we're getting a PDO connection
if ( ! $pdo instanceof PDO)
{
throw new \RuntimeException("Sentry will only work with PDO database connections.");
}
Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
}
return new BaseSentry(
$userProvider = new UserProvider(new NativeHasher),
new GroupProvider,
new ThrottleProvider($userProvider),
new FuelPHPSession(Session::instance()),
new FuelPHPCookie,
Input::real_ip()
);
} | php | public static function createSentry()
{
// If Eloquent doesn't exist, then we must assume they are using their own providers.
if (class_exists('Illuminate\Database\Eloquent\Model'))
{
// Retrieve what we need for our resolver
$database = Database_Connection::instance();
$pdo = $database->connection();
$driverName = $database->driver_name();
$tablePrefix = $database->table_prefix();
// Make sure we're getting a PDO connection
if ( ! $pdo instanceof PDO)
{
throw new \RuntimeException("Sentry will only work with PDO database connections.");
}
Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
}
return new BaseSentry(
$userProvider = new UserProvider(new NativeHasher),
new GroupProvider,
new ThrottleProvider($userProvider),
new FuelPHPSession(Session::instance()),
new FuelPHPCookie,
Input::real_ip()
);
} | [
"public",
"static",
"function",
"createSentry",
"(",
")",
"{",
"// If Eloquent doesn't exist, then we must assume they are using their own providers.",
"if",
"(",
"class_exists",
"(",
"'Illuminate\\Database\\Eloquent\\Model'",
")",
")",
"{",
"// Retrieve what we need for our resolver",
"$",
"database",
"=",
"Database_Connection",
"::",
"instance",
"(",
")",
";",
"$",
"pdo",
"=",
"$",
"database",
"->",
"connection",
"(",
")",
";",
"$",
"driverName",
"=",
"$",
"database",
"->",
"driver_name",
"(",
")",
";",
"$",
"tablePrefix",
"=",
"$",
"database",
"->",
"table_prefix",
"(",
")",
";",
"// Make sure we're getting a PDO connection",
"if",
"(",
"!",
"$",
"pdo",
"instanceof",
"PDO",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Sentry will only work with PDO database connections.\"",
")",
";",
"}",
"Eloquent",
"::",
"setConnectionResolver",
"(",
"new",
"ConnectionResolver",
"(",
"$",
"pdo",
",",
"$",
"driverName",
",",
"$",
"tablePrefix",
")",
")",
";",
"}",
"return",
"new",
"BaseSentry",
"(",
"$",
"userProvider",
"=",
"new",
"UserProvider",
"(",
"new",
"NativeHasher",
")",
",",
"new",
"GroupProvider",
",",
"new",
"ThrottleProvider",
"(",
"$",
"userProvider",
")",
",",
"new",
"FuelPHPSession",
"(",
"Session",
"::",
"instance",
"(",
")",
")",
",",
"new",
"FuelPHPCookie",
",",
"Input",
"::",
"real_ip",
"(",
")",
")",
";",
"}"
] | Creates a new instance of Sentry.
@return \Cartalyst\Sentry\Sentry
@throws \RuntimeException | [
"Creates",
"a",
"new",
"instance",
"of",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/FuelPHP/Sentry.php#L44-L72 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Kohana/Provider.php | Provider.findByUser | public function findByUser(UserInterface $user, $ipAddress = null)
{
$model = $this->createModel();
$query = $model->where('user_id', '=', ($user_id = $user->id));
if ($ipAddress)
{
$query->where('ip_address', '=', $ipAddress);
}
$throttle = $query->find();
if ( ! $throttle->loaded() )
{
$throttle = $this->createModel();
$throttle->user_id = $user_id;
if ($ipAddress) $throttle->ip_address = $ipAddress;
$throttle->save();
}
return $throttle;
} | php | public function findByUser(UserInterface $user, $ipAddress = null)
{
$model = $this->createModel();
$query = $model->where('user_id', '=', ($user_id = $user->id));
if ($ipAddress)
{
$query->where('ip_address', '=', $ipAddress);
}
$throttle = $query->find();
if ( ! $throttle->loaded() )
{
$throttle = $this->createModel();
$throttle->user_id = $user_id;
if ($ipAddress) $throttle->ip_address = $ipAddress;
$throttle->save();
}
return $throttle;
} | [
"public",
"function",
"findByUser",
"(",
"UserInterface",
"$",
"user",
",",
"$",
"ipAddress",
"=",
"null",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"query",
"=",
"$",
"model",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"(",
"$",
"user_id",
"=",
"$",
"user",
"->",
"id",
")",
")",
";",
"if",
"(",
"$",
"ipAddress",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'ip_address'",
",",
"'='",
",",
"$",
"ipAddress",
")",
";",
"}",
"$",
"throttle",
"=",
"$",
"query",
"->",
"find",
"(",
")",
";",
"if",
"(",
"!",
"$",
"throttle",
"->",
"loaded",
"(",
")",
")",
"{",
"$",
"throttle",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"throttle",
"->",
"user_id",
"=",
"$",
"user_id",
";",
"if",
"(",
"$",
"ipAddress",
")",
"$",
"throttle",
"->",
"ip_address",
"=",
"$",
"ipAddress",
";",
"$",
"throttle",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"throttle",
";",
"}"
] | Finds a throttler by the given user ID.
@param mixed $id
@param string $ipAddress
@return \Cartalyst\Sentry\Throttling\ThrottleInterface | [
"Finds",
"a",
"throttler",
"by",
"the",
"given",
"user",
"ID",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Kohana/Provider.php#L74-L95 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Eloquent/Provider.php | Provider.findById | public function findById($id)
{
$model = $this->createModel();
if ( ! $group = $model->newQuery()->find($id))
{
throw new GroupNotFoundException("A group could not be found with ID [$id].");
}
return $group;
} | php | public function findById($id)
{
$model = $this->createModel();
if ( ! $group = $model->newQuery()->find($id))
{
throw new GroupNotFoundException("A group could not be found with ID [$id].");
}
return $group;
} | [
"public",
"function",
"findById",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"if",
"(",
"!",
"$",
"group",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"GroupNotFoundException",
"(",
"\"A group could not be found with ID [$id].\"",
")",
";",
"}",
"return",
"$",
"group",
";",
"}"
] | Find the group by ID.
@param int $id
@return \Cartalyst\Sentry\Groups\GroupInterface $group
@throws \Cartalyst\Sentry\Groups\GroupNotFoundException | [
"Find",
"the",
"group",
"by",
"ID",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Eloquent/Provider.php#L55-L65 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Eloquent/Provider.php | Provider.findByName | public function findByName($name)
{
$model = $this->createModel();
if ( ! $group = $model->newQuery()->where('name', '=', $name)->first())
{
throw new GroupNotFoundException("A group could not be found with the name [$name].");
}
return $group;
} | php | public function findByName($name)
{
$model = $this->createModel();
if ( ! $group = $model->newQuery()->where('name', '=', $name)->first())
{
throw new GroupNotFoundException("A group could not be found with the name [$name].");
}
return $group;
} | [
"public",
"function",
"findByName",
"(",
"$",
"name",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"if",
"(",
"!",
"$",
"group",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"where",
"(",
"'name'",
",",
"'='",
",",
"$",
"name",
")",
"->",
"first",
"(",
")",
")",
"{",
"throw",
"new",
"GroupNotFoundException",
"(",
"\"A group could not be found with the name [$name].\"",
")",
";",
"}",
"return",
"$",
"group",
";",
"}"
] | Find the group by name.
@param string $name
@return \Cartalyst\Sentry\Groups\GroupInterface $group
@throws \Cartalyst\Sentry\Groups\GroupNotFoundException | [
"Find",
"the",
"group",
"by",
"name",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Eloquent/Provider.php#L74-L84 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Eloquent/Provider.php | Provider.create | public function create(array $attributes)
{
$group = $this->createModel();
$group->fill($attributes);
$group->save();
return $group;
} | php | public function create(array $attributes)
{
$group = $this->createModel();
$group->fill($attributes);
$group->save();
return $group;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"group",
"->",
"fill",
"(",
"$",
"attributes",
")",
";",
"$",
"group",
"->",
"save",
"(",
")",
";",
"return",
"$",
"group",
";",
"}"
] | Creates a group.
@param array $attributes
@return \Cartalyst\Sentry\Groups\GroupInterface | [
"Creates",
"a",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Eloquent/Provider.php#L104-L110 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Group.php | Group.hasAccess | public function hasAccess($permissions, $all = true)
{
$groupPermissions = $this->getPermissions();
foreach ((array) $permissions as $permission)
{
// We will set a flag now for whether this permission was
// matched at all.
$matched = true;
// Now, let's check if the permission ends in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
if ((strlen($permission) > 1) and \Text::ends_with($permission, '*'))
{
$matched = false;
foreach ($groupPermissions as $groupPermission => $value)
{
// Strip the '*' off the end of the permission.
$checkPermission = substr($permission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkPermission != $groupPermission and \Text::starts_with($groupPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
// Now, let's check if the permission starts in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
elseif ((strlen($permission) > 1) and \Text::starts_with($permission, '*'))
{
$matched = false;
foreach ($groupPermissions as $groupPermission => $value)
{
// Strip the '*' off the start of the permission.
$checkPermission = substr($permission, 1);
// We will make sure that the merged permission does not
// exactly match our permission, but ends with it.
if ($checkPermission != $groupPermission and \Text::ends_with($groupPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
else
{
$matched = false;
foreach ($groupPermissions as $groupPermission => $value)
{
// This time check if the groupPermission ends in wildcard "*" symbol.
if ((strlen($groupPermission) > 1) and \Text::ends_with($groupPermission, '*'))
{
$matched = false;
// Strip the '*' off the end of the permission.
$checkGroupPermission = substr($groupPermission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkGroupPermission != $permission and \Text::starts_with($permission, $checkGroupPermission) and $value == 1)
{
$matched = true;
break;
}
}
// Otherwise, we'll fallback to standard permissions checking where
// we match that permissions explicitly exist.
elseif ($permission == $groupPermission and $groupPermissions[$permission] == 1)
{
$matched = true;
break;
}
}
}
// Now, we will check if we have to match all
// permissions or any permission and return
// accordingly.
if ($all === true and $matched === false)
{
return false;
}
elseif ($all === false and $matched === true)
{
return true;
}
}
if ($all === false)
{
return false;
}
return true;
} | php | public function hasAccess($permissions, $all = true)
{
$groupPermissions = $this->getPermissions();
foreach ((array) $permissions as $permission)
{
// We will set a flag now for whether this permission was
// matched at all.
$matched = true;
// Now, let's check if the permission ends in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
if ((strlen($permission) > 1) and \Text::ends_with($permission, '*'))
{
$matched = false;
foreach ($groupPermissions as $groupPermission => $value)
{
// Strip the '*' off the end of the permission.
$checkPermission = substr($permission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkPermission != $groupPermission and \Text::starts_with($groupPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
// Now, let's check if the permission starts in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
elseif ((strlen($permission) > 1) and \Text::starts_with($permission, '*'))
{
$matched = false;
foreach ($groupPermissions as $groupPermission => $value)
{
// Strip the '*' off the start of the permission.
$checkPermission = substr($permission, 1);
// We will make sure that the merged permission does not
// exactly match our permission, but ends with it.
if ($checkPermission != $groupPermission and \Text::ends_with($groupPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
else
{
$matched = false;
foreach ($groupPermissions as $groupPermission => $value)
{
// This time check if the groupPermission ends in wildcard "*" symbol.
if ((strlen($groupPermission) > 1) and \Text::ends_with($groupPermission, '*'))
{
$matched = false;
// Strip the '*' off the end of the permission.
$checkGroupPermission = substr($groupPermission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkGroupPermission != $permission and \Text::starts_with($permission, $checkGroupPermission) and $value == 1)
{
$matched = true;
break;
}
}
// Otherwise, we'll fallback to standard permissions checking where
// we match that permissions explicitly exist.
elseif ($permission == $groupPermission and $groupPermissions[$permission] == 1)
{
$matched = true;
break;
}
}
}
// Now, we will check if we have to match all
// permissions or any permission and return
// accordingly.
if ($all === true and $matched === false)
{
return false;
}
elseif ($all === false and $matched === true)
{
return true;
}
}
if ($all === false)
{
return false;
}
return true;
} | [
"public",
"function",
"hasAccess",
"(",
"$",
"permissions",
",",
"$",
"all",
"=",
"true",
")",
"{",
"$",
"groupPermissions",
"=",
"$",
"this",
"->",
"getPermissions",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"// We will set a flag now for whether this permission was",
"// matched at all.",
"$",
"matched",
"=",
"true",
";",
"// Now, let's check if the permission ends in a wildcard \"*\" symbol.",
"// If it does, we'll check through all the merged permissions to see",
"// if a permission exists which matches the wildcard.",
"if",
"(",
"(",
"strlen",
"(",
"$",
"permission",
")",
">",
"1",
")",
"and",
"\\",
"Text",
"::",
"ends_with",
"(",
"$",
"permission",
",",
"'*'",
")",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"foreach",
"(",
"$",
"groupPermissions",
"as",
"$",
"groupPermission",
"=>",
"$",
"value",
")",
"{",
"// Strip the '*' off the end of the permission.",
"$",
"checkPermission",
"=",
"substr",
"(",
"$",
"permission",
",",
"0",
",",
"-",
"1",
")",
";",
"// We will make sure that the merged permission does not",
"// exactly match our permission, but starts with it.",
"if",
"(",
"$",
"checkPermission",
"!=",
"$",
"groupPermission",
"and",
"\\",
"Text",
"::",
"starts_with",
"(",
"$",
"groupPermission",
",",
"$",
"checkPermission",
")",
"and",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"// Now, let's check if the permission starts in a wildcard \"*\" symbol.",
"// If it does, we'll check through all the merged permissions to see",
"// if a permission exists which matches the wildcard.",
"elseif",
"(",
"(",
"strlen",
"(",
"$",
"permission",
")",
">",
"1",
")",
"and",
"\\",
"Text",
"::",
"starts_with",
"(",
"$",
"permission",
",",
"'*'",
")",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"foreach",
"(",
"$",
"groupPermissions",
"as",
"$",
"groupPermission",
"=>",
"$",
"value",
")",
"{",
"// Strip the '*' off the start of the permission.",
"$",
"checkPermission",
"=",
"substr",
"(",
"$",
"permission",
",",
"1",
")",
";",
"// We will make sure that the merged permission does not",
"// exactly match our permission, but ends with it.",
"if",
"(",
"$",
"checkPermission",
"!=",
"$",
"groupPermission",
"and",
"\\",
"Text",
"::",
"ends_with",
"(",
"$",
"groupPermission",
",",
"$",
"checkPermission",
")",
"and",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"matched",
"=",
"false",
";",
"foreach",
"(",
"$",
"groupPermissions",
"as",
"$",
"groupPermission",
"=>",
"$",
"value",
")",
"{",
"// This time check if the groupPermission ends in wildcard \"*\" symbol.",
"if",
"(",
"(",
"strlen",
"(",
"$",
"groupPermission",
")",
">",
"1",
")",
"and",
"\\",
"Text",
"::",
"ends_with",
"(",
"$",
"groupPermission",
",",
"'*'",
")",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"// Strip the '*' off the end of the permission.",
"$",
"checkGroupPermission",
"=",
"substr",
"(",
"$",
"groupPermission",
",",
"0",
",",
"-",
"1",
")",
";",
"// We will make sure that the merged permission does not",
"// exactly match our permission, but starts with it.",
"if",
"(",
"$",
"checkGroupPermission",
"!=",
"$",
"permission",
"and",
"\\",
"Text",
"::",
"starts_with",
"(",
"$",
"permission",
",",
"$",
"checkGroupPermission",
")",
"and",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"// Otherwise, we'll fallback to standard permissions checking where",
"// we match that permissions explicitly exist.",
"elseif",
"(",
"$",
"permission",
"==",
"$",
"groupPermission",
"and",
"$",
"groupPermissions",
"[",
"$",
"permission",
"]",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"// Now, we will check if we have to match all",
"// permissions or any permission and return",
"// accordingly.",
"if",
"(",
"$",
"all",
"===",
"true",
"and",
"$",
"matched",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"all",
"===",
"false",
"and",
"$",
"matched",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"all",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | See if a group has access to the passed permission(s).
If multiple permissions are passed, the group must
have access to all permissions passed through, unless the
"all" flag is set to false.
@param string|array $permissions
@param bool $all
@return bool | [
"See",
"if",
"a",
"group",
"has",
"access",
"to",
"the",
"passed",
"permission",
"(",
"s",
")",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Group.php#L121-L227 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Group.php | Group.delete | public function delete()
{
\DB::delete('users_groups')
->where('group_id', '=', $this->pk())
->execute($this->_db);
return parent::delete();
} | php | public function delete()
{
\DB::delete('users_groups')
->where('group_id', '=', $this->pk())
->execute($this->_db);
return parent::delete();
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"\\",
"DB",
"::",
"delete",
"(",
"'users_groups'",
")",
"->",
"where",
"(",
"'group_id'",
",",
"'='",
",",
"$",
"this",
"->",
"pk",
"(",
")",
")",
"->",
"execute",
"(",
"$",
"this",
"->",
"_db",
")",
";",
"return",
"parent",
"::",
"delete",
"(",
")",
";",
"}"
] | Delete the group.
@return bool | [
"Delete",
"the",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Group.php#L246-L253 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Group.php | Group.setPermissionsAttribute | public function setPermissionsAttribute(array $permissions)
{
// Merge permissions
$permissions = array_merge($this->getPermissions(), $permissions);
// Loop through and adjust permissions as needed
foreach ($permissions as $permission => &$value)
{
// Lets make sure their is a valid permission value
if ( ! in_array($value = (int) $value, $this->allowedPermissionsValues))
{
throw new \InvalidArgumentException("Invalid value [$value] for permission [$permission] given.");
}
// If the value is 0, delete it
if ($value === 0)
{
unset($permissions[$permission]);
}
}
$this->attributes['permissions'] = ( ! empty($permissions)) ? $permissions : '';
} | php | public function setPermissionsAttribute(array $permissions)
{
// Merge permissions
$permissions = array_merge($this->getPermissions(), $permissions);
// Loop through and adjust permissions as needed
foreach ($permissions as $permission => &$value)
{
// Lets make sure their is a valid permission value
if ( ! in_array($value = (int) $value, $this->allowedPermissionsValues))
{
throw new \InvalidArgumentException("Invalid value [$value] for permission [$permission] given.");
}
// If the value is 0, delete it
if ($value === 0)
{
unset($permissions[$permission]);
}
}
$this->attributes['permissions'] = ( ! empty($permissions)) ? $permissions : '';
} | [
"public",
"function",
"setPermissionsAttribute",
"(",
"array",
"$",
"permissions",
")",
"{",
"// Merge permissions",
"$",
"permissions",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getPermissions",
"(",
")",
",",
"$",
"permissions",
")",
";",
"// Loop through and adjust permissions as needed",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
"=>",
"&",
"$",
"value",
")",
"{",
"// Lets make sure their is a valid permission value",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
",",
"$",
"this",
"->",
"allowedPermissionsValues",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid value [$value] for permission [$permission] given.\"",
")",
";",
"}",
"// If the value is 0, delete it",
"if",
"(",
"$",
"value",
"===",
"0",
")",
"{",
"unset",
"(",
"$",
"permissions",
"[",
"$",
"permission",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"attributes",
"[",
"'permissions'",
"]",
"=",
"(",
"!",
"empty",
"(",
"$",
"permissions",
")",
")",
"?",
"$",
"permissions",
":",
"''",
";",
"}"
] | Mutator for taking permissions.
@param array $permissions
@return void
@throws \InvalidArgumentException | [
"Mutator",
"for",
"taking",
"permissions",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Group.php#L289-L311 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Group.php | Group.validate | public function validate()
{
// Check if name field was passed
$name = $this->name;
if ( empty($name) )
{
throw new NameRequiredException("A name is required for a group, none given.");
}
// Check if group already exists
$persistedGroup = $this->unique_key_exists($name, 'name');
if (! $persistedGroup)
{
throw new GroupExistsException("A group already exists with name [$name], names must be unique for groups.");
}
return true;
} | php | public function validate()
{
// Check if name field was passed
$name = $this->name;
if ( empty($name) )
{
throw new NameRequiredException("A name is required for a group, none given.");
}
// Check if group already exists
$persistedGroup = $this->unique_key_exists($name, 'name');
if (! $persistedGroup)
{
throw new GroupExistsException("A group already exists with name [$name], names must be unique for groups.");
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"// Check if name field was passed",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"NameRequiredException",
"(",
"\"A name is required for a group, none given.\"",
")",
";",
"}",
"// Check if group already exists",
"$",
"persistedGroup",
"=",
"$",
"this",
"->",
"unique_key_exists",
"(",
"$",
"name",
",",
"'name'",
")",
";",
"if",
"(",
"!",
"$",
"persistedGroup",
")",
"{",
"throw",
"new",
"GroupExistsException",
"(",
"\"A group already exists with name [$name], names must be unique for groups.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validates the group and throws a number of
Exceptions if validation fails.
@return bool
@throws \Cartalyst\Sentry\Groups\NameRequiredException
@throws \Cartalyst\Sentry\Groups\GroupExistsException | [
"Validates",
"the",
"group",
"and",
"throws",
"a",
"number",
"of",
"Exceptions",
"if",
"validation",
"fails",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Group.php#L322-L341 |
cartalyst/sentry | src/Cartalyst/Sentry/Groups/Kohana/Group.php | Group.unique_key_exists | public function unique_key_exists($value, $field)
{
$total = \DB::select(array(\DB::expr('COUNT(*)'), 'total_count'))
->from($this->_table_name)
->where($field, '=', $value)
->where($this->_primary_key, '!=', $this->pk())
->execute($this->_db)
->get('total_count');
return ($total == 0);
} | php | public function unique_key_exists($value, $field)
{
$total = \DB::select(array(\DB::expr('COUNT(*)'), 'total_count'))
->from($this->_table_name)
->where($field, '=', $value)
->where($this->_primary_key, '!=', $this->pk())
->execute($this->_db)
->get('total_count');
return ($total == 0);
} | [
"public",
"function",
"unique_key_exists",
"(",
"$",
"value",
",",
"$",
"field",
")",
"{",
"$",
"total",
"=",
"\\",
"DB",
"::",
"select",
"(",
"array",
"(",
"\\",
"DB",
"::",
"expr",
"(",
"'COUNT(*)'",
")",
",",
"'total_count'",
")",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"_table_name",
")",
"->",
"where",
"(",
"$",
"field",
",",
"'='",
",",
"$",
"value",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"_primary_key",
",",
"'!='",
",",
"$",
"this",
"->",
"pk",
"(",
")",
")",
"->",
"execute",
"(",
"$",
"this",
"->",
"_db",
")",
"->",
"get",
"(",
"'total_count'",
")",
";",
"return",
"(",
"$",
"total",
"==",
"0",
")",
";",
"}"
] | Tests if a unique key value exists in the database.
@param mixed $value the value to test
@param string $field field name
@return boolean | [
"Tests",
"if",
"a",
"unique",
"key",
"value",
"exists",
"in",
"the",
"database",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Groups/Kohana/Group.php#L350-L360 |
cartalyst/sentry | src/Cartalyst/Sentry/Hashing/WhirlpoolHasher.php | WhirlpoolHasher.checkhash | public function checkhash($string, $hashedString)
{
$salt = substr($hashedString, 0, $this->saltLength);
return $this->slowEquals($salt.hash('whirlpool', $salt.$string), $hashedString);
} | php | public function checkhash($string, $hashedString)
{
$salt = substr($hashedString, 0, $this->saltLength);
return $this->slowEquals($salt.hash('whirlpool', $salt.$string), $hashedString);
} | [
"public",
"function",
"checkhash",
"(",
"$",
"string",
",",
"$",
"hashedString",
")",
"{",
"$",
"salt",
"=",
"substr",
"(",
"$",
"hashedString",
",",
"0",
",",
"$",
"this",
"->",
"saltLength",
")",
";",
"return",
"$",
"this",
"->",
"slowEquals",
"(",
"$",
"salt",
".",
"hash",
"(",
"'whirlpool'",
",",
"$",
"salt",
".",
"$",
"string",
")",
",",
"$",
"hashedString",
")",
";",
"}"
] | Check string against hashed string.
@param string $string
@param string $hashedString
@return bool | [
"Check",
"string",
"against",
"hashed",
"string",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Hashing/WhirlpoolHasher.php#L51-L56 |
cartalyst/sentry | src/Cartalyst/Sentry/Facades/Kohana/Sentry.php | Sentry.createSentry | public static function createSentry()
{
$config = \Kohana::$config->load('sentry')->as_array();
//If the user hasn't defined a config file offer defaults
if ( count($config) == 0 )
{
$config = array(
'session_driver' => 'native',
'session_key' => 'cartalyst_sentry',
'cookie_key' => 'cartalyst_sentry',
'hasher' => 'Bcrypt'
);
}
//Choose the hasher
switch ( $config['hasher'] )
{
default:
case 'Bcrypt':
$hasher = new \Cartalyst\Sentry\Hashing\BcryptHasher;
break;
case 'Native':
$hasher = new \Cartalyst\Sentry\Hashing\NativeHasher;
break;
case 'Sha256':
$hasher = new \Cartalyst\Sentry\Hashing\Sha256Hasher;
break;
}
return new BaseSentry(
$userProvider = new UserProvider($hasher),
new GroupProvider,
new ThrottleProvider($userProvider),
new KohanaSession(\Session::instance($config['session_driver']), $config['session_key']),
new KohanaCookie($config['cookie_key']),
\Request::$client_ip
);
} | php | public static function createSentry()
{
$config = \Kohana::$config->load('sentry')->as_array();
//If the user hasn't defined a config file offer defaults
if ( count($config) == 0 )
{
$config = array(
'session_driver' => 'native',
'session_key' => 'cartalyst_sentry',
'cookie_key' => 'cartalyst_sentry',
'hasher' => 'Bcrypt'
);
}
//Choose the hasher
switch ( $config['hasher'] )
{
default:
case 'Bcrypt':
$hasher = new \Cartalyst\Sentry\Hashing\BcryptHasher;
break;
case 'Native':
$hasher = new \Cartalyst\Sentry\Hashing\NativeHasher;
break;
case 'Sha256':
$hasher = new \Cartalyst\Sentry\Hashing\Sha256Hasher;
break;
}
return new BaseSentry(
$userProvider = new UserProvider($hasher),
new GroupProvider,
new ThrottleProvider($userProvider),
new KohanaSession(\Session::instance($config['session_driver']), $config['session_key']),
new KohanaCookie($config['cookie_key']),
\Request::$client_ip
);
} | [
"public",
"static",
"function",
"createSentry",
"(",
")",
"{",
"$",
"config",
"=",
"\\",
"Kohana",
"::",
"$",
"config",
"->",
"load",
"(",
"'sentry'",
")",
"->",
"as_array",
"(",
")",
";",
"//If the user hasn't defined a config file offer defaults",
"if",
"(",
"count",
"(",
"$",
"config",
")",
"==",
"0",
")",
"{",
"$",
"config",
"=",
"array",
"(",
"'session_driver'",
"=>",
"'native'",
",",
"'session_key'",
"=>",
"'cartalyst_sentry'",
",",
"'cookie_key'",
"=>",
"'cartalyst_sentry'",
",",
"'hasher'",
"=>",
"'Bcrypt'",
")",
";",
"}",
"//Choose the hasher",
"switch",
"(",
"$",
"config",
"[",
"'hasher'",
"]",
")",
"{",
"default",
":",
"case",
"'Bcrypt'",
":",
"$",
"hasher",
"=",
"new",
"\\",
"Cartalyst",
"\\",
"Sentry",
"\\",
"Hashing",
"\\",
"BcryptHasher",
";",
"break",
";",
"case",
"'Native'",
":",
"$",
"hasher",
"=",
"new",
"\\",
"Cartalyst",
"\\",
"Sentry",
"\\",
"Hashing",
"\\",
"NativeHasher",
";",
"break",
";",
"case",
"'Sha256'",
":",
"$",
"hasher",
"=",
"new",
"\\",
"Cartalyst",
"\\",
"Sentry",
"\\",
"Hashing",
"\\",
"Sha256Hasher",
";",
"break",
";",
"}",
"return",
"new",
"BaseSentry",
"(",
"$",
"userProvider",
"=",
"new",
"UserProvider",
"(",
"$",
"hasher",
")",
",",
"new",
"GroupProvider",
",",
"new",
"ThrottleProvider",
"(",
"$",
"userProvider",
")",
",",
"new",
"KohanaSession",
"(",
"\\",
"Session",
"::",
"instance",
"(",
"$",
"config",
"[",
"'session_driver'",
"]",
")",
",",
"$",
"config",
"[",
"'session_key'",
"]",
")",
",",
"new",
"KohanaCookie",
"(",
"$",
"config",
"[",
"'cookie_key'",
"]",
")",
",",
"\\",
"Request",
"::",
"$",
"client_ip",
")",
";",
"}"
] | Creates a new instance of Sentry.
@return \Cartalyst\Sentry\Sentry | [
"Creates",
"a",
"new",
"instance",
"of",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/Kohana/Sentry.php#L36-L74 |
cartalyst/sentry | src/Cartalyst/Sentry/Cookies/IlluminateCookie.php | IlluminateCookie.put | public function put($value, $minutes)
{
$cookie = $this->jar->make($this->getKey(), $value, $minutes);
$this->jar->queue($cookie);
} | php | public function put($value, $minutes)
{
$cookie = $this->jar->make($this->getKey(), $value, $minutes);
$this->jar->queue($cookie);
} | [
"public",
"function",
"put",
"(",
"$",
"value",
",",
"$",
"minutes",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"jar",
"->",
"make",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"$",
"value",
",",
"$",
"minutes",
")",
";",
"$",
"this",
"->",
"jar",
"->",
"queue",
"(",
"$",
"cookie",
")",
";",
"}"
] | Put a value in the Sentry cookie.
@param mixed $value
@param int $minutes
@return void | [
"Put",
"a",
"value",
"in",
"the",
"Sentry",
"cookie",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Cookies/IlluminateCookie.php#L100-L104 |
cartalyst/sentry | src/Cartalyst/Sentry/Cookies/IlluminateCookie.php | IlluminateCookie.forever | public function forever($value)
{
$cookie = $this->jar->forever($this->getKey(), $value);
$this->jar->queue($cookie);
} | php | public function forever($value)
{
$cookie = $this->jar->forever($this->getKey(), $value);
$this->jar->queue($cookie);
} | [
"public",
"function",
"forever",
"(",
"$",
"value",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"jar",
"->",
"forever",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"jar",
"->",
"queue",
"(",
"$",
"cookie",
")",
";",
"}"
] | Put a value in the Sentry cookie forever.
@param mixed $value
@return void | [
"Put",
"a",
"value",
"in",
"the",
"Sentry",
"cookie",
"forever",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Cookies/IlluminateCookie.php#L112-L116 |
cartalyst/sentry | src/Cartalyst/Sentry/Cookies/IlluminateCookie.php | IlluminateCookie.get | public function get()
{
$key = $this->getKey();
$queued = $this->jar->getQueuedCookies();
if (isset($queued[$key]))
{
return $queued[$key];
}
if ($this->strategy === 'request')
{
return $this->request->cookie($key);
}
else
{
return $this->jar->get($key);
}
} | php | public function get()
{
$key = $this->getKey();
$queued = $this->jar->getQueuedCookies();
if (isset($queued[$key]))
{
return $queued[$key];
}
if ($this->strategy === 'request')
{
return $this->request->cookie($key);
}
else
{
return $this->jar->get($key);
}
} | [
"public",
"function",
"get",
"(",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
")",
";",
"$",
"queued",
"=",
"$",
"this",
"->",
"jar",
"->",
"getQueuedCookies",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"queued",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"queued",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"strategy",
"===",
"'request'",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"cookie",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"jar",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"}"
] | Get the Sentry cookie value.
@return mixed | [
"Get",
"the",
"Sentry",
"cookie",
"value",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Cookies/IlluminateCookie.php#L123-L141 |
cartalyst/sentry | src/Cartalyst/Sentry/Cookies/IlluminateCookie.php | IlluminateCookie.forget | public function forget()
{
$cookie = $this->jar->forget($this->getKey());
$this->jar->queue($cookie);
} | php | public function forget()
{
$cookie = $this->jar->forget($this->getKey());
$this->jar->queue($cookie);
} | [
"public",
"function",
"forget",
"(",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"jar",
"->",
"forget",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
";",
"$",
"this",
"->",
"jar",
"->",
"queue",
"(",
"$",
"cookie",
")",
";",
"}"
] | Remove the Sentry cookie.
@return void | [
"Remove",
"the",
"Sentry",
"cookie",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Cookies/IlluminateCookie.php#L148-L152 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.register | public function register()
{
$this->registerHasher();
$this->registerUserProvider();
$this->registerGroupProvider();
$this->registerThrottleProvider();
$this->registerSession();
$this->registerCookie();
$this->registerSentry();
} | php | public function register()
{
$this->registerHasher();
$this->registerUserProvider();
$this->registerGroupProvider();
$this->registerThrottleProvider();
$this->registerSession();
$this->registerCookie();
$this->registerSentry();
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"registerHasher",
"(",
")",
";",
"$",
"this",
"->",
"registerUserProvider",
"(",
")",
";",
"$",
"this",
"->",
"registerGroupProvider",
"(",
")",
";",
"$",
"this",
"->",
"registerThrottleProvider",
"(",
")",
";",
"$",
"this",
"->",
"registerSession",
"(",
")",
";",
"$",
"this",
"->",
"registerCookie",
"(",
")",
";",
"$",
"this",
"->",
"registerSentry",
"(",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L50-L59 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerHasher | protected function registerHasher()
{
$this->app['sentry.hasher'] = $this->app->share(function($app)
{
$hasher = $app['config']['cartalyst/sentry::hasher'];
switch ($hasher)
{
case 'native':
return new NativeHasher;
break;
case 'bcrypt':
return new BcryptHasher;
break;
case 'sha256':
return new Sha256Hasher;
break;
case 'whirlpool':
return new WhirlpoolHasher;
break;
}
throw new \InvalidArgumentException("Invalid hasher [$hasher] chosen for Sentry.");
});
} | php | protected function registerHasher()
{
$this->app['sentry.hasher'] = $this->app->share(function($app)
{
$hasher = $app['config']['cartalyst/sentry::hasher'];
switch ($hasher)
{
case 'native':
return new NativeHasher;
break;
case 'bcrypt':
return new BcryptHasher;
break;
case 'sha256':
return new Sha256Hasher;
break;
case 'whirlpool':
return new WhirlpoolHasher;
break;
}
throw new \InvalidArgumentException("Invalid hasher [$hasher] chosen for Sentry.");
});
} | [
"protected",
"function",
"registerHasher",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry.hasher'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"hasher",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::hasher'",
"]",
";",
"switch",
"(",
"$",
"hasher",
")",
"{",
"case",
"'native'",
":",
"return",
"new",
"NativeHasher",
";",
"break",
";",
"case",
"'bcrypt'",
":",
"return",
"new",
"BcryptHasher",
";",
"break",
";",
"case",
"'sha256'",
":",
"return",
"new",
"Sha256Hasher",
";",
"break",
";",
"case",
"'whirlpool'",
":",
"return",
"new",
"WhirlpoolHasher",
";",
"break",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid hasher [$hasher] chosen for Sentry.\"",
")",
";",
"}",
")",
";",
"}"
] | Register the hasher used by Sentry.
@return void | [
"Register",
"the",
"hasher",
"used",
"by",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L66-L93 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerUserProvider | protected function registerUserProvider()
{
$this->app['sentry.user'] = $this->app->share(function($app)
{
$model = $app['config']['cartalyst/sentry::users.model'];
// We will never be accessing a user in Sentry without accessing
// the user provider first. So, we can lazily set up our user
// model's login attribute here. If you are manually using the
// attribute outside of Sentry, you will need to ensure you are
// overriding at runtime.
if (method_exists($model, 'setLoginAttributeName'))
{
$loginAttribute = $app['config']['cartalyst/sentry::users.login_attribute'];
forward_static_call_array(
array($model, 'setLoginAttributeName'),
array($loginAttribute)
);
}
// Define the Group model to use for relationships.
if (method_exists($model, 'setGroupModel'))
{
$groupModel = $app['config']['cartalyst/sentry::groups.model'];
forward_static_call_array(
array($model, 'setGroupModel'),
array($groupModel)
);
}
// Define the user group pivot table name to use for relationships.
if (method_exists($model, 'setUserGroupsPivot'))
{
$pivotTable = $app['config']['cartalyst/sentry::user_groups_pivot_table'];
forward_static_call_array(
array($model, 'setUserGroupsPivot'),
array($pivotTable)
);
}
return new UserProvider($app['sentry.hasher'], $model);
});
} | php | protected function registerUserProvider()
{
$this->app['sentry.user'] = $this->app->share(function($app)
{
$model = $app['config']['cartalyst/sentry::users.model'];
// We will never be accessing a user in Sentry without accessing
// the user provider first. So, we can lazily set up our user
// model's login attribute here. If you are manually using the
// attribute outside of Sentry, you will need to ensure you are
// overriding at runtime.
if (method_exists($model, 'setLoginAttributeName'))
{
$loginAttribute = $app['config']['cartalyst/sentry::users.login_attribute'];
forward_static_call_array(
array($model, 'setLoginAttributeName'),
array($loginAttribute)
);
}
// Define the Group model to use for relationships.
if (method_exists($model, 'setGroupModel'))
{
$groupModel = $app['config']['cartalyst/sentry::groups.model'];
forward_static_call_array(
array($model, 'setGroupModel'),
array($groupModel)
);
}
// Define the user group pivot table name to use for relationships.
if (method_exists($model, 'setUserGroupsPivot'))
{
$pivotTable = $app['config']['cartalyst/sentry::user_groups_pivot_table'];
forward_static_call_array(
array($model, 'setUserGroupsPivot'),
array($pivotTable)
);
}
return new UserProvider($app['sentry.hasher'], $model);
});
} | [
"protected",
"function",
"registerUserProvider",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry.user'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"model",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::users.model'",
"]",
";",
"// We will never be accessing a user in Sentry without accessing",
"// the user provider first. So, we can lazily set up our user",
"// model's login attribute here. If you are manually using the",
"// attribute outside of Sentry, you will need to ensure you are",
"// overriding at runtime.",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setLoginAttributeName'",
")",
")",
"{",
"$",
"loginAttribute",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::users.login_attribute'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setLoginAttributeName'",
")",
",",
"array",
"(",
"$",
"loginAttribute",
")",
")",
";",
"}",
"// Define the Group model to use for relationships.",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setGroupModel'",
")",
")",
"{",
"$",
"groupModel",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::groups.model'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setGroupModel'",
")",
",",
"array",
"(",
"$",
"groupModel",
")",
")",
";",
"}",
"// Define the user group pivot table name to use for relationships.",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setUserGroupsPivot'",
")",
")",
"{",
"$",
"pivotTable",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::user_groups_pivot_table'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setUserGroupsPivot'",
")",
",",
"array",
"(",
"$",
"pivotTable",
")",
")",
";",
"}",
"return",
"new",
"UserProvider",
"(",
"$",
"app",
"[",
"'sentry.hasher'",
"]",
",",
"$",
"model",
")",
";",
"}",
")",
";",
"}"
] | Register the user provider used by Sentry.
@return void | [
"Register",
"the",
"user",
"provider",
"used",
"by",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L100-L145 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerGroupProvider | protected function registerGroupProvider()
{
$this->app['sentry.group'] = $this->app->share(function($app)
{
$model = $app['config']['cartalyst/sentry::groups.model'];
// Define the User model to use for relationships.
if (method_exists($model, 'setUserModel'))
{
$userModel = $app['config']['cartalyst/sentry::users.model'];
forward_static_call_array(
array($model, 'setUserModel'),
array($userModel)
);
}
// Define the user group pivot table name to use for relationships.
if (method_exists($model, 'setUserGroupsPivot'))
{
$pivotTable = $app['config']['cartalyst/sentry::user_groups_pivot_table'];
forward_static_call_array(
array($model, 'setUserGroupsPivot'),
array($pivotTable)
);
}
return new GroupProvider($model);
});
} | php | protected function registerGroupProvider()
{
$this->app['sentry.group'] = $this->app->share(function($app)
{
$model = $app['config']['cartalyst/sentry::groups.model'];
// Define the User model to use for relationships.
if (method_exists($model, 'setUserModel'))
{
$userModel = $app['config']['cartalyst/sentry::users.model'];
forward_static_call_array(
array($model, 'setUserModel'),
array($userModel)
);
}
// Define the user group pivot table name to use for relationships.
if (method_exists($model, 'setUserGroupsPivot'))
{
$pivotTable = $app['config']['cartalyst/sentry::user_groups_pivot_table'];
forward_static_call_array(
array($model, 'setUserGroupsPivot'),
array($pivotTable)
);
}
return new GroupProvider($model);
});
} | [
"protected",
"function",
"registerGroupProvider",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry.group'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"model",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::groups.model'",
"]",
";",
"// Define the User model to use for relationships.",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setUserModel'",
")",
")",
"{",
"$",
"userModel",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::users.model'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setUserModel'",
")",
",",
"array",
"(",
"$",
"userModel",
")",
")",
";",
"}",
"// Define the user group pivot table name to use for relationships.",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setUserGroupsPivot'",
")",
")",
"{",
"$",
"pivotTable",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::user_groups_pivot_table'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setUserGroupsPivot'",
")",
",",
"array",
"(",
"$",
"pivotTable",
")",
")",
";",
"}",
"return",
"new",
"GroupProvider",
"(",
"$",
"model",
")",
";",
"}",
")",
";",
"}"
] | Register the group provider used by Sentry.
@return void | [
"Register",
"the",
"group",
"provider",
"used",
"by",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L152-L182 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerThrottleProvider | protected function registerThrottleProvider()
{
$this->app['sentry.throttle'] = $this->app->share(function($app)
{
$model = $app['config']['cartalyst/sentry::throttling.model'];
$throttleProvider = new ThrottleProvider($app['sentry.user'], $model);
if ($app['config']['cartalyst/sentry::throttling.enabled'] === false)
{
$throttleProvider->disable();
}
if (method_exists($model, 'setAttemptLimit'))
{
$attemptLimit = $app['config']['cartalyst/sentry::throttling.attempt_limit'];
forward_static_call_array(
array($model, 'setAttemptLimit'),
array($attemptLimit)
);
}
if (method_exists($model, 'setSuspensionTime'))
{
$suspensionTime = $app['config']['cartalyst/sentry::throttling.suspension_time'];
forward_static_call_array(
array($model, 'setSuspensionTime'),
array($suspensionTime)
);
}
// Define the User model to use for relationships.
if (method_exists($model, 'setUserModel'))
{
$userModel = $app['config']['cartalyst/sentry::users.model'];
forward_static_call_array(
array($model, 'setUserModel'),
array($userModel)
);
}
return $throttleProvider;
});
} | php | protected function registerThrottleProvider()
{
$this->app['sentry.throttle'] = $this->app->share(function($app)
{
$model = $app['config']['cartalyst/sentry::throttling.model'];
$throttleProvider = new ThrottleProvider($app['sentry.user'], $model);
if ($app['config']['cartalyst/sentry::throttling.enabled'] === false)
{
$throttleProvider->disable();
}
if (method_exists($model, 'setAttemptLimit'))
{
$attemptLimit = $app['config']['cartalyst/sentry::throttling.attempt_limit'];
forward_static_call_array(
array($model, 'setAttemptLimit'),
array($attemptLimit)
);
}
if (method_exists($model, 'setSuspensionTime'))
{
$suspensionTime = $app['config']['cartalyst/sentry::throttling.suspension_time'];
forward_static_call_array(
array($model, 'setSuspensionTime'),
array($suspensionTime)
);
}
// Define the User model to use for relationships.
if (method_exists($model, 'setUserModel'))
{
$userModel = $app['config']['cartalyst/sentry::users.model'];
forward_static_call_array(
array($model, 'setUserModel'),
array($userModel)
);
}
return $throttleProvider;
});
} | [
"protected",
"function",
"registerThrottleProvider",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry.throttle'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"model",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::throttling.model'",
"]",
";",
"$",
"throttleProvider",
"=",
"new",
"ThrottleProvider",
"(",
"$",
"app",
"[",
"'sentry.user'",
"]",
",",
"$",
"model",
")",
";",
"if",
"(",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::throttling.enabled'",
"]",
"===",
"false",
")",
"{",
"$",
"throttleProvider",
"->",
"disable",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setAttemptLimit'",
")",
")",
"{",
"$",
"attemptLimit",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::throttling.attempt_limit'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setAttemptLimit'",
")",
",",
"array",
"(",
"$",
"attemptLimit",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setSuspensionTime'",
")",
")",
"{",
"$",
"suspensionTime",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::throttling.suspension_time'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setSuspensionTime'",
")",
",",
"array",
"(",
"$",
"suspensionTime",
")",
")",
";",
"}",
"// Define the User model to use for relationships.",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"'setUserModel'",
")",
")",
"{",
"$",
"userModel",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::users.model'",
"]",
";",
"forward_static_call_array",
"(",
"array",
"(",
"$",
"model",
",",
"'setUserModel'",
")",
",",
"array",
"(",
"$",
"userModel",
")",
")",
";",
"}",
"return",
"$",
"throttleProvider",
";",
"}",
")",
";",
"}"
] | Register the throttle provider used by Sentry.
@return void | [
"Register",
"the",
"throttle",
"provider",
"used",
"by",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L189-L234 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerSession | protected function registerSession()
{
$this->app['sentry.session'] = $this->app->share(function($app)
{
$key = $app['config']['cartalyst/sentry::cookie.key'];
return new IlluminateSession($app['session.store'], $key);
});
} | php | protected function registerSession()
{
$this->app['sentry.session'] = $this->app->share(function($app)
{
$key = $app['config']['cartalyst/sentry::cookie.key'];
return new IlluminateSession($app['session.store'], $key);
});
} | [
"protected",
"function",
"registerSession",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry.session'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"key",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::cookie.key'",
"]",
";",
"return",
"new",
"IlluminateSession",
"(",
"$",
"app",
"[",
"'session.store'",
"]",
",",
"$",
"key",
")",
";",
"}",
")",
";",
"}"
] | Register the session driver used by Sentry.
@return void | [
"Register",
"the",
"session",
"driver",
"used",
"by",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L241-L249 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerCookie | protected function registerCookie()
{
$this->app['sentry.cookie'] = $this->app->share(function($app)
{
$key = $app['config']['cartalyst/sentry::cookie.key'];
/**
* We'll default to using the 'request' strategy, but switch to
* 'jar' if the Laravel version in use is 4.0.*
*/
$strategy = 'request';
if (preg_match('/^4\.0\.\d*$/D', $app::VERSION))
{
$strategy = 'jar';
}
return new IlluminateCookie($app['request'], $app['cookie'], $key, $strategy);
});
} | php | protected function registerCookie()
{
$this->app['sentry.cookie'] = $this->app->share(function($app)
{
$key = $app['config']['cartalyst/sentry::cookie.key'];
/**
* We'll default to using the 'request' strategy, but switch to
* 'jar' if the Laravel version in use is 4.0.*
*/
$strategy = 'request';
if (preg_match('/^4\.0\.\d*$/D', $app::VERSION))
{
$strategy = 'jar';
}
return new IlluminateCookie($app['request'], $app['cookie'], $key, $strategy);
});
} | [
"protected",
"function",
"registerCookie",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry.cookie'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"key",
"=",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'cartalyst/sentry::cookie.key'",
"]",
";",
"/**\n\t\t\t * We'll default to using the 'request' strategy, but switch to\n\t\t\t * 'jar' if the Laravel version in use is 4.0.*\n\t\t\t */",
"$",
"strategy",
"=",
"'request'",
";",
"if",
"(",
"preg_match",
"(",
"'/^4\\.0\\.\\d*$/D'",
",",
"$",
"app",
"::",
"VERSION",
")",
")",
"{",
"$",
"strategy",
"=",
"'jar'",
";",
"}",
"return",
"new",
"IlluminateCookie",
"(",
"$",
"app",
"[",
"'request'",
"]",
",",
"$",
"app",
"[",
"'cookie'",
"]",
",",
"$",
"key",
",",
"$",
"strategy",
")",
";",
"}",
")",
";",
"}"
] | Register the cookie driver used by Sentry.
@return void | [
"Register",
"the",
"cookie",
"driver",
"used",
"by",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L256-L276 |
cartalyst/sentry | src/Cartalyst/Sentry/SentryServiceProvider.php | SentryServiceProvider.registerSentry | protected function registerSentry()
{
$this->app['sentry'] = $this->app->share(function($app)
{
return new Sentry(
$app['sentry.user'],
$app['sentry.group'],
$app['sentry.throttle'],
$app['sentry.session'],
$app['sentry.cookie'],
$app['request']->getClientIp()
);
});
$this->app->alias('sentry', 'Cartalyst\Sentry\Sentry');
} | php | protected function registerSentry()
{
$this->app['sentry'] = $this->app->share(function($app)
{
return new Sentry(
$app['sentry.user'],
$app['sentry.group'],
$app['sentry.throttle'],
$app['sentry.session'],
$app['sentry.cookie'],
$app['request']->getClientIp()
);
});
$this->app->alias('sentry', 'Cartalyst\Sentry\Sentry');
} | [
"protected",
"function",
"registerSentry",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'sentry'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"Sentry",
"(",
"$",
"app",
"[",
"'sentry.user'",
"]",
",",
"$",
"app",
"[",
"'sentry.group'",
"]",
",",
"$",
"app",
"[",
"'sentry.throttle'",
"]",
",",
"$",
"app",
"[",
"'sentry.session'",
"]",
",",
"$",
"app",
"[",
"'sentry.cookie'",
"]",
",",
"$",
"app",
"[",
"'request'",
"]",
"->",
"getClientIp",
"(",
")",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"'sentry'",
",",
"'Cartalyst\\Sentry\\Sentry'",
")",
";",
"}"
] | Takes all the components of Sentry and glues them
together to create Sentry.
@return void | [
"Takes",
"all",
"the",
"components",
"of",
"Sentry",
"and",
"glues",
"them",
"together",
"to",
"create",
"Sentry",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/SentryServiceProvider.php#L284-L299 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php | Throttle.suspend | public function suspend()
{
if ( ! $this->suspended)
{
$this->suspended = true;
$this->suspended_at = $this->freshTimeStamp();
$this->save();
}
} | php | public function suspend()
{
if ( ! $this->suspended)
{
$this->suspended = true;
$this->suspended_at = $this->freshTimeStamp();
$this->save();
}
} | [
"public",
"function",
"suspend",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"suspended",
")",
"{",
"$",
"this",
"->",
"suspended",
"=",
"true",
";",
"$",
"this",
"->",
"suspended_at",
"=",
"$",
"this",
"->",
"freshTimeStamp",
"(",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Suspend the user associated with the throttle
@return void | [
"Suspend",
"the",
"user",
"associated",
"with",
"the",
"throttle"
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php#L164-L172 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php | Throttle.ban | public function ban()
{
if ( ! $this->banned)
{
$this->banned = true;
$this->banned_at = $this->freshTimeStamp();
$this->save();
}
} | php | public function ban()
{
if ( ! $this->banned)
{
$this->banned = true;
$this->banned_at = $this->freshTimeStamp();
$this->save();
}
} | [
"public",
"function",
"ban",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"banned",
")",
"{",
"$",
"this",
"->",
"banned",
"=",
"true",
";",
"$",
"this",
"->",
"banned_at",
"=",
"$",
"this",
"->",
"freshTimeStamp",
"(",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Ban the user.
@return void | [
"Ban",
"the",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php#L212-L220 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php | Throttle.check | public function check()
{
if ($this->isBanned())
{
throw new UserBannedException(sprintf(
'User [%s] has been banned.',
$this->getUser()->getLogin()
));
}
if ($this->isSuspended())
{
throw new UserSuspendedException(sprintf(
'User [%s] has been suspended.',
$this->getUser()->getLogin()
));
}
return true;
} | php | public function check()
{
if ($this->isBanned())
{
throw new UserBannedException(sprintf(
'User [%s] has been banned.',
$this->getUser()->getLogin()
));
}
if ($this->isSuspended())
{
throw new UserSuspendedException(sprintf(
'User [%s] has been suspended.',
$this->getUser()->getLogin()
));
}
return true;
} | [
"public",
"function",
"check",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBanned",
"(",
")",
")",
"{",
"throw",
"new",
"UserBannedException",
"(",
"sprintf",
"(",
"'User [%s] has been banned.'",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLogin",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isSuspended",
"(",
")",
")",
"{",
"throw",
"new",
"UserSuspendedException",
"(",
"sprintf",
"(",
"'User [%s] has been suspended.'",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLogin",
"(",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Check user throttle status.
@return bool
@throws \Cartalyst\Sentry\Throttling\UserBannedException
@throws \Cartalyst\Sentry\Throttling\UserSuspendedException | [
"Check",
"user",
"throttle",
"status",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php#L254-L273 |
cartalyst/sentry | src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php | Throttle.toArray | public function toArray()
{
$result = parent::toArray();
if (isset($result['suspended']))
{
$result['suspended'] = $this->getSuspendedAttribute($result['suspended']);
}
if (isset($result['banned']))
{
$result['banned'] = $this->getBannedAttribute($result['banned']);
}
if (isset($result['last_attempt_at']) and $result['last_attempt_at'] instanceof DateTime)
{
$result['last_attempt_at'] = $result['last_attempt_at']->format('Y-m-d H:i:s');
}
if (isset($result['suspended_at']) and $result['suspended_at'] instanceof DateTime)
{
$result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s');
}
return $result;
} | php | public function toArray()
{
$result = parent::toArray();
if (isset($result['suspended']))
{
$result['suspended'] = $this->getSuspendedAttribute($result['suspended']);
}
if (isset($result['banned']))
{
$result['banned'] = $this->getBannedAttribute($result['banned']);
}
if (isset($result['last_attempt_at']) and $result['last_attempt_at'] instanceof DateTime)
{
$result['last_attempt_at'] = $result['last_attempt_at']->format('Y-m-d H:i:s');
}
if (isset($result['suspended_at']) and $result['suspended_at'] instanceof DateTime)
{
$result['suspended_at'] = $result['suspended_at']->format('Y-m-d H:i:s');
}
return $result;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"toArray",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'suspended'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'suspended'",
"]",
"=",
"$",
"this",
"->",
"getSuspendedAttribute",
"(",
"$",
"result",
"[",
"'suspended'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'banned'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'banned'",
"]",
"=",
"$",
"this",
"->",
"getBannedAttribute",
"(",
"$",
"result",
"[",
"'banned'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'last_attempt_at'",
"]",
")",
"and",
"$",
"result",
"[",
"'last_attempt_at'",
"]",
"instanceof",
"DateTime",
")",
"{",
"$",
"result",
"[",
"'last_attempt_at'",
"]",
"=",
"$",
"result",
"[",
"'last_attempt_at'",
"]",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'suspended_at'",
"]",
")",
"and",
"$",
"result",
"[",
"'suspended_at'",
"]",
"instanceof",
"DateTime",
")",
"{",
"$",
"result",
"[",
"'suspended_at'",
"]",
"=",
"$",
"result",
"[",
"'suspended_at'",
"]",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Convert the model instance to an array.
@return array | [
"Convert",
"the",
"model",
"instance",
"to",
"an",
"array",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Throttling/Eloquent/Throttle.php#L386-L408 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/User.php | User.attemptActivation | public function attemptActivation($activationCode)
{
if ($this->activated)
{
throw new UserAlreadyActivatedException('Cannot attempt activation on an already activated user.');
}
if ($activationCode == $this->activation_code)
{
$this->activation_code = null;
$this->activated = true;
$this->activated_at = new DateTime;
return $this->save();
}
return false;
} | php | public function attemptActivation($activationCode)
{
if ($this->activated)
{
throw new UserAlreadyActivatedException('Cannot attempt activation on an already activated user.');
}
if ($activationCode == $this->activation_code)
{
$this->activation_code = null;
$this->activated = true;
$this->activated_at = new DateTime;
return $this->save();
}
return false;
} | [
"public",
"function",
"attemptActivation",
"(",
"$",
"activationCode",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"activated",
")",
"{",
"throw",
"new",
"UserAlreadyActivatedException",
"(",
"'Cannot attempt activation on an already activated user.'",
")",
";",
"}",
"if",
"(",
"$",
"activationCode",
"==",
"$",
"this",
"->",
"activation_code",
")",
"{",
"$",
"this",
"->",
"activation_code",
"=",
"null",
";",
"$",
"this",
"->",
"activated",
"=",
"true",
";",
"$",
"this",
"->",
"activated_at",
"=",
"new",
"DateTime",
";",
"return",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Attempts to activate the given user by checking
the activate code. If the user is activated already,
an Exception is thrown.
@param string $activationCode
@return bool
@throws \Cartalyst\Sentry\Users\UserAlreadyActivatedException | [
"Attempts",
"to",
"activate",
"the",
"given",
"user",
"by",
"checking",
"the",
"activate",
"code",
".",
"If",
"the",
"user",
"is",
"activated",
"already",
"an",
"Exception",
"is",
"thrown",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/User.php#L392-L408 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/User.php | User.getGroups | public function getGroups()
{
if ( ! $this->userGroups)
{
$this->userGroups = $this->groups->find_all();
}
return $this->userGroups;
} | php | public function getGroups()
{
if ( ! $this->userGroups)
{
$this->userGroups = $this->groups->find_all();
}
return $this->userGroups;
} | [
"public",
"function",
"getGroups",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"userGroups",
")",
"{",
"$",
"this",
"->",
"userGroups",
"=",
"$",
"this",
"->",
"groups",
"->",
"find_all",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"userGroups",
";",
"}"
] | Returns an array of groups which the given
user belongs to.
@return array | [
"Returns",
"an",
"array",
"of",
"groups",
"which",
"the",
"given",
"user",
"belongs",
"to",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/User.php#L492-L500 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/User.php | User.addGroup | public function addGroup(GroupInterface $group)
{
if ( ! $this->inGroup($group))
{
$this->add('groups', $group);
}
return true;
} | php | public function addGroup(GroupInterface $group)
{
if ( ! $this->inGroup($group))
{
$this->add('groups', $group);
}
return true;
} | [
"public",
"function",
"addGroup",
"(",
"GroupInterface",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"inGroup",
"(",
"$",
"group",
")",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"'groups'",
",",
"$",
"group",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Adds the user to the given group.
@param \Cartalyst\Sentry\Groups\GroupInterface $group
@return bool | [
"Adds",
"the",
"user",
"to",
"the",
"given",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/User.php#L508-L516 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/User.php | User.removeGroup | public function removeGroup(GroupInterface $group)
{
if ($this->inGroup($group))
{
$this->remove('groups', $group);
}
return true;
} | php | public function removeGroup(GroupInterface $group)
{
if ($this->inGroup($group))
{
$this->remove('groups', $group);
}
return true;
} | [
"public",
"function",
"removeGroup",
"(",
"GroupInterface",
"$",
"group",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"inGroup",
"(",
"$",
"group",
")",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"'groups'",
",",
"$",
"group",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Removes the user from the given group.
@param \Cartalyst\Sentry\Groups\GroupInterface $group
@return bool | [
"Removes",
"the",
"user",
"from",
"the",
"given",
"group",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/User.php#L524-L532 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Kohana/User.php | User.hasPermission | public function hasPermission($permissions, $all = true)
{
$mergedPermissions = $this->getMergedPermissions();
foreach ((array) $permissions as $permission)
{
// We will set a flag now for whether this permission was
// matched at all.
$matched = true;
// Now, let's check if the permission ends in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
if ((strlen($permission) > 1) and \Text::ends_with($permission, '*'))
{
$matched = false;
foreach ($mergedPermissions as $mergedPermission => $value)
{
// Strip the '*' off the end of the permission.
$checkPermission = substr($permission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkPermission != $mergedPermission and \Text::starts_with($mergedPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
elseif ((strlen($permission) > 1) and \Text::starts_with($permission, '*'))
{
$matched = false;
foreach ($mergedPermissions as $mergedPermission => $value)
{
// Strip the '*' off the beginning of the permission.
$checkPermission = substr($permission, 1);
// We will make sure that the merged permission does not
// exactly match our permission, but ends with it.
if ($checkPermission != $mergedPermission and \Text::ends_with($mergedPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
else
{
$matched = false;
foreach ($mergedPermissions as $mergedPermission => $value)
{
// This time check if the mergedPermission ends in wildcard "*" symbol.
if ((strlen($mergedPermission) > 1) and \Text::ends_with($mergedPermission, '*'))
{
$matched = false;
// Strip the '*' off the end of the permission.
$checkMergedPermission = substr($mergedPermission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkMergedPermission != $permission and \Text::starts_with($permission, $checkMergedPermission) and $value == 1)
{
$matched = true;
break;
}
}
// Otherwise, we'll fallback to standard permissions checking where
// we match that permissions explicitly exist.
elseif ($permission == $mergedPermission and $mergedPermissions[$permission] == 1)
{
$matched = true;
break;
}
}
}
// Now, we will check if we have to match all
// permissions or any permission and return
// accordingly.
if ($all === true and $matched === false)
{
return false;
}
elseif ($all === false and $matched === true)
{
return true;
}
}
if ($all === false)
{
return false;
}
return true;
} | php | public function hasPermission($permissions, $all = true)
{
$mergedPermissions = $this->getMergedPermissions();
foreach ((array) $permissions as $permission)
{
// We will set a flag now for whether this permission was
// matched at all.
$matched = true;
// Now, let's check if the permission ends in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
if ((strlen($permission) > 1) and \Text::ends_with($permission, '*'))
{
$matched = false;
foreach ($mergedPermissions as $mergedPermission => $value)
{
// Strip the '*' off the end of the permission.
$checkPermission = substr($permission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkPermission != $mergedPermission and \Text::starts_with($mergedPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
elseif ((strlen($permission) > 1) and \Text::starts_with($permission, '*'))
{
$matched = false;
foreach ($mergedPermissions as $mergedPermission => $value)
{
// Strip the '*' off the beginning of the permission.
$checkPermission = substr($permission, 1);
// We will make sure that the merged permission does not
// exactly match our permission, but ends with it.
if ($checkPermission != $mergedPermission and \Text::ends_with($mergedPermission, $checkPermission) and $value == 1)
{
$matched = true;
break;
}
}
}
else
{
$matched = false;
foreach ($mergedPermissions as $mergedPermission => $value)
{
// This time check if the mergedPermission ends in wildcard "*" symbol.
if ((strlen($mergedPermission) > 1) and \Text::ends_with($mergedPermission, '*'))
{
$matched = false;
// Strip the '*' off the end of the permission.
$checkMergedPermission = substr($mergedPermission, 0, -1);
// We will make sure that the merged permission does not
// exactly match our permission, but starts with it.
if ($checkMergedPermission != $permission and \Text::starts_with($permission, $checkMergedPermission) and $value == 1)
{
$matched = true;
break;
}
}
// Otherwise, we'll fallback to standard permissions checking where
// we match that permissions explicitly exist.
elseif ($permission == $mergedPermission and $mergedPermissions[$permission] == 1)
{
$matched = true;
break;
}
}
}
// Now, we will check if we have to match all
// permissions or any permission and return
// accordingly.
if ($all === true and $matched === false)
{
return false;
}
elseif ($all === false and $matched === true)
{
return true;
}
}
if ($all === false)
{
return false;
}
return true;
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permissions",
",",
"$",
"all",
"=",
"true",
")",
"{",
"$",
"mergedPermissions",
"=",
"$",
"this",
"->",
"getMergedPermissions",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"// We will set a flag now for whether this permission was",
"// matched at all.",
"$",
"matched",
"=",
"true",
";",
"// Now, let's check if the permission ends in a wildcard \"*\" symbol.",
"// If it does, we'll check through all the merged permissions to see",
"// if a permission exists which matches the wildcard.",
"if",
"(",
"(",
"strlen",
"(",
"$",
"permission",
")",
">",
"1",
")",
"and",
"\\",
"Text",
"::",
"ends_with",
"(",
"$",
"permission",
",",
"'*'",
")",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"foreach",
"(",
"$",
"mergedPermissions",
"as",
"$",
"mergedPermission",
"=>",
"$",
"value",
")",
"{",
"// Strip the '*' off the end of the permission.",
"$",
"checkPermission",
"=",
"substr",
"(",
"$",
"permission",
",",
"0",
",",
"-",
"1",
")",
";",
"// We will make sure that the merged permission does not",
"// exactly match our permission, but starts with it.",
"if",
"(",
"$",
"checkPermission",
"!=",
"$",
"mergedPermission",
"and",
"\\",
"Text",
"::",
"starts_with",
"(",
"$",
"mergedPermission",
",",
"$",
"checkPermission",
")",
"and",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"elseif",
"(",
"(",
"strlen",
"(",
"$",
"permission",
")",
">",
"1",
")",
"and",
"\\",
"Text",
"::",
"starts_with",
"(",
"$",
"permission",
",",
"'*'",
")",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"foreach",
"(",
"$",
"mergedPermissions",
"as",
"$",
"mergedPermission",
"=>",
"$",
"value",
")",
"{",
"// Strip the '*' off the beginning of the permission.",
"$",
"checkPermission",
"=",
"substr",
"(",
"$",
"permission",
",",
"1",
")",
";",
"// We will make sure that the merged permission does not",
"// exactly match our permission, but ends with it.",
"if",
"(",
"$",
"checkPermission",
"!=",
"$",
"mergedPermission",
"and",
"\\",
"Text",
"::",
"ends_with",
"(",
"$",
"mergedPermission",
",",
"$",
"checkPermission",
")",
"and",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"matched",
"=",
"false",
";",
"foreach",
"(",
"$",
"mergedPermissions",
"as",
"$",
"mergedPermission",
"=>",
"$",
"value",
")",
"{",
"// This time check if the mergedPermission ends in wildcard \"*\" symbol.",
"if",
"(",
"(",
"strlen",
"(",
"$",
"mergedPermission",
")",
">",
"1",
")",
"and",
"\\",
"Text",
"::",
"ends_with",
"(",
"$",
"mergedPermission",
",",
"'*'",
")",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"// Strip the '*' off the end of the permission.",
"$",
"checkMergedPermission",
"=",
"substr",
"(",
"$",
"mergedPermission",
",",
"0",
",",
"-",
"1",
")",
";",
"// We will make sure that the merged permission does not",
"// exactly match our permission, but starts with it.",
"if",
"(",
"$",
"checkMergedPermission",
"!=",
"$",
"permission",
"and",
"\\",
"Text",
"::",
"starts_with",
"(",
"$",
"permission",
",",
"$",
"checkMergedPermission",
")",
"and",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"// Otherwise, we'll fallback to standard permissions checking where",
"// we match that permissions explicitly exist.",
"elseif",
"(",
"$",
"permission",
"==",
"$",
"mergedPermission",
"and",
"$",
"mergedPermissions",
"[",
"$",
"permission",
"]",
"==",
"1",
")",
"{",
"$",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"// Now, we will check if we have to match all",
"// permissions or any permission and return",
"// accordingly.",
"if",
"(",
"$",
"all",
"===",
"true",
"and",
"$",
"matched",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"all",
"===",
"false",
"and",
"$",
"matched",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"all",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | See if a user has access to the passed permission(s).
Permissions are merged from all groups the user belongs to
and then are checked against the passed permission(s).
If multiple permissions are passed, the user must
have access to all permissions passed through, unless the
"all" flag is set to false.
Super users DON'T have access no matter what.
@param string|array $permissions
@param bool $all
@return bool | [
"See",
"if",
"a",
"user",
"has",
"access",
"to",
"the",
"passed",
"permission",
"(",
"s",
")",
".",
"Permissions",
"are",
"merged",
"from",
"all",
"groups",
"the",
"user",
"belongs",
"to",
"and",
"then",
"are",
"checked",
"against",
"the",
"passed",
"permission",
"(",
"s",
")",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Kohana/User.php#L608-L711 |
cartalyst/sentry | src/Cartalyst/Sentry/Hashing/BcryptHasher.php | BcryptHasher.hash | public function hash($string)
{
// Format strength
$strength = str_pad($this->strength, 2, '0', STR_PAD_LEFT);
// Create salt
$salt = $this->createSalt();
//create prefix; $2y$ fixes blowfish weakness
$prefix = PHP_VERSION_ID < 50307 ? '$2a$' : '$2y$';
return crypt($string, $prefix.$strength.'$'.$salt.'$');
} | php | public function hash($string)
{
// Format strength
$strength = str_pad($this->strength, 2, '0', STR_PAD_LEFT);
// Create salt
$salt = $this->createSalt();
//create prefix; $2y$ fixes blowfish weakness
$prefix = PHP_VERSION_ID < 50307 ? '$2a$' : '$2y$';
return crypt($string, $prefix.$strength.'$'.$salt.'$');
} | [
"public",
"function",
"hash",
"(",
"$",
"string",
")",
"{",
"// Format strength",
"$",
"strength",
"=",
"str_pad",
"(",
"$",
"this",
"->",
"strength",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"// Create salt",
"$",
"salt",
"=",
"$",
"this",
"->",
"createSalt",
"(",
")",
";",
"//create prefix; $2y$ fixes blowfish weakness",
"$",
"prefix",
"=",
"PHP_VERSION_ID",
"<",
"50307",
"?",
"'$2a$'",
":",
"'$2y$'",
";",
"return",
"crypt",
"(",
"$",
"string",
",",
"$",
"prefix",
".",
"$",
"strength",
".",
"'$'",
".",
"$",
"salt",
".",
"'$'",
")",
";",
"}"
] | Hash string.
@param string $string
@return string | [
"Hash",
"string",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Hashing/BcryptHasher.php#L43-L55 |
cartalyst/sentry | src/Cartalyst/Sentry/Facades/Native/Sentry.php | Sentry.createSentry | public static function createSentry(
UserProviderInterface $userProvider = null,
GroupProviderInterface $groupProvider = null,
ThrottleProviderInterface $throttleProvider = null,
SessionInterface $session = null,
CookieInterface $cookie = null,
$ipAddress = null
)
{
$userProvider = $userProvider ?: new UserProvider(new NativeHasher);
return new BaseSentry(
$userProvider,
$groupProvider ?: new GroupProvider,
$throttleProvider ?: new ThrottleProvider($userProvider),
$session ?: new NativeSession,
$cookie ?: new NativeCookie,
$ipAddress ?: static::guessIpAddress()
);
} | php | public static function createSentry(
UserProviderInterface $userProvider = null,
GroupProviderInterface $groupProvider = null,
ThrottleProviderInterface $throttleProvider = null,
SessionInterface $session = null,
CookieInterface $cookie = null,
$ipAddress = null
)
{
$userProvider = $userProvider ?: new UserProvider(new NativeHasher);
return new BaseSentry(
$userProvider,
$groupProvider ?: new GroupProvider,
$throttleProvider ?: new ThrottleProvider($userProvider),
$session ?: new NativeSession,
$cookie ?: new NativeCookie,
$ipAddress ?: static::guessIpAddress()
);
} | [
"public",
"static",
"function",
"createSentry",
"(",
"UserProviderInterface",
"$",
"userProvider",
"=",
"null",
",",
"GroupProviderInterface",
"$",
"groupProvider",
"=",
"null",
",",
"ThrottleProviderInterface",
"$",
"throttleProvider",
"=",
"null",
",",
"SessionInterface",
"$",
"session",
"=",
"null",
",",
"CookieInterface",
"$",
"cookie",
"=",
"null",
",",
"$",
"ipAddress",
"=",
"null",
")",
"{",
"$",
"userProvider",
"=",
"$",
"userProvider",
"?",
":",
"new",
"UserProvider",
"(",
"new",
"NativeHasher",
")",
";",
"return",
"new",
"BaseSentry",
"(",
"$",
"userProvider",
",",
"$",
"groupProvider",
"?",
":",
"new",
"GroupProvider",
",",
"$",
"throttleProvider",
"?",
":",
"new",
"ThrottleProvider",
"(",
"$",
"userProvider",
")",
",",
"$",
"session",
"?",
":",
"new",
"NativeSession",
",",
"$",
"cookie",
"?",
":",
"new",
"NativeCookie",
",",
"$",
"ipAddress",
"?",
":",
"static",
"::",
"guessIpAddress",
"(",
")",
")",
";",
"}"
] | Creates a Sentry instance.
@param \Cartalyst\Sentry\Users\ProviderInterface $userProvider
@param \Cartalyst\Sentry\Groups\ProviderInterface $groupProvider
@param \Cartalyst\Sentry\Throttling\ProviderInterface $throttleProvider
@param \Cartalyst\Sentry\Sessions\SessionInterface $session
@param \Cartalyst\Sentry\Cookies\CookieInterface $cookie
@param string $ipAddress
@return \Cartalyst\Sentry\Sentry | [
"Creates",
"a",
"Sentry",
"instance",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/Native/Sentry.php#L51-L70 |
cartalyst/sentry | src/Cartalyst/Sentry/Facades/Native/Sentry.php | Sentry.setupDatabaseResolver | public static function setupDatabaseResolver(PDO $pdo, $driverName = null, $tablePrefix = '')
{
// If Eloquent doesn't exist, then we must assume they are using their own providers.
if (class_exists('Illuminate\Database\Eloquent\Model'))
{
if (is_null($driverName))
{
$driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
}
Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
}
} | php | public static function setupDatabaseResolver(PDO $pdo, $driverName = null, $tablePrefix = '')
{
// If Eloquent doesn't exist, then we must assume they are using their own providers.
if (class_exists('Illuminate\Database\Eloquent\Model'))
{
if (is_null($driverName))
{
$driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
}
Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
}
} | [
"public",
"static",
"function",
"setupDatabaseResolver",
"(",
"PDO",
"$",
"pdo",
",",
"$",
"driverName",
"=",
"null",
",",
"$",
"tablePrefix",
"=",
"''",
")",
"{",
"// If Eloquent doesn't exist, then we must assume they are using their own providers.",
"if",
"(",
"class_exists",
"(",
"'Illuminate\\Database\\Eloquent\\Model'",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"driverName",
")",
")",
"{",
"$",
"driverName",
"=",
"$",
"pdo",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
";",
"}",
"Eloquent",
"::",
"setConnectionResolver",
"(",
"new",
"ConnectionResolver",
"(",
"$",
"pdo",
",",
"$",
"driverName",
",",
"$",
"tablePrefix",
")",
")",
";",
"}",
"}"
] | Sets up the Eloquent Connection Resolver with the given PDO connection.
@param PDO $pdo
@param string $driverName
@param string $tablePrefix
@return void | [
"Sets",
"up",
"the",
"Eloquent",
"Connection",
"Resolver",
"with",
"the",
"given",
"PDO",
"connection",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/Native/Sentry.php#L80-L92 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.