]> dev.renevier.net Git - syj.git/blobdiff - application/controllers/UserController.php
update copyright headers
[syj.git] / application / controllers / UserController.php
index 2bd41d3106b78bbecf9c7d03c6001e255ba853a8..9989d311379c3369e803e5b221ce8b16dee23937 100644 (file)
@@ -1,10 +1,25 @@
 <?php
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
+/*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
     and is published under the AGPL license. */
 
 class UserController extends Zend_Controller_Action
 {
 
+    public function existsAction() {
+        $name = $this->getRequest()->getUserParam('name');
+
+        $userMapper = new Syj_Model_UserMapper();
+        $user = new Syj_Model_User();
+
+        if ($userMapper->findByPseudo($name, $user)) {
+            $this->_helper->SyjApi->setCode(200);
+        } else {
+            // opera needs some body content with 404 code, otherwise, it
+            // reports a xmlhttprequest.status of 0
+            $this->_helper->SyjApi->setCode(404)->setBody(' ');
+        }
+    }
+
     public function userAction() {
         $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_User');
 
@@ -47,6 +62,8 @@ class UserController extends Zend_Controller_Action
         }
 
         $this->_helper->SyjSession->login($user->id);
-        $this->_helper->SyjApi->setCode(200);
+
+        $data = array('pseudo' => $user->pseudo);
+        $this->_helper->SyjApi->setBodyJson($data)->setCode(200);
     }
 }