|
1 | 1 | <?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 |
| -*/ |
10 | 2 |
|
11 | 3 | defined('_JEXEC') or die( 'Restricted access' );
|
| 4 | +jimport('joomla.user.user'); |
12 | 5 |
|
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'; |
26 | 7 |
|
27 | 8 | class UsersApiResourceUsers extends ApiResource
|
28 | 9 | {
|
29 | 10 |
|
| 11 | + public function delete() |
| 12 | + { |
| 13 | + $this->plugin->setResponse( 'in delete' ); |
| 14 | + } |
| 15 | + |
30 | 16 | 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 | + } |
81 | 20 |
|
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; |
111 | 23 |
|
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; |
120 | 31 | }
|
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); |
136 | 32 |
|
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 | + } |
141 | 41 |
|
142 |
| - $this->plugin->setResponse($error_messages); |
| 42 | + $this->plugin->setResponse( $users ); |
143 | 43 | }
|
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 |
| - } |
184 | 44 | }
|
185 | 45 |
|
186 | 46 | }
|
0 commit comments