aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin J. Novack <jnovack@gmail.com>2012-09-16 13:52:17 -0400
committerJustin J. Novack <jnovack@gmail.com>2012-09-16 13:52:17 -0400
commit5935a357efd7be14481b21560347f70116891e16 (patch)
treed33f80d1f196aff3a410b5492bf411b1f2d74833
parent7d7fab92064cfb09b152651fc9cb1fe55516fca1 (diff)
downloadphorkie-5935a357efd7be14481b21560347f70116891e16.tar.gz
phorkie-5935a357efd7be14481b21560347f70116891e16.zip
ADD: Commit as logged in user
-rw-r--r--data/config.default.php1
-rw-r--r--src/phorkie/Repository/Post.php14
-rw-r--r--www/edit.php2
-rw-r--r--www/new.php2
-rw-r--r--www/www-header.php6
5 files changed, 19 insertions, 6 deletions
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 <anonymous@phorkie>')
+ ->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']);