From: Justin J. Novack Date: Sun, 16 Sep 2012 17:52:17 +0000 (-0400) Subject: ADD: Commit as logged in user X-Git-Tag: v0.3.0~42^2~49 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/5935a357efd7be14481b21560347f70116891e16 ADD: Commit as logged in user --- diff --git a/data/config.default.php b/data/config.default.php index 7ecbda3..da16241 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -15,6 +15,7 @@ $GLOBALS['phorkie']['cfg'] = array( $GLOBALS['phorkie']['auth'] = array( 'secure' => 0, // 0 = public, no authentication, 1 = protect adds/edits/deletes, 2 = use authentication 'userlist' => false, // true = user must be explicitly defined, false = anyone allowed, but they must authenticate + 'anonymousName' => 'Anonymous', // Email for non-authenticated commits 'anonymousEmail' => 'anonymous@phorkie' // Email for non-authenticated commits ); $GLOBALS['phorkie']['tools'] = array( diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index de987e0..ed44cf1 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -15,7 +15,7 @@ class Repository_Post * * @return boolean True if the post was successful */ - public function process($postData) + public function process($postData, $sessionData) { if (!isset($postData['files'])) { return false; @@ -117,11 +117,17 @@ class Repository_Post } } + $commitmsg = "phorkie commit"; + if (isset($sessionData['identity'])) { + $commitmsg .= " from ".$sessionData['identity']; + } else { + $commitmsg .= " by ".$sessionData['ipaddr']; + } + if ($bCommit) { $vc->getCommand('commit') - ->setOption('message', '') - ->setOption('allow-empty-message') - ->setOption('author', 'Anonymous ') + ->setOption('message', $commitmsg) + ->setOption('author', $sessionData['name'].' <'.$sessionData['email'].'>') ->execute(); $bChanged = true; } diff --git a/www/edit.php b/www/edit.php index 226b774..db4428b 100644 --- a/www/edit.php +++ b/www/edit.php @@ -12,7 +12,7 @@ $repo = new Repository(); $repo->loadFromRequest(); $repopo = new Repository_Post($repo); -if ($repopo->process($_POST)) { +if ($repopo->process($_POST, $_SESSION)) { redirect($repo->getLink('display')); } diff --git a/www/new.php b/www/new.php index fc6d5f3..8d1a231 100644 --- a/www/new.php +++ b/www/new.php @@ -16,7 +16,7 @@ if ($GLOBALS['phorkie']['auth']['secure'] > 0) { } $repopo = new Repository_Post(); -if ($repopo->process($_POST)) { +if ($repopo->process($_POST, $_SESSION)) { redirect($repopo->repo->getLink('display')); } diff --git a/www/www-header.php b/www/www-header.php index 74863e1..5785a3e 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -47,6 +47,12 @@ if (file_exists(__DIR__ . '/../data/config.php')) { if ($GLOBALS['phorkie']['cfg']['setupcheck']) { SetupCheck::run(); } + +// Set/Get git commit session variables +$_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR']; +if (!isset($_SESSION['name'])) { $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName']; } +if (!isset($_SESSION['email'])) { $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail']; } + \Twig_Autoloader::register(); $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);