Added the ability to set the API key description #287
这个提交包含在:
		
							父节点
							
								
									b78259313a
								
							
						
					
					
						当前提交
						a62764e69d
					
				
					共有  5 个文件被更改,包括 106 次插入 和 0 次删除
				
			
		|  | @ -57,6 +57,44 @@ class API extends CI_Controller { | ||||||
| 		$this->load->view('interface_assets/footer'); | 		$this->load->view('interface_assets/footer'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 	function edit($key) { | ||||||
|  | 		$this->load->model('user_model'); | ||||||
|  | 		 | ||||||
|  | 		if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } | ||||||
|  | 
 | ||||||
|  | 		$this->load->model('api_model'); | ||||||
|  | 
 | ||||||
|  | 		$this->load->helper(array('form', 'url')); | ||||||
|  | 
 | ||||||
|  |         $this->load->library('form_validation'); | ||||||
|  | 
 | ||||||
|  |         $this->form_validation->set_rules('api_desc', 'API Description', 'required'); | ||||||
|  |         $this->form_validation->set_rules('api_key', 'API Key is required do not change this field', 'required'); | ||||||
|  | 
 | ||||||
|  |         $data['api_info'] = $this->api_model->key_description($key); | ||||||
|  | 
 | ||||||
|  |         if ($this->form_validation->run() == FALSE) | ||||||
|  |         { | ||||||
|  |   	      	$data['page_title'] = "Edit API Description"; | ||||||
|  | 
 | ||||||
|  | 			$this->load->view('interface_assets/header', $data); | ||||||
|  | 			$this->load->view('api/description'); | ||||||
|  | 			$this->load->view('interface_assets/footer'); | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			// Success!
 | ||||||
|  | 
 | ||||||
|  | 			$this->api_model->update_key_description($this->input->post('api_key'), $this->input->post('api_desc')); | ||||||
|  | 
 | ||||||
|  | 			$this->session->set_flashdata('notice', 'API Key <b>'.$this->input->post('api_key')."</b> description has been updated."); | ||||||
|  | 
 | ||||||
|  | 			redirect('api/help'); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	function generate($rights) { | 	function generate($rights) { | ||||||
| 		$this->load->model('user_model'); | 		$this->load->model('user_model'); | ||||||
| 		if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } | 		if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } | ||||||
|  |  | ||||||
|  | @ -19,6 +19,25 @@ class API_Model extends CI_Model { | ||||||
|     	return $this->db->get('api'); |     	return $this->db->get('api'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     function key_description($key) { | ||||||
|  |     	$this->db->where('key', $key);  | ||||||
|  |     	$query = $this->db->get('api'); | ||||||
|  | 
 | ||||||
|  |     	return $query->result_array()[0]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     function update_key_description($key, $description) { | ||||||
|  |     	 | ||||||
|  |     	$data = array( | ||||||
|  |         'description' => $description, | ||||||
|  | 		); | ||||||
|  | 
 | ||||||
|  | 		$this->db->where('key', $key); | ||||||
|  | 		$this->db->update('api', $data); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     function delete_key($key) { |     function delete_key($key) { | ||||||
|     	$this->db->where('key', $key); |     	$this->db->where('key', $key); | ||||||
| 		$this->db->delete('api'); | 		$this->db->delete('api'); | ||||||
|  |  | ||||||
|  | @ -0,0 +1,40 @@ | ||||||
|  | <div class="container api"> | ||||||
|  | 
 | ||||||
|  | <br> | ||||||
|  | <?php if($this->session->flashdata('notice')) { ?>
 | ||||||
|  | <div class="alert alert-success" role="alert"> | ||||||
|  | 	<?php echo $this->session->flashdata('notice'); ?>
 | ||||||
|  | </div> | ||||||
|  | <?php } ?>
 | ||||||
|  | 
 | ||||||
|  | <div class="card"> | ||||||
|  |   <div class="card-header"> | ||||||
|  |     <?php echo $page_title; ?>
 | ||||||
|  |   </div> | ||||||
|  |   <div class="card-body"> | ||||||
|  |     <h5 class="card-title">Editing Description for API Key: <?php echo $api_info['key']; ?></h5>
 | ||||||
|  | 
 | ||||||
|  | <?php if(validation_errors()) { ?>
 | ||||||
|  | <div class="alert alert-warning" role="alert"> | ||||||
|  |   <?php echo validation_errors(); ?>
 | ||||||
|  | </div> | ||||||
|  | <?php } ?>
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	<form method="post" action="<?php echo site_url('api/edit'); ?>/<?php echo $api_info['key']; ?>" name="APIDescription"> | ||||||
|  | 	  <div class="form-group"> | ||||||
|  | 	    <label for="APIDescription">API Description</label> | ||||||
|  | 	    <input type="text" class="form-control" name="api_desc" id="APIDescription" aria-describedby="APIDescriptionHelp" value="<?php echo $api_info['description']; ?>"> | ||||||
|  | 	    <small id="APIDescriptionHelp" class="form-text text-muted">Simple name to describle what you use this API for.</small> | ||||||
|  | 	  </div> | ||||||
|  | 
 | ||||||
|  | 	  <input type="hidden" name="api_key" value="<?php echo $api_info['key']; ?>"> | ||||||
|  | 
 | ||||||
|  | 	  <button type="submit" class="btn btn-primary">Submit</button> | ||||||
|  | 	</form> | ||||||
|  | 
 | ||||||
|  |   </div> | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | @ -21,6 +21,7 @@ | ||||||
| 		  <thead> | 		  <thead> | ||||||
| 		    <tr> | 		    <tr> | ||||||
| 		      <th scope="col">API Key</th> | 		      <th scope="col">API Key</th> | ||||||
|  | 		      <th scope="col">Description</th> | ||||||
| 		      <th scope="col">Rights</th> | 		      <th scope="col">Rights</th> | ||||||
| 		      <th scope="col">Status</th> | 		      <th scope="col">Status</th> | ||||||
| 		    </tr> | 		    </tr> | ||||||
|  | @ -29,6 +30,7 @@ | ||||||
| 			<?php foreach ($api_keys->result() as $row) { ?>
 | 			<?php foreach ($api_keys->result() as $row) { ?>
 | ||||||
| 				<tr> | 				<tr> | ||||||
| 					<td><?php echo $row->key; ?></td>
 | 					<td><?php echo $row->key; ?></td>
 | ||||||
|  | 					<td><?php echo $row->description; ?></td>
 | ||||||
| 					<td> | 					<td> | ||||||
| 						<?php | 						<?php | ||||||
| 							 | 							 | ||||||
|  | @ -44,6 +46,9 @@ | ||||||
| 
 | 
 | ||||||
| 					</td> | 					</td> | ||||||
| 					<td><span class="badge badge-pill badge-light"><?php echo ucfirst($row->status); ?></span>
 | 					<td><span class="badge badge-pill badge-light"><?php echo ucfirst($row->status); ?></span>
 | ||||||
|  | 
 | ||||||
|  | 						<a href="<?php echo site_url('api/edit'); ?>/<?php echo $row->key; ?>" class="btn btn-outline-primary btn-sm">Edit</a> | ||||||
|  | 
 | ||||||
| 						<a href="<?php echo site_url('api/auth/'.$row->key); ?>" target="_blank" class="btn btn-primary btn-sm">Test</a> | 						<a href="<?php echo site_url('api/auth/'.$row->key); ?>" target="_blank" class="btn btn-primary btn-sm">Test</a> | ||||||
| 
 | 
 | ||||||
| 						<a href="<?php echo site_url('api/delete/'.$row->key); ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want delete API Key <?php echo $row->key; ?>?');">Delete</a> | 						<a href="<?php echo site_url('api/delete/'.$row->key); ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want delete API Key <?php echo $row->key; ?>?');">Delete</a> | ||||||
|  |  | ||||||
|  | @ -46,6 +46,10 @@ | ||||||
|     margin-bottom: 0rem; |     margin-bottom: 0rem; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | .api .alert p { | ||||||
|  |     margin-bottom: 0rem; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| .qso_panel { | .qso_panel { | ||||||
|     padding-top: 25px; |     padding-top: 25px; | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用