public function actionGetRequestInfo() { if (Yii::app()->request->isAjaxRequest && isset($_POST['request_id']) ) { //get support_request info $sup_req = SupportRequests::model()->findByPk(intval($_POST['request_id'])); //get user questions $user = Users::model()->findByAttributes(array( 'User_Login'=>strval($_POST['login']), )); $user_id = $user->User_ID; $users_questions = UsersQuestions::getUserQuestions($user_id); $users_settings = UsersSettings::model()->findByAttributes(array( 'User_ID'=>$user_id )); $device= UsersDevices::model()->findByAttributes(array( 'Device_ID'=>$sup_req->User_Device_ID, 'Remote_Login'=>1 )); //return json to js $this->renderPartial('admin_side_view',array( 'sup_req'=>$sup_req, 'users_questions'=>$users_questions, 'device'=>$device, 'users_settings'=>$users_settings, 'user_id'=>$user_id )); } }
/** * Relogin user. * Not used yet. * @return boolean whether login is successful */ public function reloginByUid($user_id) { $user = Users::model()->findByPk($user_id); $user_devices = UsersDevices::model()->findByAttributes(array('User_ID'=>$user_id)); $user_login = $user->User_Login; $timezoneOffset = $user_devices->TymeZone; //$timezoneOffset = Yii::app()->user->userTimezoneOffset; //Yii::app()->user->logout(); if($this->_identity === null) { $this->_identity = new UserIdentity($user_login, 'temp100'); $this->_identity->reauthenticate($timezoneOffset); } if($this->_identity->errorCode === UserIdentity::ERROR_NONE) { $duration = $this->rememberMe ? 3600*24*30 : 0; // 30 days Yii::app()->user->login($this->_identity, $duration); return true; } else return false; }
echo '<input type="text" class="answer" name=answers['.$question['Question_ID'].'] value="'.$question['Hint'].'" autocomplete="off" >'; echo '<div class="input_error" style="display: none;color: #ff0000;font-size: 10px;">Value can\'t be empty! Value can contain only literal symbols and digits! </div>'; echo '<br/>'; $i++; echo '</div>'; } } ?> <button class="not_active_button" href="#" id="save_questions" style="padding:0px 6px;"> Save security questions </button> <br/><br/> </div> <br/> Your devices : <div class="devices" style="max-height: 465px;margin-top: 10px;overflow: auto;"> <?foreach (UsersDevices::getUsersDeviceList(Yii::app()->user->userID) as $device) {?> <div class="device-item" style="border: 1px solid #DDDDDD"> <div class="manage_link" style="float: right;padding-right: 5px; "> <a href="#" data-id="<?=$device['Hash']?>">Remove from trusted</a> </div> <table> <tr> <th>Last access</th> <td style="width: 265px;"> <?=$device['Lastlogin']; ?> </td> </tr> <tr> <th>Last location</th> <td style="width: 265px;"> <?=$device['IP']; ?> </td> </tr> <tr> <th>Device type</th> <td style="width: 265px;"> <?=$device['DeviceType']; ?> </td> </tr> <tr> <th>Hash</th> <td style="width: 265px;"> <?=$device['Hash']; ?> </td>
public static function getUsersDeviceList($user_id) { $devices = UsersDevices::model()->findAllByAttributes(array( 'User_ID'=>$user_id, )); $result = array(); foreach ($devices as $device) { $result [] = array( //'Lastlogin'=>date('Y-m-d h:i:s',$device->Last_Logged-$device->TymeZone), 'Lastlogin'=>Helper::convertDateFromIntClient($device->Last_Logged), 'LastloginServer'=>Helper::convertDateFromIntServer($device->Last_Logged), 'IP'=>$device->IP, 'DeviceType'=>$device->OS.' '.$device->Browser, 'Device_ID'=>$device->Device_ID, 'Mobile'=>$device->Mobile, 'Logged'=>$device->Logged, 'Hash'=>$device->MOB_Hash ); } return $result; }
/** * Authenticates a user. * Makes sure if the username and password * @param int $timezoneOffset * @return boolean whether authentication succeeds. */ public function authenticate($timezoneOffset = 0) { $user = Users::model()->getAuthenticateInfo($this->username,$this->password,UsersDevices::getDevHash('')); if(!empty($user->User_ID)) { $user->Last_IP = $_SERVER['REMOTE_ADDR']; $user->Last_Login = date("Y-m-d H:i:s"); $user->save(); // Set user info $this->setState('userInfo', $user->person->First_Name . ' ' . $user->person->Last_Name); $this->setState('userID', $user->User_ID); $this->setState('userLogin', $user->User_Login); $this->setState('userTimezoneOffset', $timezoneOffset); // get default client and project $default_client = false; $condition = new CDbCriteria(); $condition->condition = "users_project_list.User_ID = '" . $user->User_ID . "'"; $condition->addCondition("users_project_list.Project_ID = '" . $user->Default_Project . "'"); $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID"; $default_project = Projects::model()->with('client.company')->find($condition); if ($default_project) { $default_client = $default_project->client; } else { $settings = $user->settings; $settings->scenario = 'newClientScenario'; $settings->Default_Project = 0; $settings->save(); $condition = new CDbCriteria(); $condition->condition = "users_project_list.User_ID = '" . $user->User_ID . "'"; $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID"; $default_project = Projects::model()->with('client.company')->find($condition); if ($default_project) { $user->Default_Project = $default_project->Project_ID; $user->save(); $default_client = $default_project->client; } else { $user->Default_Project = 0; $user->save(); } } // get client $client = false; foreach ($user->clients as $cl) { if ($cl->Client_ID == $default_client->Client_ID) { $client = $cl; break; } else { $client = $cl; } } if ($client) { $this->setState('clientInfo', $client->company->Company_Name); $this->setState('clientID', $client->Client_ID); $projects = UsersProjectList::model()->with('project')->findAllByAttributes(array( 'User_ID' =>$user->User_ID, 'Client_ID' =>$client->Client_ID, )); if ($default_project) { $project = $default_project; $this->setState('projectInfo', $project->Project_Name); $this->setState('projectID', $project->Project_ID); $this->errorCode=self::ERROR_NONE; } else if ($projects) { $project = $projects[0]; $this->setState('projectInfo', $project->project->Project_Name); $this->setState('projectID', $project->Project_ID); $this->errorCode=self::ERROR_NONE; } else { $this->setState('projectInfo', 'No project'); $this->setState('projectID', 0); $this->errorCode=self::ERROR_UNKNOWN_IDENTITY; } //set user's tier settings //check for delayed settings DelayedClientServiceSettings::checkDate(date('Y-m-d'),$client->Client_ID); $user_client_settings = $client->service_settings; $user_tier_settings = TiersSettings::agregateTiersSettings($user_client_settings->Service_Level_ID); $this->setState('tier_settings', $user_tier_settings); $userClientRelation = UsersClientList::model()->findByAttributes(array( 'User_ID' =>$user->User_ID, 'Client_ID' =>$client->Client_ID, )); // set user type from user-client relation if ($userClientRelation->User_Type == UsersClientList::CLIENT_ADMIN) { $this->username = '******'; } else if ($userClientRelation->User_Type == UsersClientList::APPROVER) { $this->username = '******'; } else if ($userClientRelation->User_Type == UsersClientList::PROCESSOR) { $this->username = '******'; } else if ($userClientRelation->User_Type == UsersClientList::USER) { $this->username = '******'; } else { $this->username = '******'; } // reset user type if he id Admin, DB Admin OR DEC if ($user->User_Type == Users::ADMIN) { $this->username = '******'; } else if ($user->User_Type == Users::DB_ADMIN) { $this->username = '******'; } else if ($user->User_Type == Users::DATA_ENTRY_CLERK) { $this->username = '******'; } if ($user->User_Type == Users::USER) { $this->setState('userType', $userClientRelation->User_Type); } else { $this->setState('userType', $user->User_Type); } } else { $this->setState('clientInfo', 'No company'); $this->setState('clientID', 0); $this->setState('projectInfo', 'No project'); $this->setState('userType', 'Single User'); $this->setState('projectID', 0); $this->username = '******'; $this->errorCode=self::ERROR_NONE; } UserLog::createLogRecord($user->User_ID, '', 0, 0); } return !$this->errorCode; }