Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
UserApiController.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  // Alter parent filters to allow access to Users module when auser is trying to access getAuthenticatedUser via API
43  public function filters()
44  {
45  $filters = parent::filters();
46  foreach ($filters as $key => $filter)
47  {
48  if (is_array($filter) &&
49  isset($filter[0]) && $filter[0] == self::getRightsFilterPath() &&
50  isset($filter['moduleClassName']) && $filter['moduleClassName'] == 'UsersModule' &&
51  isset($filter['rightName']) && $filter['rightName'] == UsersModule::getAccessRight())
52  {
53  $filters[$key][0] = $filters[$key][0] . ' - getAuthenticatedUser, searchUsersByEmails';
54  }
55  }
56  return $filters;
57  }
58 
59  protected static function getSearchFormClassName()
60  {
61  return 'UsersSearchForm';
62  }
63 
68  public function actionCreate()
69  {
70  $params = Yii::app()->apiRequest->getParams();
71  if (!isset($params['data']))
72  {
73  $message = Zurmo::t('ZurmoModule', 'Please provide data.');
74  throw new ApiException($message);
75  }
76  $this->resolvePasswordParameter($params);
77  $result = $this->processCreate($params['data']);
78  Yii::app()->apiHelper->sendResponse($result);
79  }
80 
85  public function actionUpdate()
86  {
87  $params = Yii::app()->apiRequest->getParams();
88  if (!isset($params['id']))
89  {
90  $message = Zurmo::t('ZurmoModule', 'The ID specified was invalid.');
91  throw new ApiException($message);
92  }
93  $this->resolvePasswordParameter($params);
94  $result = $this->processUpdate((int)$params['id'], $params['data']);
95  Yii::app()->apiHelper->sendResponse($result);
96  }
97 
102  public function actionGetAuthenticatedUser()
103  {
104  if (Yii::app()->user->isGuest)
105  {
106  $message = Zurmo::t('ZurmoModule', 'You must be logged to use this method.');
107  throw new ApiException($message);
108  }
109  try
110  {
111  $data = static::getModelToApiDataUtilData(Yii::app()->user->userModel);
112  $resultClassName = Yii::app()->apiRequest->getResultClassName();
113  $result = new $resultClassName(ApiResponse::STATUS_SUCCESS, $data, null, null);
114  }
115  catch (Exception $e)
116  {
117  $message = $e->getMessage();
118  throw new ApiException($message);
119  }
120  Yii::app()->apiHelper->sendResponse($result);
121  }
122 
127  public function actionSearchUsersByEmails()
128  {
129  $params = Yii::app()->apiRequest->getParams();
130  if (!isset($params['data']))
131  {
132  $message = Zurmo::t('ZurmoModule', 'Please provide data.');
133  throw new ApiException($message);
134  }
135  if (!isset($params['data']['emails']) || !is_array($params['data']['emails']) || empty($params['data']['emails']))
136  {
137  $message = Zurmo::t('ZurmoModule', 'Emails parameters must exist, must be an array and must contain at least one email address.');
138  throw new ApiException($message);
139  }
140  $data = array();
141  $data['users'] = array();
142  try
143  {
144  foreach ($params['data']['emails'] as $email)
145  {
146  $usersByEmail = UserSearch::getUsersByEmailAddress($email);
147  if (!empty($usersByEmail) && count($usersByEmail) == 1)
148  {
149  $user = array();
150  $user['id'] = $usersByEmail[0]->id;
151  $user['firstName'] = $usersByEmail[0]->firstName;
152  $user['lastName'] = $usersByEmail[0]->lastName;
153  $user['username'] = $usersByEmail[0]->username;
154  if ($usersByEmail[0]->primaryEmail->emailAddress != null)
155  {
156  $user['email'] = $usersByEmail[0]->primaryEmail->emailAddress;
157  }
158  $data['users'][] = $user;
159  }
160  }
161  $result = new ApiResult(ApiResponse::STATUS_SUCCESS, $data, null, null);
162  }
163  catch (Exception $e)
164  {
165  $message = $e->getMessage();
166  throw new ApiException($message);
167  }
168  Yii::app()->apiHelper->sendResponse($result);
169  }
170 
171  protected function resolvePasswordParameter(& $params)
172  {
173  // We have to encrypt password
174  if (isset($params['data']['password']) && $params['data']['password'] != '')
175  {
176  $params['data']['hash'] = User::encryptPassword($params['data']['password']);
177  }
178  unset($params['data']['password']);
179  }
180  }
181 ?>
static getUsersByEmailAddress($emailAddress, $operatorType=null, $filterOutHideFromSelecting=false, $autoCompleteOptions=null, $pageSize=null)
Definition: UserSearch.php:104
Generated on Fri Dec 4 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.