Exemplo n.º 1
0
 function createnewuser($data)
 {
     $usersConfig =& JComponentHelper::getParams('com_users');
     $authorize =& JFactory::getACL();
     $user = clone JFactory::getUser();
     $error_messages = array();
     $fieldname = array();
     $response = NULL;
     $validated = true;
     $pt = $this->_validatePT($data['jspt']);
     $pt = true;
     if (!$pt) {
         $validated = false;
         $error_messages[] = array("id" => 1, "fieldname" => "jspt", "message" => "Invalid profile type id");
     }
     if ($data['email'] == "") {
         $validated = false;
         $error_messages[] = array("id" => 1, "fieldname" => "email", "message" => "Email cannot be blank");
     } elseif (false == $this->isValidEmail($data['email'])) {
         $validated = false;
         $error_messages[] = array("id" => 1, "fieldname" => "email", "message" => "Please set valid email id eg.(example@gmail.com). Check 'email' field in request");
     }
     if ($data['password'] == "") {
         $validated = false;
         $error_messages[] = array("id" => 1, "fieldname" => "password", "message" => "Password cannot be blank");
     }
     if ($data['name'] == "") {
         $validated = false;
         $error_messages[] = array("id" => 1, "fieldname" => "name", "message" => "Name cannot be blank");
     }
     if (true == $validated) {
         jimport('joomla.filesystem.file');
         jimport('joomla.utilities.utility');
         CFactory::load('helpers', 'image');
         CFactory::load('libraries', 'avatar');
         $userModel =& CFactory::getModel('user');
         if ($data['username'] == "") {
             $username = $data['email'];
         } else {
             $username = $data['username'];
         }
         $user->set('username', $username);
         $user->set('password', $data['password']);
         $user->set('name', $data['name']);
         $user->set('email', $data['email']);
         // password encryption
         $salt = JUserHelper::genRandomPassword(32);
         $crypt = JUserHelper::getCryptedPassword($user->password, $salt);
         $user->password = "******";
         // user group/type
         $user->set('id', '');
         $user->set('usertype', 'Registered');
         $user->set('gid', $authorize->get_group_id('', 'Registered', 'ARO'));
         $date =& JFactory::getDate();
         $user->set('registerDate', $date->toMySQL());
         $storage = JPATH_ROOT . DS . 'images' . DS . 'avatar';
         //kapil
         if ($data['avatar_imagedata'] != "") {
             file_put_contents(JPATH_ROOT . DS . 'user_images/' . $data['username'], base64_decode($data['imagedata']));
             //kapil
             $imagedata = getimagesize(JPATH_ROOT . DS . 'user_images/' . $data['username']);
             rename(JPATH_ROOT . DS . 'user_images/' . $data['username'], JPATH_ROOT . DS . 'user_images/' . $data['username'] . "." . str_replace("image/", "", $imagedata['mime']));
             $imgtype = explode(".", $data['username'] . '.' . str_replace("image/", "", $imagedata['mime']));
             $imgmimetype = $imagedata['mime'];
         } else {
             if ($data['avatar'] != "") {
                 $imgtype = explode(".", $data['avatar']);
                 $imgmimetype = "image/" . $imgtype[1];
             }
         }
         //kapil
         if (isset($imgtype)) {
             $storageImage = $storage . DS . $imgtype[0] . '.' . $imgtype[1];
             $storageThumbnail = $storage . DS . 'thumb_' . $imgtype[0] . '.' . $imgtype[1];
             $image = 'images/avatar/' . $imgtype[0] . '.' . $imgtype[1];
             $thumbnail = 'images/avatar/' . 'thumb_' . $imgtype[0] . '.' . $imgtype[1];
             $imgpath = JPATH_ROOT . DS . 'user_images/' . $imgtype[0] . '.' . $imgtype[1];
             $filetype = $imgmimetype;
         } else {
             $image = 'components/com_community/assets/default.jpg';
             $thumbnail = 'components/com_community/assets/default_thumb.jpg';
         }
         if ($data['avatar'] == "" && $data['avatar_imagedata'] == "") {
             $user->set('avatar', 'components/com_community/assets/default.jpg');
             $user->set('thumb', 'components/com_community/assets/default_thumb.jpg');
         } else {
             if (!file_exists($imgpath)) {
                 $validated = false;
                 $error_messages[] = array("id" => 1, "fieldname" => "avatar", "message" => "Invalid Avatar image path");
             } else {
                 $user->set('avatar', 'images/avatar/' . $imgtype[0] . '.' . $imgtype[1]);
                 $user->set('avatar', 'images/avatar/thumb_' . $imgtype[0] . '.' . $imgtype[1]);
                 $imageMaxWidth = 160;
                 $imageSize = cImageGetSize($imgpath);
                 // Generate full image
                 if (!cImageResizePropotional($imgpath, $storageImage, $filetype, $imageMaxWidth)) {
                     $error_messages[] = array("id" => 1, "fieldname" => "avatar", "message" => "Fail: Error Moving Uploaded File");
                 }
                 // Generate thumbnail
                 if (!cImageCreateThumb($imgpath, $storageThumbnail, $filetype)) {
                     $error_messages[] = array("id" => 1, "fieldname" => "avatar", "message" => "Fail: Error Moving Uploaded File");
                 }
             }
         }
         if (!$user->save()) {
             $error_messages[] = array("id" => 1, "fieldname" => "usernameoremail", "message" => "username or email already in use.");
         } else {
             $my = CFactory::getUser($user->id);
             $userModel->setImage($my->id, $image, 'avatar');
             $userModel->setImage($my->id, $thumbnail, 'thumb');
             // Update the user object so that the profile picture gets updated.
             $my->set('_avatar', $image);
             $my->set('_thumb', $thumbnail);
             // Update Jomsocial profile type
             if ($user->id) {
                 XiptAPI::setUserProfiletype($user->id, $data['jspt']);
             }
         }
     }
     if (true == isset($error_messages) && 0 < sizeof($error_messages)) {
         $res = array();
         foreach ($error_messages as $key => $error_message) {
             $res[] = $error_message;
         }
         $response = array("id" => 0, 'errors' => $res);
     } else {
         $response = array('id' => $user->id);
     }
     return $response;
 }
Exemplo n.º 2
0
 function setUserProfiletype($userId, $pId)
 {
     if ($this->detect_application() == false) {
         return;
     }
     //IMP : if MI are attached but subscription_message is set to false
     // then dont apply any action
     //old
     //$subscription_message =  XiptFactory::getSettings('subscription_message');
     //new
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_xipt' . DS . 'api.xipt.php';
     $integrate_with = XiptAPI::getGlobalConfig('integrate_with');
     if ($integrate_with == 'aec') {
         XiptAPI::setUserProfiletype($userId, $pId, 'ALL');
     }
     return;
 }