+

Add 'nopassword' parameter

Benjamin Renard [2014-11-27 14:58:14]
Add 'nopassword' parameter
Filename
README
addrepo/main.php
addrepo/templates/addrepo.php
diff --git a/README b/README
index a18deaa..048c0d5 100644
--- a/README
+++ b/README
@@ -6,7 +6,8 @@ ViewGit : A form permit to give

 * repository name
 * repository description
-* a password witch protect this feature
+* a password witch protect this feature (except when nopassword option is set
+  to True)

 The repository name will be validated : it must contain only letter, number,
 "_" or "-" caracter.
@@ -17,6 +18,9 @@ description file of the repository.
 The given password will be compare with $conf['addrepo']['password'] value.
 If password is ommit in the configuration, the creation will be refused.

+If you want to completely disable password check, you have to set
+$conf['addrepo']['nopassword'] to True.
+
 After create a new repository, if you go on the repository page, you will have
 a message that explain you how to push your first commits. This message could
 be change by editing template file summary.php. This message is displayed only
@@ -38,5 +42,6 @@ Install
 $conf['addrepo'] = array(
         'root_path' => '/full/path/to/your/repos',
         'password' => 'secret',
+        'nopassword' => True|False,
         'url_format' => 'git@git.example.com:public_git/%s'
 );
diff --git a/addrepo/main.php b/addrepo/main.php
index 478bba0..ab5d210 100644
--- a/addrepo/main.php
+++ b/addrepo/main.php
@@ -16,7 +16,7 @@ class AddRepoPlugin extends VGPlugin
 		if ($action === 'addrepo') {
 			global $page;
 			global $conf;
-			if (isset($_POST['repo_name']) && isset($_POST['repo_desc']) && isset($_POST['repo_pwd'])) {
+			if (isset($_POST['repo_name']) && isset($_POST['repo_desc'])) {
 				$create=True;
 				$name=rtrim($_POST['repo_name']);
 				if (!$this -> validate_repo_name($name)) {
@@ -29,16 +29,18 @@ class AddRepoPlugin extends VGPlugin
 					$create=False;
 				}

-				if (!isset($conf['addrepo']['password']) || empty($conf['addrepo']['password'])) {
-					$this -> add_display_message('Password not defined in configuration. Creation disable.',True);
-					$create=False;
-				}
-				else {
-					$pwd=rtrim($_POST['repo_pwd']);
-					if ($pwd!=$conf['addrepo']['password']) {
-						$this -> add_display_message('Password incorrect',True);
+				if (!isset($conf['addrepo']['nopassword']) || ($conf['addrepo']['nopassword']===False)) {
+					if (!isset($conf['addrepo']['password']) || empty($conf['addrepo']['password'])) {
+						$this -> add_display_message('Password not defined in configuration. Creation disable.',True);
 						$create=False;
 					}
+					else {
+						$pwd=rtrim($_POST['repo_pwd']);
+						if ($pwd!=$conf['addrepo']['password']) {
+							$this -> add_display_message('Password incorrect',True);
+							$create=False;
+						}
+					}
 				}

 				if ($create && $this -> create_repo($name,$desc)) {
diff --git a/addrepo/templates/addrepo.php b/addrepo/templates/addrepo.php
index ea4dfc9..8b96c66 100644
--- a/addrepo/templates/addrepo.php
+++ b/addrepo/templates/addrepo.php
@@ -18,8 +18,15 @@ if (isset($page['addrepo']['msg'])) {
 	<dd><input type='text' name='repo_name' class='addrepo' value="<?php echo (isset($page['addrepo']['values']['name'])?$page['addrepo']['values']['name']:''); ?>"/></dd>
 	<dt>Description</dt>
 	<dd><input type='text' name='repo_desc' class='addrepo' value="<?php echo (isset($page['addrepo']['values']['desc'])?$page['addrepo']['values']['desc']:''); ?>"/></dd>
-	<dt>Password</dt>
-	<dd><input type='password' name='repo_pwd' class='addrepo'/></dd>
+	<?php
+	global $conf;
+	if (!isset($conf['addrepo']['nopassword']) || ($conf['addrepo']['nopassword']===False)) {
+		echo"
+		<dt>Password</dt>
+		<dd><input type='password' name='repo_pwd' class='addrepo'/></dd>
+		";
+	}
+	?>
 </dl>
 <input type='submit' value='Create' id='addrepo_submit'/>
 </form>
ViewGit