Skip to content

Commit 558c865

Browse files
committed
Updated manifest for Joomla 2.5+ and list view refactor
1 parent c1d6f05 commit 558c865

File tree

2 files changed

+35
-176
lines changed

2 files changed

+35
-176
lines changed

users/users.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<install version="1.7" type="plugin" group="api" method="upgrade">
2+
<extension version="2.5.0" type="plugin" group="api" method="upgrade">
33
<name>Api - users</name>
44
<version>1.0</version>
5-
<creationDate>April 2012</creationDate>
6-
<author>Tekdi</author>
7-
<authorEmail>support@tekdi.com</authorEmail>
8-
<authorUrl>http://www.tekdi.com</authorUrl>
9-
<copyright>2012 users</copyright>
5+
<creationDate>July 2014</creationDate>
6+
<author>techjoomla</author>
7+
<authorEmail>contact@techjoomla.com</authorEmail>
8+
<authorUrl>http://techjoomla.com</authorUrl>
9+
<copyright>Techjoomla</copyright>
1010
<license>GNU General Public License v2</license>
1111
<description>This plugin exposes users to the Joomla! API</description>
1212

1313
<files>
1414
<filename plugin="users">users.php</filename>
15-
<filename >users/users.php</filename>
1615
<folder>users</folder>
1716
</files>
18-
</install>
17+
</extension>

users/users/users.php

Lines changed: 28 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,46 @@
11
<?php
2-
/**
3-
* @package API
4-
* @version 1.5
5-
* @author Brian Edgerton
6-
* @link http://www.edgewebworks.com
7-
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
8-
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
9-
*/
102

113
defined('_JEXEC') or die( 'Restricted access' );
4+
jimport('joomla.user.user');
125

13-
jimport('joomla.plugin.plugin');
14-
jimport('joomla.html.html');
15-
jimport('joomla.user.helper');
16-
jimport( 'joomla.application.component.helper' );
17-
jimport( 'joomla.application.component.model' );
18-
jimport( 'joomla.database.table.user' );
19-
require_once( JPATH_SITE .DS.'components'.DS.'com_community'.DS.'libraries'.DS.'core.php');
20-
require_once( JPATH_SITE .DS.'libraries'.DS.'joomla'.DS.'filesystem'.DS.'folder.php');
21-
//vishal
22-
if(JFolder::exists(JPATH_BASE.DS.'components'.DS.'com_xipt'))
23-
{
24-
require_once( JPATH_SITE .DS.'components'.DS.'com_xipt'.DS.'api.xipt.php');
25-
}
6+
require_once JPATH_ROOT . '/administrator/components/com_users/models/users.php';
267

278
class UsersApiResourceUsers extends ApiResource
289
{
2910

11+
public function delete()
12+
{
13+
$this->plugin->setResponse( 'in delete' );
14+
}
15+
3016
public function post()
31-
{
32-
33-
$error_messages = array();
34-
$fieldname = array();
35-
$response = NULL;
36-
$validated = true;
37-
$userid = NULL;
38-
$data = JRequest::get('post');
39-
//for rest api only
40-
unset($data['format']);
41-
unset($data['resource']);
42-
unset($data['app']);
43-
unset($data['password']);
44-
unset($data['username']);
45-
//
46-
//$userid = $data['userid'];
47-
$fields = $data['field'];
48-
49-
//chk data
50-
if($data['email']=="" )
51-
{
52-
$validated = false;
53-
$error_messages[] = array("id"=>1,"fieldname"=>"email","message"=>"Email cannot be blank");
54-
} elseif( false == $this->isValidEmail( $data['email'] ) ) {
55-
$validated = false;
56-
$error_messages[] = array("id"=>1,"fieldname"=>"email","message"=>"Please set valid email id eg.(example@gmail.com). Check 'email' field in request");
57-
58-
}else
59-
{
60-
//check mail is registerd
61-
$isemail =& CFactory::getModel('register');
62-
$found = $isemail->isEmailExists(array('email'=>$data['email'] ));
63-
if($found)
64-
{
65-
$validated = false;
66-
$error_messages[] = array("id"=>1,"fieldname"=>"email","message"=>"email already exist and user is registered");
67-
}
68-
}
69-
70-
if( $data['password1']=="" )
71-
{
72-
$validated = false;
73-
$error_messages[] = array("id"=>1,"fieldname"=>"password","message"=>"Password cannot be blank");
74-
}
75-
76-
if( $data['name']=="" or $data['username1']=="" )
77-
{
78-
$validated = false;
79-
$error_messages[] = array("id"=>1,"fieldname"=>"name","message"=>"Name cannot be blank");
80-
}
17+
{
18+
$this->plugin->setResponse( 'in post' );
19+
}
8120

82-
if( true == $validated)
83-
{ //to create new user for joomla
84-
85-
global $message;
86-
jimport('joomla.user.helper');
87-
$authorize = & JFactory::getACL();
88-
$user = clone(JFactory::getUser());
89-
$user->set('username', $data['username1']);
90-
$user->set('password', $data['password1'] );
91-
$user->set('name', $data['name']);
92-
$user->set('email', $data['email']);
93-
94-
// password encryption
95-
$salt = JUserHelper::genRandomPassword(32);
96-
$crypt = JUserHelper::getCryptedPassword($user->password, $salt);
97-
$user->password = "$crypt:$salt";
98-
99-
// user group/type
100-
$user->set('id', '');
101-
$user->set('usertype', 'Registered');
102-
if(JVERSION >= '1.6.0')
103-
{
104-
$userConfig = JComponentHelper::getParams('com_users');
105-
// Default to Registered.
106-
$defaultUserGroup = $userConfig->get('new_usertype', 2);
107-
$user->set('groups', array($defaultUserGroup));
108-
}
109-
else
110-
$user->set('gid', $authorize->get_group_id( '', 'Registered', 'ARO' ));
21+
public function get() {
22+
$input = JFactory::getApplication()->input;
11123

112-
$date =& JFactory::getDate();
113-
$user->set('registerDate', $date->toMySQL());
114-
115-
// true on success, false otherwise
116-
if(!$user->save())
117-
{
118-
$message="not created because of ".$user->getError();
119-
return false;
24+
// If we have an id try to fetch the user
25+
if ($id = $input->get('id')) {
26+
$user = JUser::getInstance($id);
27+
28+
if (!$user->id) {
29+
$this->plugin->setResponse( $this->getErrorResponse(404, 'User not found') );
30+
return;
12031
}
121-
else
122-
{
123-
$message="created of username-".$user->username." and send mail of details please check";
124-
125-
}
126-
//$this->plugin->setResponse($user->id);
127-
$userid = $user->id;
128-
//create profile
129-
$profileModel =& CFactory::getModel('profile');
130-
$val = $profileModel->saveProfile($userid, $fields);
131-
//result message
132-
$result = array('user id '=>$userid,'message'=>$message);
133-
$result =($userid) ? $result : $message;
134-
135-
$this->plugin->setResponse($result);
13632

137-
138-
}
139-
else
140-
{
33+
$this->plugin->setResponse( $user );
34+
} else {
35+
$model = new UsersModelUsers;
36+
$users = $model->getItems();
37+
38+
foreach ($users as $k => $v) {
39+
unset($users[$k]->password);
40+
}
14141

142-
$this->plugin->setResponse($error_messages);
42+
$this->plugin->setResponse( $users );
14343
}
144-
145-
146-
147-
}
148-
149-
public function put()
150-
{
151-
$data = JRequest::get('post');
152-
153-
//for rest api only
154-
unset($data['format']);
155-
unset($data['resource']);
156-
unset($data['app']);
157-
unset($data['password']);
158-
unset($data['username']);
159-
//
160-
$userid = $data['userid'];
161-
$fields = $data['field'];
162-
163-
print_r($data);die;
164-
165-
166-
$this->plugin->setResponse( "in the put method" );
167-
}
168-
169-
public function delete()
170-
{
171-
$this->plugin->setResponse( "in the delete method" );
172-
}
173-
174-
function isValidEmail( $email )
175-
{
176-
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
177-
178-
if ( eregi( $pattern, $email ) )
179-
{
180-
return true;
181-
} else {
182-
return false;
183-
}
18444
}
18545

18646
}

0 commit comments

Comments
 (0)