Added methods to facades, increased admin powers...working on 'SET' program

Esse commit está contido em:
Felipe N. Moura
2012-06-29 02:16:05 -03:00
commit 74224da9c8
11 arquivos alterados com 158 adições e 30 exclusões
+1 -1
Ver Arquivo
@@ -20,7 +20,7 @@ abstract class Neuron {
public static function listLobes()
{
$list= Array();
$d = dir(\theos\ProjectFileManager::getLobesDir());
$d = dir(\theos\Gosh::getLobesDir());
while (false !== ($entry = $d->read()))
{
if($entry!= 'Neuron.php' && $entry[0] != '.')
Arquivo normal → Arquivo executável
Ver Arquivo
+4 -2
Ver Arquivo
@@ -156,8 +156,10 @@ class MindProject extends VersionManager{
project.name as name
from project_user,
project
where fk_user= ".$user."
and fk_project = pk_project
where fk_project = pk_project
";
if(!\API\User::isAdmin())
$hasProject.= " and fk_user= ".$user."
";
$data= $db->query($hasProject);
return $data;
+13 -5
Ver Arquivo
@@ -28,17 +28,25 @@ class MindSpeaker
{
$msg= Mind::message("L10N: Message $k does not exist", '[Fail]', false);
}
if(!is_array($args))
if(!is_array($args)){
$args= func_get_args();
array_shift($args);
array_shift($args); // ugly, isn't it?!
}
$parms= "";
if(sizeof($args)>2)
if(sizeof($args)>=1)
{
for($i=2; $i<sizeof($args); $i++)
for($i=0; $i<sizeof($args); $i++)
{
$parms.= ', "'.$args[$i].'"';
$parms.= ', "'.addslashes($args[$i]).'"';
}
$parms= '"'.$msg.'"'.$parms;
eval("\$print= sprintf(".$parms.");");
try{
eval("\$print= sprintf(".$parms.");");
}catch(Exception $exc){
// actually, do nothing...
}
}else{
$print= $msg;
}
+38 -3
Ver Arquivo
@@ -25,13 +25,14 @@ class MindUser
{
if(\in_array($attr, self::$adminValidAttrs) || $user)
{
if($_SESSION['pk_user'] != 1)
if(!\MindUser::isAdmin())
{
\Mind::write('mustBeAdmin');
return false;
}
}elseif(!\in_array($attr, self::$validAttrs))
return false;
}
if(!\in_array($attr, self::$validAttrs))
return false;
if($attr == 'pwd')
$value= self::hash($value);
@@ -39,9 +40,18 @@ class MindUser
$value= (is_string($value))? "'".$value."'": $value;
$db= self::getDBConn();
if($user && !is_numeric($user)){
$user= \MindUser::getUserByLogin($user);
if(!$user){
\MindSpeaker::write('auth_fail');
return false;
}
$user= $user['pk_user'];
}
$user= $user? $user: $_SESSION['pk_user'];
$qr= "UPDATE user set ".$attr."= ".$value.
"WHERE pk_user=".$user;
$db->execute($qr);
if($attr == 'pwd')
echo "\n";
@@ -72,6 +82,31 @@ class MindUser
return self::$dbConn;
}
/**
* Retrieves the user details based on the login.
*
* This method DEMANDS the current user to be admin.
*
* @param String $login
* @return UserObject Or false if not admin
*/
public static function getUserByLogin($login){
if(!\MindUser::isAdmin()){
\Mind::write('mustBeAdmin');
return false;
}
$db= self::getDBConn();
$user= false;
$usrs= $db->query("SELECT * from user where login = '".addslashes($login)."'");
foreach($usrs as $k=>$usr)
{
$user= $usr;
break;
}
return $user;
}
/**
* Retrieves the list of users.
* @param boolean $detailed
+8 -1
Ver Arquivo
@@ -5,5 +5,12 @@ which
whom
whose
well
we
too
also
also
I
you
they
he
she
it
+11 -1
Ver Arquivo
@@ -16,4 +16,14 @@ na
mínimo
máximo
minimo
maximo
maximo
eu
nós
nos
vocês
voces
eles
elas
ele
ela
tu
+2 -2
Ver Arquivo
@@ -1,6 +1,6 @@
/**
* This is a model, created to ilustrate how and where
* This is a model, created to illustrate how and where
* you can write your code
* You may have as many files as you want, altough, the
* You may have as many files as you want, although, the
* main.mnd is required
*/
+32 -9
Ver Arquivo
@@ -39,12 +39,35 @@
public function executableFunction()
{
if($this->whose == 'user')
$property= explode('.', $this->property);
if(sizeof($property) <= 1){
//\MindSpeaker::write('wrongParam', $this->property);
\MindSpeaker::write('wrongParam', true, "property", $this->property);
return false;
}
$entity= $property[0];
$property= $property[1];
if($entity == 'user'){
if($property == 'pwd' && !$this->extra){
$this->prompt('pwd', "What will be the password?", true);
if($this->value)
$this->extra= $this->value;
$this->value= $this->answers['pwd'];
}
if($this->extra){
\MindUser::set($property, $this->value, $this->extra);
}else{
\MindUser::set($property, $this->value);
}
}else{
\MindUser::set($property, $this->value);
}
/*if($this->whose == 'user')
{
$this->setUserData();
}else{
$this->setProjectData();
}
}*/
}
public function __construct()
@@ -61,15 +84,15 @@
Where status may be 'A' or 'I', and type may be 'A' or 'N'")
->setAction('executableFunction');
$this->addRequiredArgument('whose',
'Who will suffer the update',
Array('user', 'project'));
$this->addRequiredArgument('attribute',
'The attribute you will change');
$this->addRequiredArgument('property',
'Who will suffer the update. Use entity.property(eg. user.pwd'/*,
Array('user', 'project')*/);
/*$this->addRequiredArgument('attribute',
'The attribute you will change');*/
$this->addOptionalArgument('value',
'The value for that attribute(optional only for pwd)');
'The value for that attribute(optional for pwd)');
$this->addOptionalArgument('extra',
'An extra data about the defined attribute(the status or type for users or projects)');
'An extra data about the defined attribute(eg. if admin, the user to be changed)');
$this->init();
}
+48 -5
Ver Arquivo
@@ -33,7 +33,11 @@ EOT
'idioms',
'plugins',
'ddl',
'source',
'info',
'data',
'props',
'properties',
'lobes');
asort($opts);
$this->addRequiredArgument('what',
@@ -67,6 +71,35 @@ EOT
$this->printMatrix($projectList);
}
break;
case 'data':
case 'props':
case 'properties':
//var_dump($_MIND);
$p= \Mind::$currentProject;
if($p){
if($_REQ['env']=='http')
echo JSON_encode($p);
else{
foreach($p as $k=>$v){
if($k == 'database_user' || $k == 'database_pwd'){
if(!\API\User::isAdmin())
continue;
}
echo " ".str_pad($k, 16, " ").": ".$v."\n";
}
}
}else{
\MindSpeaker::write("currentProjectRequired");
}
break;
case 'source':
$p= \Mind::$currentProject;
if($p){
var_dump(\MindProject::loadSource());
}else{
\MindSpeaker::write("currentProjectRequired");
}
break;
case 'users':
$users= $this->loadUsersList();
$userList= Array();
@@ -151,13 +184,23 @@ EOT
MindPlugin::listPlugins($_REQ['env']!='http');
break;
case 'idioms':
Mind::getIdiomsList();
if($_REQ['env']=='http'){
echo JSON_encode(Mind::getIdiomsList());
}else{
echo " ".implode(', ', Mind::getIdiomsList())."\n";
}
break;
case 'ddl':
$ddls= $this->detailed? \API\Get::DecoratedDDL():
\API\Get::DDL();
foreach($ddls as $ddlCommand)
echo $ddlCommand;
$p= \Mind::$currentProject;
if($p){
$ddls= $this->detailed? \API\Get::DecoratedDDL():
\API\Get::DDL();
foreach($ddls as $ddlCommand){
echo $ddlCommand;
}
}else{
\MindSpeaker::write("currentProjectRequired");
}
break;
case 'lobes':
echo implode("\n", \Lobe\Neuron::listLobes());
+1 -1
Ver Arquivo
@@ -29,7 +29,7 @@
$this->setCommandName('who')
->setDescription("Show information about the currently logged used")
->setRestrict(true)
->setHelp("Show information about the currently logged used")
->setHelp("Show information about the currently logged used.\n used as $ who am i?")
->setAction(function($class){
$class->executableFunction();
});