protected function beforeAction($action)
 {
     $controller = Yii::app()->controller->id;
     $action = Yii::app()->controller->action->id;
     if ($controller == "site" && $action == "login") {
         return TRUE;
     }
     if ($controller == "site" && $action == "logout") {
         return TRUE;
     }
     if (Yii::app()->user == NULL) {
         $this->redirect(Yii::app()->request->baseUrl . "/site/login");
     } else {
         if (Yii::app()->user->getId() != NULL) {
             $log = new UserLog();
             $log->time = date("Y-m-d H:i:s");
             $log->user_id = Yii::app()->user->id;
             $log->user_level_id = Yii::app()->user->level_id;
             $log->path = $_SERVER["REQUEST_URI"];
             $log->data = json_encode($_POST);
             $log->is_ajax = 0;
             if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                 $log->is_ajax = 1;
             }
             $log->save();
             return TRUE;
         } else {
             $this->redirect(Yii::app()->request->baseUrl . "/site/login");
         }
     }
 }
Пример #2
0
 public static function afterLogin($e)
 {
     $ip = \Yii::$app->request->getUserIP();
     $log = UserLog::findByIp($ip);
     if (!$log) {
         $log = new UserLog();
         $log->ip = $ip;
     } else {
         $log->logincount += 1;
     }
     $log->userAgent = \Yii::$app->request->getUserAgent();
     $log->lastvisit = time();
     $log->save(false);
 }
Пример #3
0
 public static function createUserLog($params)
 {
     $resultInfo = array();
     $userLog = new UserLog();
     $userLog->attributes = $params;
     if (!$userLog->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $userLog->getErrors();
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         $resultInfo['detail'] = array('id' => $userLog->id);
     }
     return $resultInfo;
 }
Пример #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     if (!Auth::check()) {
         // Custom for required fields.
         if (empty(Input::get('username')) || empty(Input::get('password'))) {
             Session::flash('message', 'Please input your credentials.');
             return Redirect::to('api');
         } else {
             if (Auth::attempt(array('username' => Input::get('username'), 'password' => Input::get('password')))) {
                 // Save to user_log table
                 $id = Auth::id();
                 $log = new UserLog();
                 $log->user_id = $id;
                 $log->login = date('Y-m-d H:i:s');
                 $log->save();
                 // End
                 Session::put('log_id', $log->id);
                 $option = Input::get('option');
                 if ($option == 'crud') {
                     return Redirect::to('crud');
                 } else {
                     return Redirect::to('api');
                 }
             } else {
                 Session::flash('message', 'Invalid credentials.');
                 return Redirect::back();
             }
         }
     } else {
         if (!$this->user->isValid($input = Input::all())) {
             return Redirect::back()->withInput()->withErrors($this->user->error);
         } else {
             $this->user->create($input);
             Session::flash('message', 'Successfully added user.');
             return Redirect::to("api");
         }
     }
 }
 protected function beforeAction($action)
 {
     $controller = Yii::app()->controller->id;
     $action = Yii::app()->controller->action->id;
     if ($controller == "site" && $action == "login") {
         return TRUE;
     }
     if ($controller == "notFound") {
         return TRUE;
     }
     /*if(Yii::app()->user->level != NULL){
           $module = Module::model()->findByAttributes(array("controller"=>$controller));
           $hakAkses = HakAkses::model()->findByAttributes(array("module_id"=>$module->id, "user_level_id"=>Yii::app()->user->level));
           if($hakAkses == NULL){
               //throw new CHttpException(404, 'Halaman Tidak Ditemukan.');
               $this->redirect(Yii::app()->request->baseUrl . "/notFound/");
               return FALSE;
           }
           
       }*/
     if (Yii::app()->user == NULL) {
         $this->redirect(Yii::app()->request->baseUrl . "/site/login");
     } else {
         if (Yii::app()->user->getId() != NULL) {
             $log = new UserLog();
             $log->time = date("Y-m-d H:i:s");
             $log->user_id = Yii::app()->user->id;
             $log->user_level_id = Yii::app()->user->level_id;
             $log->path = $_SERVER["REQUEST_URI"];
             $log->data = json_encode($_POST);
             $log->is_ajax = 0;
             if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                 $log->is_ajax = 1;
             }
             $log->save();
             return TRUE;
         } else {
             $this->redirect(Yii::app()->request->baseUrl . "/site/login");
         }
     }
 }
Пример #6
0
 public function deleteSoftwareType($id)
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         if (!is_numeric($id) || !SoftwareType::find($id)) {
             return Redirect::to("settings/assets/softwaretypes");
         } else {
             if (count(SoftwareType::find($id)->softwareassets) > 0) {
                 return Redirect::to("settings/assets/softwaretypes");
             }
         }
         $softwareType = SoftwareType::find($id);
         $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted software type <strong>" . $softwareType->software_type . "</strong>.";
         //Log the changes made
         $newLog = new UserLog();
         $newLog->description = $desc;
         $newLog->user_id = Session::get('user_id');
         $newLog->type = "System";
         $newLog->save();
         $softwareType->delete();
         return Redirect::to("settings/assets/softwaretypes");
     } else {
         return Redirect::to("/");
     }
 }
Пример #7
0
 public function deleteAssets()
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         $ip = Input::get("ip_id");
         $hasDeletedAny = false;
         $noOfDeletedAssets = 0;
         foreach ($ip as $s) {
             $ip = IP::find($s);
             if (!$ip) {
                 continue;
             }
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted IP asset ( type: " . $ip->type . ") <strong>" . $ip->ip . "</strong>.";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
             $hasDeletedAny = true;
             $noOfDeletedAssets += 1;
             $ip->delete();
         }
         if ($hasDeletedAny) {
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted <strong>" . $noOfDeletedAssets . "</strong> IP asset(s).";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
         }
         return Redirect::to(Session::get("page"));
     } else {
         return Redirect::to("/");
     }
 }
Пример #8
0
 public function deleteAssets()
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         $assets = Input::get("asset_id");
         $hasDeletedAny = false;
         $noOfDeletedAssets = 0;
         foreach ($assets as $a) {
             $asset = Asset::where("id", "=", $a)->whereHas("classification", function ($query) {
                 $query->where("type", "=", "Network");
             })->first();
             if (!$asset) {
                 continue;
             }
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted network asset ( type: " . $asset->classification->name . ")  <strong>" . $asset->asset_tag . "</strong>, SN: <strong>" . $asset->serial_number . "</strong>.";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
             $hasDeletedAny = true;
             $noOfDeletedAssets += 1;
             $asset->delete();
         }
         if ($hasDeletedAny) {
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted <strong>" . $noOfDeletedAssets . "</strong> network asset(s).";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
         }
         return Redirect::to(Session::get("page"));
     } else {
         return Redirect::to("/");
     }
 }
Пример #9
0
 public function saveUserLog($unique_id, $session_id, $user_id, $employee_id, $username, $login_time = null, $logout_time = null)
 {
     $model = new UserLog();
     $model->unique_id = $unique_id;
     $model->sessoin_id = $session_id;
     $model->user_id = $user_id;
     $model->employee_id = $employee_id;
     $model->login_time = $login_time;
     $model->logout_time = $logout_time;
     $model->modified_by = $username;
     $model->save();
 }
Пример #10
0
 /**
  * function ->delete ()
  */
 public function delete()
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = $this;
     if ($log = new UserLog()) {
         $log->username = $username;
         $log->action = 'Delete';
         $log->object_class = 'GeneralInfoTranslation';
         $log->object_pk = $model->id;
         $log->created_at = $now;
         $log->is_success = 0;
         $log->save();
     }
     if (parent::delete()) {
         if ($log) {
             $log->is_success = 1;
             $log->save();
         }
         return true;
     }
     return false;
 }
Пример #11
0
 /**
  * function ->delete ()
  */
 public function delete()
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = $this;
     if ($log = new UserLog()) {
         $log->username = $username;
         $log->action = "Delete ProductCategoryTranslation, id = {$model->id}";
         $log->created_at = $now;
         $log->type = 3;
         $log->is_success = 0;
         $log->save();
     }
     if (parent::delete()) {
         if ($log) {
             $log->is_success = 1;
             $log->save();
         }
         return true;
     }
     return false;
 }
Пример #12
0
 public function deleteEmployee()
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         $employees = Input::get("employee_id");
         $hasDeletedAny = false;
         $noOfDeletedEmployees = 0;
         foreach ($employees as $e) {
             $employee = Employee::find($e);
             if (!$employee) {
                 continue;
             }
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted employee <strong>" . $employee->first_name . " " . $employee->last_name . " (Employee #: " . $employee->employee_number . ") </strong>.";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "Employees";
             $newLog->save();
             $hasDeletedAny = true;
             $noOfDeletedEmployees += 1;
             $employee->delete();
         }
         if ($hasDeletedAny) {
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted <strong>" . $noOfDeletedEmployees . "</strong> employee(s).";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "Employees";
             $newLog->save();
         }
         return Redirect::to(Session::get("page"));
     } else {
         return Redirect::to("/");
     }
 }
Пример #13
0
 public function resetPassword()
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         $input = Input::all();
         $validator = Validator::make(array("username" => $input["username"], "new_password" => $input["new_password"], "new_password2" => $input["new_password2"], "root_password" => $input["root_password"]), array("username" => "required|alpha_dash|exists:tbl_user_accounts,username", "new_password" => "required|min:8", "new_password2" => "required|min:8", "root_password" => "required"));
         if ($validator->fails()) {
             Input::flash();
             return Redirect::to('accounts/passwordmanager')->with('message', $validator->messages()->first());
         } else {
             if (!Auth::attempt(array('username' => Session::get('username'), 'password' => $input['root_password']))) {
                 Input::flash();
                 return Redirect::to('accounts/passwordmanager')->with('message', "Invalid root password. Try again.");
             } else {
                 if ($input["new_password"] != $input["new_password2"]) {
                     Input::flash();
                     return Redirect::to('accounts/passwordmanager')->with('message', "New passwords didn't match. Try again.");
                 } else {
                     $user = User::where("username", "=", $input["username"])->first();
                     if ($user->user_type == "Root") {
                         Input::flash();
                         return Redirect::to('accounts/passwordmanager')->with('message', "Cannot reset password of root administrator accounts.");
                     }
                     $user->password = Hash::make(trim($input["new_password"]));
                     $user->save();
                     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has reset the password of <strong>" . $user->username . "</strong>.";
                     //Log the changes made
                     $newLog = new UserLog();
                     $newLog->description = $desc;
                     $newLog->user_id = Session::get('user_id');
                     $newLog->type = "System";
                     $newLog->save();
                     return Redirect::to('accounts/passwordmanager')->with('success', "User <b>" . $input['username'] . "'s</b> password has been changed. ");
                 }
             }
         }
     } else {
         return Redirect::to('/');
     }
 }
Пример #14
0
 public function osImage()
 {
     $user = Input::get('userid');
     $status = Input::get('function_params');
     $assettag = Input::get('assettag');
     DB::table('tbl_assets')->where('id', $user)->update(array('image' => $status));
     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has updated client asset <strong>" . $assettag . "'s</strong> information. These are the fields that have been modified:<br/>" . "1.) image to " . $status;
     //Log the changes made
     $newLog = new UserLog();
     $newLog->description = $desc;
     $newLog->user_id = Session::get('user_id');
     $newLog->type = "System";
     $newLog->save();
     //Parallel logging to asset logs
     $assetLog = new AssetLog();
     $assetLog->asset_id = $user;
     $assetLog->user_id = Session::get("user_id");
     $assetLog->description = $desc;
     $assetLog->transaction = "Updates";
     $assetLog->save();
     return Redirect::to("assets/client/view/laptops");
 }
Пример #15
0
 /**
  * Creates new record in Users' log
  * @param $userId
  * @param $tableName
  * @param $rowId
  * @param $eventType
  */
 public static function createLogRecord($userId, $tableName, $rowId, $eventType)
 {
     $userEvent = new UserLog();
     $userEvent->Date_Time = date("Y-m-d H:i:s");
     $userEvent->Event_Type = $eventType;
     $userEvent->ROW_ID = $rowId;
     $userEvent->Table_Name = $tableName;
     $userEvent->User_ID = $userId;
     $userEvent->save();
 }