Files
icehrm/ext/admin/users/api/UsersActionManager.php
Thilina Hasantha 31bb455d6f Release note v16.0
------------------
### Features
 * Advanced Employee Management Module is now included in IceHrm Open Source Edition
 * LDAP Module which was only available in IceHrm Enterprise is now included in open source also
 * Initial implementation of icehrm REST Api for reading employee details
 * Improvements to data filtering
 * Multiple tabs for settings module
 * Overtime reports - now its possible to calculate overtime for employees.compatible with US overtime rules
 * Logout the user if tried accessing an unauthorized module
 * Setting for updating module names

### Fixes
 * Fix issue: classes should be loaded even the module is disabled
 * Deleting the only Admin user is not allowed
 * Fixes for handling non UTF-8
 * Fix for non-mandatory select boxes are shown as mandatory
2016-04-15 20:24:39 +05:30

108 lines
3.7 KiB
PHP

<?php
/*
This file is part of iCE Hrm.
iCE Hrm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iCE Hrm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iCE Hrm. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/
class UsersActionManager extends SubActionManager{
public function changePassword($req){
if(defined('DEMO_MODE')){
return new IceResponse(IceResponse::ERROR,"You are not allowed to change the password in demo mode");
}
$user = new User();
$user->Load("id = ?",array($req->id));
LogManager::getInstance()->debug("Current User:".print_r($this->user,true));
LogManager::getInstance()->debug("Edit User:".print_r($user,true));
if($this->user->user_level == 'Admin' || $this->user->id == $user->id){
if(empty($user->id)){
return new IceResponse(IceResponse::ERROR,"Please save the user first");
}
$user->password = md5($req->pwd);
$ok = $user->Save();
if(!$ok){
return new IceResponse(IceResponse::ERROR,$user->ErrorMsg());
}
return new IceResponse(IceResponse::SUCCESS,$user);
}
return new IceResponse(IceResponse::ERROR);
}
public function saveUser($req){
if($this->user->user_level == 'Admin'){
$user = new User();
$user->Load("email = ?",array($req->email));
if($user->email == $req->email){
return new IceResponse(IceResponse::ERROR,"User with same email already exists");
}
$user->Load("username = ?",array($req->username));
if($user->username == $req->username){
return new IceResponse(IceResponse::ERROR,"User with same username already exists");
}
$user = new User();
$user->email = $req->email;
$user->username = $req->username;
$password = $this->generateRandomString(6);
$user->password = md5($password);
$user->employee = (empty($req->employee) || $req->employee == "NULL" )?NULL:$req->employee;
$user->user_level = $req->user_level;
$user->last_login = date("Y-m-d H:i:s");
$user->last_update = date("Y-m-d H:i:s");
$user->created = date("Y-m-d H:i:s");
$employee = null;
if(!empty($user->employee)){
$employee = $this->baseService->getElement('Employee',$user->employee,null,true);
}
$ok = $user->Save();
if(!$ok){
LogManager::getInstance()->info($user->ErrorMsg()."|".json_encode($user));
return new IceResponse(IceResponse::ERROR,"Error occured while saving the user");
}
$user->password = "";
$user = $this->baseService->cleanUpAdoDB($user);
if(!empty($this->emailSender)){
$usersEmailSender = new UsersEmailSender($this->emailSender, $this);
$usersEmailSender->sendWelcomeUserEmail($user, $password, $employee);
}
return new IceResponse(IceResponse::SUCCESS,$user);
}
return new IceResponse(IceResponse::ERROR, "Not Allowed");
}
private function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}