ADD: Commit as logged in user
authorJustin J. Novack <jnovack@gmail.com>
Sun, 16 Sep 2012 17:52:17 +0000 (13:52 -0400)
committerJustin J. Novack <jnovack@gmail.com>
Sun, 16 Sep 2012 17:52:17 +0000 (13:52 -0400)
data/config.default.php
src/phorkie/Repository/Post.php
www/edit.php
www/new.php
www/www-header.php

index 7ecbda3..da16241 100644 (file)
@@ -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(
index de987e0..ed44cf1 100644 (file)
@@ -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;
         }
index 226b774..db4428b 100644 (file)
@@ -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'));
 }
 
index fc6d5f3..8d1a231 100644 (file)
@@ -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'));
 }
 
index 74863e1..5785a3e 100644 (file)
@@ -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']);