Пример #1
0
 protected function setUp()
 {
     parent::setUp();
     foreach (array_keys($_POST) as $key) {
         unset($_POST[$key]);
     }
     Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_NonPersistent());
     $this->clean();
     $front = Zend_Controller_Front::getInstance();
     $router = new Zend_Controller_Router_Rewrite();
     $routes_config = new USVN_Config_Ini(USVN_ROUTES_CONFIG_FILE, USVN_CONFIG_SECTION);
     $router->addConfig($routes_config, 'routes');
     $front->setRouter($router);
     $table = new USVN_Db_Table_Users();
     $this->user = $table->fetchNew();
     $this->user->setFromArray(array('users_login' => 'john', 'users_password' => 'pinocchio'));
     $this->user->save();
     $this->admin_user = $table->fetchNew();
     $this->admin_user->setFromArray(array('users_login' => 'god', 'users_password' => 'ingodwetrust', 'users_is_admin' => true));
     $this->admin_user->save();
     $authAdapter = new USVN_Auth_Adapter_Database('john', 'pinocchio');
     Zend_Auth::getInstance()->authenticate($authAdapter);
     $front->setControllerDirectory(USVN_CONTROLLERS_DIR);
     $this->request = new USVN_Controller_Request_Http();
     $front->setRequest($this->request);
     $this->response = new Zend_Controller_Response_Cli();
     $front->setResponse($this->response);
     $router->addRoute('default', new Zend_Controller_Router_Route_Module(array(), $front->getDispatcher(), $front->getRequest()));
 }
Пример #2
0
 /**
  * Pre-dispatch routines
  *
  * Called before action method. If using class with
  * {@link Zend_Controller_Front}, it may modify the
  * {@link $_request Request object} and reset its dispatched flag in order
  * to skip processing the current action.
  *
  * @return void
  */
 public function preDispatch()
 {
     parent::preDispatch();
     $project = $this->getRequest()->getParam('project');
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchRow(array("projects_name = ?" => $project));
     /* @var $project USVN_Db_Table_Row_Project */
     if ($project === null) {
         $this->_redirect("/");
     }
     $this->_project = $project;
     $table = new USVN_Db_Table_Users();
     $user = $table->findBySecret($_GET['secret']);
     if ($user) {
         $groups = $user->findManyToManyRowset("USVN_Db_Table_Groups", "USVN_Db_Table_UsersToGroups");
         $find = false;
         foreach ($groups as $group) {
             if ($project->groupIsMember($group)) {
                 $find = true;
                 break;
             }
         }
         if (!$find && !$this->isAdmin()) {
             $this->_redirect("/");
         }
     } else {
         $this->_redirect("/");
     }
 }
Пример #3
0
 public function setUp()
 {
     parent::setUp();
     $table = new USVN_Db_Table_Users();
     $this->_user = $table->fetchNew();
     $this->_user->setFromArray(array('users_login' => 'test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $this->_user->save();
 }
Пример #4
0
 protected function getUser()
 {
     if ($this->user === null) {
         $identity = Zend_Auth::getInstance()->getIdentity();
         $table = new USVN_Db_Table_Users();
         $this->user = $table->fetchRow(array('users_login = ?' => $identity['username']));
     }
     return $this->user;
 }
Пример #5
0
 /**
  * Create a new user
  *
  * @param array User attributes
  * @param boolean true : create a homonym group's
  * @param array|null Group's id which this user must be affected
  * @return USVN_User
  */
 public static function create($data, $createGroup, $groups = null)
 {
     $user = new USVN_User();
     $table = new USVN_Db_Table_Users();
     $user->user = $table->createRow($data);
     $user->createGroup = $createGroup;
     $user->groups = $groups;
     return $user;
 }
Пример #6
0
 /**
  * Default action for every controller.
  *
  */
 public function indexAction()
 {
     $projects = new USVN_Db_Table_Projects();
     $this->view->projects = $projects->fetchAllAssignedTo($this->getRequest()->getParam('user'));
     $identity = Zend_Auth::getInstance()->getIdentity();
     $user_table = new USVN_Db_Table_Users();
     $user = $user_table->fetchRow(array('users_login = ?' => $identity['username']));
     $this->view->groups = $user->listGroups();
     $this->view->maxlen = 12;
 }
Пример #7
0
 public function setUp()
 {
     parent::setUp();
     $table = new USVN_Db_Table_Users();
     $this->_user = $table->fetchNew();
     $this->_user->setFromArray(array('users_login' => 'test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $this->_user->save();
     $this->_projectid1 = USVN_Project::createProject(array('projects_name' => "project1"), "test", true, false, false, true)->id;
     $this->_projectid2 = USVN_Project::createProject(array('projects_name' => "project2"), "test", true, false, false, true)->id;
     $group_table = new USVN_Db_Table_Groups();
     $group = $group_table->fetchNew();
     $group->setFromArray(array("groups_name" => "toto"));
     $this->_groupid1 = $group->save();
     $group_table = new USVN_Db_Table_Groups();
     $group = $group_table->fetchNew();
     $group->setFromArray(array("groups_name" => "titi"));
     $this->_groupid2 = $group->save();
 }
Пример #8
0
 /**
  * Create a project
  *
  * @param array Fields data
  * @param string The creating user
  * @param bool Create a group for the project
  * @param bool Add user into group
  * @param bool Add user as admin for the project
  * @param bool Create SVN standard directories
  * @return USVN_Db_Table_Row_Project
  */
 public static function createProject(array $data, $login, $create_group, $add_user_to_group, $create_admin, $create_svn_directories)
 {
     //We need check if admin exist before create project because we can't go back
     $user_table = new USVN_Db_Table_Users();
     $user = $user_table->fetchRow(array('users_login = ?' => $login));
     if ($user === null) {
         throw new USVN_Exception(T_('Login %s not found'), $login);
     }
     $groups = new USVN_Db_Table_Groups();
     if ($create_group) {
         $group = $groups->fetchRow(array('groups_name = ?' => $data['projects_name']));
         if ($group !== null) {
             throw new USVN_Exception(T_("Group %s already exists."), $data['projects_name']);
         }
     }
     try {
         $table = new USVN_Db_Table_Projects();
         $table->getAdapter()->beginTransaction();
         $project = $table->createRow($data);
         $project->save();
         USVN_Project::createProjectSVN($data['projects_name'], $create_svn_directories);
         if ($create_group) {
             $group = $groups->createRow();
             $group->description = sprintf(T_("Autocreated group for project %s"), $data['projects_name']);
             $group->name = $data['projects_name'];
             $group->save();
             $project->addGroup($group);
             USVN_Project::ApplyFileRights($project, $group, $create_svn_directories);
         }
         if ($create_group && $add_user_to_group) {
             $group->addUser($user);
             $group->promoteUser($user);
         }
         if ($create_admin) {
             $project->addUser($user);
         }
     } catch (Exception $e) {
         $table->getAdapter()->rollBack();
         throw $e;
     }
     $table->getAdapter()->commit();
     return $project;
 }
Пример #9
0
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $result = array();
     $result['isValid'] = false;
     $result['identity'] = array();
     $result['identity']['username'] = $this->_login;
     $result['messages'] = array();
     $table = new USVN_Db_Table_Users();
     $user = $table->fetchRow(array('users_login = ?' => $this->_login));
     if ($user === NULL) {
         $result['messages'][] = sprintf(T_('Login %s not found'), $this->_login);
         return new Zend_Auth_Result($result['isValid'], $result['identity'], $result['messages']);
     }
     if (!USVN_Crypt::checkPassword($this->_password, $user->password)) {
         $result['messages'][] = T_('Incorrect password');
         return new Zend_Auth_Result($result['isValid'], $result['identity'], $result['messages']);
     }
     $result['isValid'] = true;
     return new Zend_Auth_Result($result['isValid'], $result['identity'], $result['messages']);
 }
Пример #10
0
 private function loadIntoDb()
 {
     $users = new USVN_Db_Table_Users();
     $users->getAdapter()->beginTransaction();
     foreach (array_keys($this->_users_password) as $user) {
         $data['users_login'] = $user;
         $data['users_password'] = $this->_users_password[$user];
         $where = $users->getAdapter()->quoteInto('users_login = ?', $user);
         $user_row = $users->fetchRow($where);
         try {
             if ($user_row === null) {
                 $users->insert($data);
             } else {
                 $users->update($data, $where);
             }
         } catch (Exception $e) {
             $users->getAdapter()->rollBack();
             throw new USVN_Exception(T_("Can't add users %s. Import cancel."), $user);
         }
     }
     $users->getAdapter()->commit();
 }
Пример #11
0
 public function updateAction()
 {
     $data = $this->getGroupData($_POST);
     if (empty($data)) {
         $this->_redirect("/admin/group/");
     }
     $group_name = str_replace(USVN_URL_SEP, '/', $this->getRequest()->getParam('name'));
     $table = new USVN_Db_Table_Groups();
     $group = $table->fetchRow(array("groups_name = ?" => $group_name));
     if ($group === null) {
         throw new USVN_Exception(T_("Invalid group %s."), $group_name);
     }
     $group->setFromArray($data);
     try {
         $group->save();
         $this->_redirect("/admin/group/");
     } catch (USVN_Exception $e) {
         $this->view->group = $group;
         $this->view->message = $e->getMessage();
         $table = new USVN_Db_Table_Users();
         $this->view->users = $table->fetchAll(null, "users_login");
         $this->render('edit');
     }
 }
Пример #12
0
 /**
  * Check if an user is in the project
  *
  * @param USVN_Db_Table_Row_User or string User
  * @return boolean
  */
 public function userIsAdmin($user)
 {
     if (!is_object($user)) {
         $table = new USVN_Db_Table_Users();
         $user = $table->fetchRow(array('users_login = ?' => $user));
     }
     $table = new USVN_Db_Table_UsersToProjects();
     $res = $table->fetchRow(array("users_id = ?" => $user->id, "projects_id = ?" => $this->id));
     if ($res === null) {
         return false;
     }
     return true;
 }
Пример #13
0
 /**
  * This method will write create an admin
  *
  * Throw an exception in case of problems.
  *
  * @param string Path to the USVN config file
  * @param string Admin login
  * @param string Admin password
  * @param string Admin first name
  * @param string Admin last name
  * @param string Admin email
  * @throw USVN_Exception
  */
 public static function installAdmin($config_file, $login, $password, $firstname, $lastname, $email)
 {
     if (empty($password)) {
         throw new USVN_Exception(T_('Password empty'));
     }
     $userTable = new USVN_Db_Table_Users();
     $user = $userTable->createRow();
     $user->login = $login;
     $user->password = $password;
     $user->firstname = $firstname;
     $user->lastname = $lastname;
     $user->email = $email;
     $user->is_admin = true;
     $user->secret_id = md5(time() . mt_rand());
     $user->save();
 }
Пример #14
0
 public function addleadergroupAction()
 {
     if ($this->_group->isLeaderOrAdmin($this->view->user) == 1) {
         $request = $this->getRequest();
         /* @var $request USVN_Controller_Request_Http */
         $table = new USVN_Db_Table_Groups();
         $group = $table->fetchRow(array("groups_name = ?" => str_replace(USVN_URL_SEP, '/', $request->getParam('group'))));
         /* @var $group USVN_Db_Table_Row_Group */
         try {
             $table = new USVN_Db_Table_Users();
             if ($request->getParam('ap', "") != "") {
                 $user = $table->fetchRow(array("users_login = ?" => $request->getParam('ap')));
                 if ($user === null) {
                     throw new USVN_Exception(sprintf(T_("Unknown user %s"), $request->getParam('ap')));
                 }
                 if (!$group->hasUser($user)) {
                     $group->addUser($user, true);
                 } else {
                     $group->updateLeaderUser($user, 1);
                 }
             }
             if ($request->getParam('deleteid', 0) != 0) {
                 $user = $table->fetchRow(array("users_id = ?" => $request->getParam('deleteid')));
                 if ($user === null) {
                     throw new USVN_Exception(sprintf(T_("Unknown user %s"), $request->getParam('deleteid')));
                 }
                 if ($group->hasUser($user)) {
                     $group->deleteUser($user);
                 }
             }
         } catch (Exception $e) {
             $this->view->message = $e->getMessage();
         }
         $this->view->group = $group;
     } else {
         throw new USVN_Exception(sprintf(T_("Access denied.")));
     }
 }
Пример #15
0
 /**
  * Realiza a autenticação
  * 
  * @todo Create an abstract authenticated method to use around all project
  */
 private function _auth()
 {
     // Get auth informations
     $username = (string) $this->_xml->auth->username;
     $password = (string) $this->_xml->auth->password;
     $auth = Zend_Auth::getInstance();
     // Find the authentication adapter from the config file
     $config = new USVN_Config_Ini(USVN_CONFIG_FILE, 'general');
     $authAdapterMethod = "database";
     if (empty($config->alwaysUseDatabaseForLogin)) {
         $config->alwaysUseDatabaseForLogin = '******';
     }
     if ($config->alwaysUseDatabaseForLogin != $username && $config->authAdapterMethod) {
         $authAdapterMethod = strtolower($config->authAdapterMethod);
     }
     $authAdapterClass = 'USVN_Auth_Adapter_' . ucfirst($authAdapterMethod);
     if (!class_exists($authAdapterClass)) {
         throw new USVN_Exception(T_('The authentication adapter method set in the config file is not valid.'));
     }
     // Retrieve auth-options, if any, from the config file
     $authOptions = null;
     if ($config->{$authAdapterMethod} && $config->{$authAdapterMethod}->options) {
         $authOptions = $config->{$authAdapterMethod}->options->toArray();
     }
     // Set up the authentication adapter
     $authAdapter = new $authAdapterClass($username, $password, $authOptions);
     // Attempt authentication, saving the result
     $result = $auth->authenticate($authAdapter);
     if (!$result->isValid()) {
         return FALSE;
     } else {
         $identity = $auth->getStorage()->read();
         $table = new USVN_Db_Table_Users();
         $this->_userRow = $table->fetchRow(array("users_login = ?" => $username));
         /**
          * Workaround for LDAP.
          * We need the identity to match the database,
          * but LDAP identities can be in the following form:
          * uid=username,ou=people,dc=foo,dc=com
          * We need to simply keep username, as passed to the constructor method.
          *
          * Using in_array(..., get_class_methods()) instead of method_exists() or is_callable(),
          * because none of them really check if the method is actually callable (ie. not protected/private).
          * See comments @ http://us.php.net/manual/en/function.method-exists.php
          */
         if (in_array("getIdentityUserName", get_class_methods($authAdapter))) {
             // Because USVN uses an array (...) when Zend uses a string
             if (!is_array($identity)) {
                 $identity = array();
             }
             $username = $authAdapter->getIdentityUserName();
             $auth->getStorage()->write($identity);
         }
         /**
          * Another workaround for LDAP.
          * As long as we don't provide real
          * and full LDAP support (add, remove, etc.), if a user managed to
          * log in with LDAP, or any other non-DB support, we need to add
          * the user in the database :)
          */
         if ($config->{$authAdapterMethod}->createUserInDBOnLogin) {
             $table = new USVN_Db_Table_Users();
             $this->_userRow = $table->fetchRow(array("users_login = ?" => $username));
         }
         return TRUE;
     }
 }
Пример #16
0
 /**
  * Genere un tableau d'utilisateur
  *
  * @param int $n
  */
 function _generateUsers($n)
 {
     $table = new USVN_Db_Table_Users();
     $ret = array();
     for ($i = 1; $i <= $n; $i++) {
         $ret[$i - 1] = $table->fetchNew();
         $ret[$i - 1]->login = "******";
         $ret[$i - 1]->password = "******";
         $ret[$i - 1]->save();
     }
     return $ret;
 }
Пример #17
0
 public function adduserAction()
 {
     $this->requireAdmin();
     $table = new USVN_Db_Table_Users();
     $user = $table->fetchRow(array("users_login = ?" => $this->getRequest()->getParam('users_login')));
     if ($user !== null) {
         try {
             $this->_project->addUser($user);
         } catch (Exception $e) {
         }
     }
     $this->_redirect("/project/" . str_replace('/', USVN_URL_SEP, $this->_project->name) . "/");
 }
Пример #18
0
 public function testfetchAllAssignedTwoUserInGroup()
 {
     $table_user = new USVN_Db_Table_Users();
     $user = $table_user->fetchNew();
     $user->setFromArray(array('users_login' => 'test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $user->save();
     $user2 = $table_user->fetchNew();
     $user2->setFromArray(array('users_login' => 'test2', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $user2->save();
     $table_project = new USVN_Db_Table_Projects();
     $project = $table_project->fetchNew();
     $project->setFromArray(array('projects_name' => 'InsertProjectOk', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project->save();
     $project2 = $table_project->fetchNew();
     $project2->setFromArray(array('projects_name' => 'Project2', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project2->save();
     $group_table = new USVN_Db_Table_Groups();
     $group_table->insert(array("groups_id" => 2, "groups_name" => "toto"));
     $group = $group_table->find(2)->current();
     $group_table = new USVN_Db_Table_Groups();
     $group_table->insert(array("groups_id" => 3, "groups_name" => "titi"));
     $group = $group_table->find(3)->current();
     $project->addGroup($group);
     $this->assertEquals(count($table_project->fetchAllAssignedTo($user)), 0);
     $group->addUser($user);
     $group->addUser($user2);
     $this->assertEquals(count($table_project->fetchAllAssignedTo($user)), 1);
 }
Пример #19
0
 public function completionAction()
 {
     echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
     $table = "<table width=100%>";
     $nb = 0;
     echo "<files>\n";
     if ($_GET['idx'] == 1) {
         if (isset($_GET['grp']) && $_GET['grp'] != "") {
             $table_groups = new USVN_Db_Table_Groups();
             $res_groups = $table_groups->findByGroupsName($_GET['grp']);
             $table_userstogroups = new USVN_Db_Table_UsersToGroups();
             $res_usersspe = $table_userstogroups->findByGroupId($res_groups->groups_id);
         } else {
             if (isset($_GET['prj']) && $_GET['prj'] != "") {
                 $table_project = new USVN_Db_Table_Projects();
                 $res_project = $table_project->findByName($_GET['prj']);
                 $table_userstoprojects = new USVN_Db_Table_UsersToProjects();
                 $res_usersspe = $table_userstoprojects->findByProjectId($res_project->projects_id);
             }
         }
         $table_users = new USVN_Db_Table_Users();
         $res_users = $table_users->allUsersLike($_GET['txt']);
         foreach ($res_users as $user) {
             $find = false;
             foreach ($res_usersspe as $tmpuser) {
                 if ($tmpuser->users_id == $user->users_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='user" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion\")'>";
                 $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     if ($_GET['idx'] == 2) {
         $table_project = new USVN_Db_Table_Projects();
         $res_project = $table_project->findByName($_GET['prj']);
         $table_groupstoprojects = new USVN_Db_Table_GroupsToProjects();
         $res_groupstoprojects = $table_groupstoprojects->findByProjectId($res_project->projects_id);
         $table_groups = new USVN_Db_Table_Groups();
         $res_groups = $table_groups->allGroupsLike($_GET['txt']);
         foreach ($res_groups as $group) {
             $find = false;
             foreach ($res_groupstoprojects as $tmpgrp) {
                 if ($tmpgrp->groups_id == $group->groups_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='grp" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $group->groups_name . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion1\")'>";
                 $table .= "<label id='lgrp" . $nb . "'>" . $group->groups_name . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     if ($_GET['idx'] == 3) {
         $table_users = new USVN_Db_Table_Users();
         $res_users = $table_users->allUsersLike($_GET['txt']);
         $table_groups = new USVN_Db_Table_Groups();
         $res_groups = $table_groups->findByGroupsName($_GET['grp']);
         $res_usersspe = $table_users->allLeader($res_groups->groups_id);
         foreach ($res_users as $user) {
             $find = false;
             foreach ($res_usersspe as $tmpuser) {
                 if ($tmpuser->users_id == $user->users_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='user" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completionleader\")'>";
                 $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     if ($_GET['idx'] == 4) {
         $table_groups = new USVN_Db_Table_Groups();
         $res_groups = $table_groups->findByGroupsName($_GET['grp']);
         $table_userstogroups = new USVN_Db_Table_UsersToGroups();
         $res_usersspe = $table_userstogroups->noleaderFindByGroupId($res_groups->groups_id);
         $table_users = new USVN_Db_Table_Users();
         $res_users = $table_users->allUsersLike($_GET['txt']);
         foreach ($res_users as $user) {
             $find = false;
             foreach ($res_usersspe as $tmpuser) {
                 if ($tmpuser->users_id == $user->users_id) {
                     $find = true;
                 }
             }
             if ($find == false) {
                 $table .= "<tr id='user" . $nb . "' class='comp'>";
                 $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion\")'>";
                 $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>";
                 $table .= "</td></tr>";
                 $nb++;
             }
         }
     }
     $table .= "</table>";
     echo "<nbcomp>" . $nb . "</nbcomp>\n";
     echo "<tableau><![CDATA[" . $table . "]]></tableau>\n";
     echo "</files>\n";
 }
Пример #20
0
 public function deleteAction()
 {
     $table = new USVN_Db_Table_Users();
     $user = $table->fetchRow(array('users_login = ?' => $this->getRequest()->getParam('login')));
     if ($user === null) {
         throw new USVN_Exception(T_("Invalid user %s."), $this->getRequest()->getParam('login'));
     }
     if ($user->login == $this->getRequest()->getParam('user')->login) {
         throw new USVN_Exception(T_("You can't delete yourself."));
     }
     $user->delete();
     $this->_redirect("/admin/user/");
 }
Пример #21
0
 public function updateAction()
 {
     $data = $this->getProjectData($_POST);
     if (empty($data)) {
         $this->_redirect("/admin/project/new");
     }
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchRow(array("projects_name = ?" => str_replace(USVN_URL_SEP, '/', $this->getRequest()->getParam('name'))));
     if ($project === null) {
         $this->_redirect("/admin/project/");
     }
     $identity = Zend_Auth::getInstance()->getIdentity();
     $user_table = new USVN_Db_Table_Users();
     $users = $user_table->fetchRow(array('users_login = ?' => $identity['username']));
     if (isset($_POST['admin'])) {
         $table->AddUserToProject($users, $project);
     } else {
         $table->DeleteUserToProject($users, $project);
     }
     $project->setFromArray($data);
     try {
         $project->save();
         $this->_redirect("/admin/project/");
     } catch (Exception $e) {
         $this->view->project = $project;
         $this->view->message = nl2br($e->getMessage());
         $this->render('edit');
     }
 }
Пример #22
0
 public function allLeader($group_id, $type)
 {
     $type = $type ? 1 : 0;
     $user_groups = new USVN_Db_Table_UsersToGroups();
     $links = $user_groups->fetchAll(array('groups_id = ?' => $group_id, '(CASE WHEN is_leader THEN 1 ELSE 0 END) = ?' => $type));
     if (count($links) === 0) {
         return array();
     }
     $users = new USVN_Db_Table_Users();
     $leaders = array();
     foreach ($links as $link) {
         array_push($leaders, $link->users_id);
     }
     return $users->find($leaders);
 }
Пример #23
0
 /**
  * Pre-dispatch routines
  *
  * Called before action method. If using class with
  * {@link Zend_Controller_Front}, it may modify the
  * {@link $_request Request object} and reset its dispatched flag in order
  * to skip processing the current action.
  *
  * @return void
  */
 public function preDispatch()
 {
     $request = $this->getRequest();
     $controller = $request->getControllerName();
     $dir = realpath(USVN_VIEWS_DIR . '/' . $controller);
     if ($dir === false || !is_dir($dir)) {
         throw new Zend_Controller_Exception('Controller\'s views directory not found. Controller is $controller.');
     }
     $this->view->setScriptPath($dir);
     $this->view->assign('project', str_replace(USVN_URL_SEP, '/', $request->getParam('project')));
     $this->view->assign('controller', $request->getParam('controller'));
     $area = $request->getParam('area');
     if ($area == '__NONE__') {
         $area = $request->getParam('controller');
     } elseif (in_array($area, array('project', 'group'))) {
         $area = 'index';
     }
     $this->view->assign('area', $area);
     $this->view->assign('action', $request->getParam('action'));
     $identity = Zend_Auth::getInstance()->getIdentity();
     if ($identity === null) {
         /*
          * That should be better than magic strings. All controller that 
          * needs to work without login like "login" or "rss" just need to
          * define a constant and set it to 'true'
          */
         if (defined(get_class($this) . '::IgnoreLogin') !== true || constant(get_class($this) . '::IgnoreLogin') !== true) {
             $currentUrl = $request->getRequestUri();
             $baseUrl = rtrim($this->getFrontController()->getBaseUrl(), '/');
             if (strncmp($baseUrl, $currentUrl, strlen($baseUrl)) == 0) {
                 $currentUrl = substr($currentUrl, strlen($baseUrl));
             }
             $this->_redirect('/login/' . ltrim($currentUrl, '/'));
         }
         return;
     }
     $table = new USVN_Db_Table_Users();
     $user = $table->fetchRow(array("users_login = ?" => $identity['username']));
     $this->view->isLogged = true;
     if ($user === null && (defined(get_class($this) . '::IgnoreLogin') !== true || constant(get_class($this) . '::IgnoreLogin') !== true)) {
         $this->_redirect("/logout/");
         $this->view->isLogged = false;
     }
     if (isset($user)) {
         $this->view->isAdmin = $user->is_admin;
         $this->view->login = $user->login;
     }
     $request->setParam('user', $user);
 }
Пример #24
0
 public function testImportHtpasswd()
 {
     file_put_contents('../tests/htpasswd', "noplay:BD3ZmTBhHmWJs\nstem:1YApoa5EK/WFs");
     $message = USVN_ConsoleUtils::runCmdCaptureMessage("php tools/usvn-import-htpasswd.php ../tests/test.ini ../tests/htpasswd", $return);
     $this->assertEquals(0, $return, $message);
     echo $message;
     chdir($this->_path);
     //Else SQLite doesn't work
     $userTable = new USVN_Db_Table_Users();
     $user = $userTable->fetchRow(array('users_login = ?' => "noplay"));
     $this->assertNotNull($user);
     $this->assertEquals("BD3ZmTBhHmWJs", $user->password);
 }
Пример #25
0
 public function testImportSVNRepositoriesOk()
 {
     try {
         $table = new USVN_Db_Table_Users();
         $obj = $table->fetchNew();
         $obj->setFromArray(array('users_login' => 'user_test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
         $obj->save();
     } catch (USVN_Exception $e) {
         print $e->getMessage() . "\n";
         $this->fail();
     }
     $path = 'tests/tmp/svn/test/';
     mkdir($path);
     USVN_SVNUtils::createSvn($path . 'test');
     USVN_SVNUtils::createSvn($path . 'test2');
     mkdir($path . 'test3');
     USVN_SVNUtils::createSvn($path . 'test3/test3');
     $options = array('recursive' => true, 'login' => 'user_test');
     $imp = new USVN_ImportSVNRepositories();
     $results = $imp->lookAfterSVNRepositoriesToImport($path, $options);
     if (count($results) != 3) {
         $this->fail();
     }
     $imp->addSVNRepositoriesToImport($results, $options);
     try {
         $imp->importSVNRepositories();
     } catch (USVN_Exception $e) {
         print $e->getMessage() . "\n";
         $this->fail();
     }
     USVN_DirectoryUtils::removeDirectory($path);
 }
Пример #26
0
 protected function _doLogin()
 {
     // Get a reference to the Singleton instance of Zend_Auth
     $auth = Zend_Auth::getInstance();
     // Find the authentication adapter from the config file
     $config = new USVN_Config_Ini(USVN_CONFIG_FILE, 'general');
     $authAdapterMethod = "database";
     // Default method is databse
     if (empty($config->alwaysUseDatabaseForLogin)) {
         $config->alwaysUseDatabaseForLogin = '******';
     }
     if ($config->alwaysUseDatabaseForLogin != $_POST['login'] && $config->authAdapterMethod) {
         $authAdapterMethod = strtolower($config->authAdapterMethod);
     }
     $authAdapterClass = 'USVN_Auth_Adapter_' . ucfirst($authAdapterMethod);
     if (!class_exists($authAdapterClass)) {
         throw new USVN_Exception(T_('The authentication adapter method set in the config file is not valid.'));
     }
     // Retrieve auth-options, if any, from the config file
     $authOptions = null;
     if ($config->{$authAdapterMethod} && $config->{$authAdapterMethod}->options) {
         $authOptions = $config->{$authAdapterMethod}->options->toArray();
     }
     // Set up the authentication adapter
     $authAdapter = new $authAdapterClass($_POST['login'], $_POST['password'], $authOptions);
     // Attempt authentication, saving the result
     $result = $auth->authenticate($authAdapter);
     if (!$result->isValid()) {
         $this->view->login = $_POST['login'];
         $this->view->messages = $result->getMessages();
         $this->render('errors');
         $this->render('login');
     } else {
         $identity = $auth->getStorage()->read();
         /**
          * Workaround for LDAP. We need the identity to match the database,
          * but LDAP identities can be in the following form:
          * uid=username,ou=people,dc=foo,dc=com
          * We need to simply keep username, as passed to the constructor method.
          *
          * Using in_array(..., get_class_methods()) instead of method_exists() or is_callable(),
          * because none of them really check if the method is actually callable (ie. not protected/private).
          * See comments @ http://us.php.net/manual/en/function.method-exists.php
          */
         if (in_array("getIdentityUserName", get_class_methods($authAdapter))) {
             // Because USVN uses an array (...) when Zend uses a string
             if (!is_array($identity)) {
                 $identity = array();
             }
             $identity['username'] = $authAdapter->getIdentityUserName();
             $auth->getStorage()->write($identity);
         }
         /**
          * Another workaround for LDAP. As long as we don't provide real
          * and full LDAP support (add, remove, etc.), if a user managed to
          * log in with LDAP, or any other non-DB support, we need to add
          * the user in the database :)
          */
         if ($config->{$authAdapterMethod}->createUserInDBOnLogin) {
             $table = new USVN_Db_Table_Users();
             $user = $table->fetchRow(array("users_login = ?" => $identity['username']));
             // Not very sure if we need to ask the authAdapter if we need to
             // create user in DB, as it is redundant with the config...
             if (!$user && in_array("createUserInDB", get_class_methods($authAdapter)) && $authAdapter->createUserInDB()) {
                 $data = array('users_login' => $identity['username'], 'users_is_admin' => 0, 'users_password' => $_POST['password']);
                 /* Request firstname, lastname, and username if possible (e.g., can be read from LDAP) */
                 $authAdapterClassMethods = get_class_methods($authAdapter);
                 if (in_array('getFirstName', $authAdapterClassMethods)) {
                     $data['users_firstname'] = $authAdapter->getFirstName();
                 }
                 if (in_array('getLastName', $authAdapterClassMethods)) {
                     $data['users_lastname'] = $authAdapter->getLastName();
                 }
                 if (in_array('getEmail', $authAdapterClassMethods)) {
                     $data['users_email'] = $authAdapter->getEmail();
                 }
                 $user = USVN_User::create($data, $config->{$authAdapterMethod}->createGroupForUserInDB, null);
                 $user->save();
             }
         }
         $this->_redirect('/' . $this->getRequest()->getParam('path'));
         exit(0);
     }
 }
Пример #27
0
 public function test_edit()
 {
     $users = new USVN_Db_Table_Users();
     $user = $users->find(3)->current();
     $this->request->setParam('login', 'Indochine');
     $this->runAction('edit');
     $this->assertContains('Indochine', $this->getBody(), $this->getBody());
 }
Пример #28
0
 /**
  * Pre-dispatch routines
  *
  * Called before action method. If using class with
  * {@link Zend_Controller_Front}, it may modify the
  * {@link $_request Request object} and reset its dispatched flag in order
  * to skip processing the current action.
  *
  * @return void
  */
 public function preDispatch()
 {
     $request = $this->getRequest();
     $controller = $request->getControllerName();
     $dir = realpath(USVN_VIEWS_DIR . '/' . $controller);
     if ($dir === false || !is_dir($dir)) {
         throw new Zend_Controller_Exception('Controller\'s views directory not found. Controller is $controller.');
     }
     $this->view->setScriptPath($dir);
     $this->view->assign('project', str_replace(USVN_URL_SEP, '/', $request->getParam('project')));
     $this->view->assign('controller', $request->getParam('controller'));
     $area = $request->getParam('area');
     if ($area == '__NONE__') {
         $area = $request->getParam('controller');
     } elseif (in_array($area, array('project', 'group'))) {
         $area = 'index';
     }
     $this->view->assign('area', $area);
     $this->view->assign('action', $request->getParam('action'));
     $identity = Zend_Auth::getInstance()->getIdentity();
     if ($identity === null) {
         // TODO:
         // It is ugly to have "magic strings" instead of an array saying
         // which controllers do not need to be logged in...
         if ($controller != "login" && $controller != "rss") {
             $currentUrl = $request->getRequestUri();
             $baseUrl = rtrim($this->getFrontController()->getBaseUrl(), '/');
             if (strncmp($baseUrl, $currentUrl, strlen($baseUrl)) == 0) {
                 $currentUrl = substr($currentUrl, strlen($baseUrl));
             }
             $this->_redirect('/login/' . ltrim($currentUrl, '/'));
         }
         return;
     }
     $table = new USVN_Db_Table_Users();
     $user = $table->fetchRow(array("users_login = ?" => $identity['username']));
     $this->view->isLogged = true;
     if ($user === null && $controller != "login" && $controller != "rss") {
         $this->_redirect("/logout/");
         $this->view->isLogged = false;
     }
     if (isset($user)) {
         $this->view->isAdmin = $user->is_admin;
         $this->view->login = $user->login;
     }
     $request->setParam('user', $user);
 }
Пример #29
0
 public function test_updateUser()
 {
     file_put_contents("tests/htpasswd", "noplay:lQeKGl9L6sH3M\nbibi:9bhJwNgJ00I6E");
     $import = new USVN_ImportHtpasswd("tests/htpasswd");
     file_put_contents("tests/htpasswd", "noplay:BD3ZmTBhHmWJs\nbibi:9bhJwNgJ00I6E\njames:hkjfhdjk");
     $import = new USVN_ImportHtpasswd("tests/htpasswd");
     $userTable = new USVN_Db_Table_Users();
     $user = $userTable->fetchRow(array('users_login = ?' => "james"));
     $this->assertNotNull($user);
     $user = $userTable->fetchRow(array('users_login = ?' => "bibi"));
     $this->assertNotNull($user);
     $this->assertEquals("9bhJwNgJ00I6E", $user->password);
     $user = $userTable->fetchRow(array('users_login = ?' => "noplay"));
     $this->assertNotNull($user);
     $this->assertEquals("BD3ZmTBhHmWJs", $user->password);
 }
Пример #30
0
Файл: DB.php Проект: phpscr/usvn
 /**
  * Create and save a user
  *
  * @return USVN_Db_Table_Row_User
  */
 protected function createUser($login, $password = "******")
 {
     $table = new USVN_Db_Table_Users();
     try {
         $user = $table->insert(array("users_login" => $login, "users_password" => USVN_Crypt::crypt($password), 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
         $user = $table->find($user)->current();
         return $user;
     } catch (Exception $e) {
         $this->fail($login . " : " . $e->getMessage());
     }
 }