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 7ecbda33dc02ecc7d61aa46fe9df0bf07aa053ce..da1624156fe5a92540eee913f74588a475e5c277 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 de987e0a74fe07e70245c7cbd53df8e99957399d..ed44cf1535bd030d2f3ff364e8c4e6d4c23d02b1 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 226b774e056f5040c6306a1e11aa942662b69341..db4428b3cb36958778bf86cafb408bb58428fa49 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 fc6d5f38b196b9810e9af438cd5b8ba377e80293..8d1a231d1ff9e339f2bc062702c886ea074ddc20 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 74863e1637f18b011a31ec2609eb38105e0bbea2..5785a3ec300ff16552a627896f99ebf65e71fca2 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']);