]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apichecknickname.php
Let's not limit qvitter stuff to 'json' requests
[quix0rs-gnu-social.git] / actions / apichecknickname.php
1 <?php
2                 
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Check nickname
7  *
8  * Returns 1 if nickname is ok, 0 if not
9  *
10  * PHP version 5
11  *
12  * LICENCE: This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  *
25  * @category  API
26  * @package   GNUSocial
27  * @author    Hannes Mannerheim <h@nnesmannerhe.im>
28  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29  * @link      http://www.gnu.org/software/social/
30  */
31
32 if (!defined('GNUSOCIAL')) { exit(1); }
33
34 class ApiCheckNicknameAction extends ApiAction
35 {
36
37     protected function prepare($args)
38     {
39         parent::prepare($args);
40
41         if ($this->format !== 'json') {
42             $this->clientError('This method currently only serves JSON.', 415);
43         }
44         
45         return true;
46     }
47
48     protected function handle()
49     {
50         parent::handle();
51         
52         $nickname = $this->trimmed('nickname');
53                 
54         if ($this->nicknameExists($nickname)) {
55             $nickname_ok = 0;
56         } else if (!User::allowed_nickname($nickname)) {
57             $nickname_ok = 0;        }
58         else {
59             $nickname_ok = 1;           
60                 }
61
62         $this->initDocument('json');
63         $this->showJsonObjects($nickname_ok);
64         $this->endDocument('json');
65     }
66     
67     function nicknameExists($nickname)
68     {
69         $user = User::staticGet('nickname', $nickname);
70         return is_object($user);
71     }    
72     
73 }