Skip to content

Commit 9f43cf4

Browse files
committed
vishal - added create user code
1 parent c962346 commit 9f43cf4

File tree

1 file changed

+129
-26
lines changed

1 file changed

+129
-26
lines changed

users/users/users.php

100755100644
Lines changed: 129 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,155 @@
11
<?php
22
/**
3-
* @package Com_api
4-
* @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
5-
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
6-
* @link http://www.techjoomla.com
7-
*/
8-
9-
defined('_JEXEC') or die( 'Restricted access' );
3+
* @package Joomla.Administrator
4+
* @subpackage com_trading
5+
*
6+
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
// No direct access.
10+
defined('_JEXEC') or die;
11+
1012
jimport('joomla.user.user');
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');
1119

20+
require_once JPATH_SITE . '/libraries/joomla/filesystem/folder.php';
1221
require_once JPATH_ROOT . '/administrator/components/com_users/models/users.php';
1322

23+
/**
24+
* User Api.
25+
*
26+
* @package Joomla.Administrator
27+
* @subpackage com_api
28+
*
29+
* @since 1.0
30+
*/
1431
class UsersApiResourceUsers extends ApiResource
1532
{
16-
33+
/**
34+
* Function delete for user record.
35+
*
36+
* @return void
37+
*/
1738
public function delete()
18-
{
19-
$this->plugin->setResponse( 'in delete' );
39+
{
40+
$this->plugin->setResponse('in delete');
2041
}
2142

43+
/**
44+
* Function post for create user record.
45+
*
46+
* @return void
47+
*/
2248
public function post()
23-
{
24-
$this->plugin->setResponse( 'in post' );
49+
{
50+
$error_messages = array();
51+
$fieldname = array();
52+
$response = null;
53+
$validated = true;
54+
$userid = null;
55+
$data = array();
56+
57+
$app = JFactory::getApplication();
58+
$data['username'] = $app->input->get('username', '', 'STRING');
59+
$data['password'] = $app->input->get('password', '', 'STRING');
60+
$data['name'] = $app->input->get('name', '', 'STRING');
61+
$data['email'] = $app->input->get('email', '', 'STRING');
62+
63+
global $message;
64+
jimport('joomla.user.helper');
65+
$authorize = JFactory::getACL();
66+
$user = clone JFactory::getUser();
67+
$user->set('username', $data['username']);
68+
$user->set('password', $data['password']);
69+
$user->set('name', $data['name']);
70+
$user->set('email', $data['email']);
71+
72+
// Password encryption
73+
$salt = JUserHelper::genRandomPassword(32);
74+
$crypt = JUserHelper::getCryptedPassword($user->password, $salt);
75+
$user->password = "$crypt:$salt";
76+
77+
// User group/type
78+
$user->set('id', '');
79+
$user->set('usertype', 'Registered');
80+
81+
if (JVERSION >= '1.6.0')
82+
{
83+
$userConfig = JComponentHelper::getParams('com_users');
84+
85+
// Default to Registered.
86+
$defaultUserGroup = $userConfig->get('new_usertype', 2);
87+
$user->set('groups', array($defaultUserGroup));
88+
}
89+
else
90+
{
91+
$user->set('gid', $authorize->get_group_id('', 'Registered', 'ARO'));
92+
}
93+
94+
$date =& JFactory::getDate();
95+
$user->set('registerDate', $date->toSql());
96+
97+
// True on success, false otherwise
98+
if (!$user->save())
99+
{
100+
$message = "not created because of " . $user->getError();
101+
102+
return false;
103+
}
104+
else
105+
{
106+
$message = "created of username-" . $user->username . " and send mail of details please check";
107+
}
108+
109+
// #$this->plugin->setResponse($user->id);
110+
$userid = $user->id;
111+
112+
// Result message
113+
$result = array('user id ' => $userid, 'message' => $message);
114+
$result = ($userid) ? $result : $message;
115+
116+
$this->plugin->setResponse($result);
25117
}
26-
27-
public function get() {
118+
119+
/**
120+
* Function get for users record.
121+
*
122+
* @return void
123+
*/
124+
public function get()
125+
{
28126
$input = JFactory::getApplication()->input;
29127

30128
// If we have an id try to fetch the user
31-
if ($id = $input->get('id')) {
129+
if ($id = $input->get('id'))
130+
{
32131
$user = JUser::getInstance($id);
33-
34-
if (!$user->id) {
35-
$this->plugin->setResponse( $this->getErrorResponse(404, 'User not found') );
132+
133+
if (!$user->id)
134+
{
135+
$this->plugin->setResponse($this->getErrorResponse(404, 'User not found'));
136+
36137
return;
37138
}
38-
39-
$this->plugin->setResponse( $user );
40-
} else {
139+
140+
$this->plugin->setResponse($user);
141+
}
142+
else
143+
{
41144
$model = new UsersModelUsers;
42145
$users = $model->getItems();
43-
44-
foreach ($users as $k => $v) {
146+
147+
foreach ($users as $k => $v)
148+
{
45149
unset($users[$k]->password);
46150
}
47-
48-
$this->plugin->setResponse( $users );
151+
152+
$this->plugin->setResponse($users);
49153
}
50154
}
51-
52155
}

0 commit comments

Comments
 (0)