<commit_before><?php

/**
 * Kebab Framework
 *
 * LICENSE
 *
 * This source file is subject to the  Dual Licensing Model that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.kebab-project.com/cms/licensing
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   Kebab (kebab-reloaded)
 * @package    Kebab
 * @subpackage Controllers
 * @author     lab2023 Dev Team
 * @copyright  Copyright (c) 2010-2011 lab2023 - internet technologies TURKEY Inc. (http://www.lab2023.com)
 * @license    http://www.kebab-project.com/cms/licensing
 * @version    1.5.0
 */


/**
 * Kebab_USerInvitationController
 *
 * @category   Kebab (kebab-reloaded)
 * @package    Kebab
 * @subpackage Controllers
 * @author     lab2023 Dev Team
 * @copyright  Copyright (c) 2010-2011 lab2023 - internet technologies TURKEY Inc. (http://www.lab2023.com)
 * @license    http://www.kebab-project.com/cms/licensing
 * @version    1.5.0
 */
class Kebab_UserInvitationController extends Kebab_Rest_Controller
{
    public function postAction()
    {
        $params = $this->_helper->param();
        $user = Kebab_Model_User::invite($params['fullName'], $params['email']);
        if (is_object($user)) {
            $this->sendInviteMail($user, $params['message']);
            $this->_helper->response(true, 200)->getResponse();
        } else {
            $this->_helper->response()->getResponse();
        }<commit_msg>#9 : Add validations.<commit_after><?php

/**
 * Kebab Framework
 *
 * LICENSE
 *
 * This source file is subject to the  Dual Licensing Model that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.kebab-project.com/cms/licensing
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   Kebab (kebab-reloaded)
 * @package    Kebab
 * @subpackage Controllers
 * @author     lab2023 Dev Team
 * @copyright  Copyright (c) 2010-2011 lab2023 - internet technologies TURKEY Inc. (http://www.lab2023.com)
 * @license    http://www.kebab-project.com/cms/licensing
 * @version    1.5.0
 */


/**
 * Kebab_USerInvitationController
 *
 * @category   Kebab (kebab-reloaded)
 * @package    Kebab
 * @subpackage Controllers
 * @author     lab2023 Dev Team
 * @copyright  Copyright (c) 2010-2011 lab2023 - internet technologies TURKEY Inc. (http://www.lab2023.com)
 * @license    http://www.kebab-project.com/cms/licensing
 * @version    1.5.0
 */
class Kebab_UserInvitationController extends Kebab_Rest_Controller
{
    public function postAction()
    {
        // Params
        $params = $this->_helper->param();
        $response = $this->_helper->response();
        $valid = true;

        // Validatation

        // Exist user
        $count = Doctrine_Core::getTable('Model_Entity_User')->findByemail($params['email'])->count();
        if ($count > 0) {
            $response->addNotification('ERR', 'There is a user with this email');
            $valid = false;
        }

        // Invalid email address
        $validator = new Zend_Validate_EmailAddress();
        if (!$validator->isValid($params['email'])) {
            $response->addNotification('ERR', 'Invalid email address');
            $valid = false;
        }

        // Check Fullname only Alpha chracter enable
        $validator = new Zend_Validate_Alpha(array('allowWhiteSpace' => true));
        if (!$validator->isValid($params['fullName'])) {
            $response->addNotification('ERR', 'Only alpha character enable.');
            $valid = false;
        }

        // Model
        if ($valid) {
            $user = Kebab_Model_User::invite($params['fullName'], $params['email']);
        }        

        // Response
        if ($valid && is_object($user)) {
            $this->sendInviteMail($user, $params['message']);
            $response->setSuccess(true);
        }

        $response->getResponse();
{'fraction_non_alphanumeric': 0.12996219281663515, 'fraction_numerical': 0.022920604914933838, 'mean_word_length': 2.74933569530558, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1463300', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1258, 'n_words': 339}