Example #1
0
 public function addAction($email = null)
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $validator = new Zend_Validate_EmailAddress();
     if ($validator->isValid($this->getRequest()->getParam('email'))) {
         $splitEmail = explode('@', $this->getRequest()->getParam('email'));
         $password = Sendlove_Utilities::createPassword();
         $token = uniqid();
         $login = Zend_Json::decode($this->_helper->api(array('app' => $this->_helper->api->name('login'), 'key' => $this->_helper->api->key('login'), 'token' => $token, 'admin_id' => $this->getSession()->userid, 'user_data' => array(array('username' => $this->getRequest()->getParam('email'), 'password' => $password, 'nickname' => $splitEmail[0], 'Active' => 1, 'Confirmed' => 1, 'status' => 'new'))), $this->_helper->api->endpoint('login') . 'admincreateusers'));
         if ($login['error'] == 0) {
             if ($login['token'] == $token) {
                 if ($this->getRequest()->getParam('sendlove')) {
                     $love = new Sendlove_Love();
                     $love->sendLove($this->getLoveEmail(), $this->getSession()->username, 'Welcome to SendLove');
                 }
                 $companyMapper = new Admin_Model_CompanyMapper();
                 $company = $companyMapper->find($this->_helper->config('application')->companyid);
                 if (!$this->sendCreateMail(array('creator_nickname' => $this->getSession()->nickname, 'creator_email' => $this->getSession()->username, 'company_name' => $company->getCompany_name(), 'url' => $this->_helper->config('application')->loveLoginUrl, 'user_username' => $this->getRequest()->getParam('email'), 'user_password' => $password))) {
                     throw new Exception('Email could not be sent!');
                 }
                 // Get the user data
                 $user = $login['0'][0];
                 $newUsers[] = array('id' => $user['id'], 'username' => $user['username'], 'nickname' => $user['nickname'], 'active' => 1, 'confirmed' => 1);
                 echo Zend_Json::encode(array('success' => true, 'message' => 'User successfully added', 'users' => $newUsers));
             } else {
                 echo Zend_Json::encode(array('success' => false, 'message' => $login['message']));
             }
         } else {
             echo Zend_Json::encode(array('success' => false, 'message' => 'Could not add the user.'));
         }
     } else {
         echo Zend_Json::encode(array('success' => false, 'message' => 'No valid email address.'));
     }
 }