Skip to content

Commit

Permalink
fix and new featrue
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyouseea committed Jun 13, 2021
1 parent 8be20ae commit a524d7f
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 132 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>hqr</groupId>
<artifactId>o365</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<name>o365</name>
<description>Manage office 365</description>
<properties>
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/hqr/o365/ctrl/UserTabCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,15 @@ public String massCreateUser(@RequestParam(name="prefix") String prefix,

@ResponseBody
@RequestMapping(value = {"/deleteOfficeUser"}, method = RequestMethod.POST)
public boolean deleteUser(@RequestParam(name="uid") String uid) {
return dou.deleteUser(uid);
public String deleteUser(@RequestParam(name="uids") String uids) {
HashMap<String, int[]> map = dou.deleteUser(uids);
int [] overall = map.get("delete_res");

StringBuilder sb = new StringBuilder();
sb.append("用户删除成功:"+overall[0]+"<br>");
sb.append("用户删除失败:"+overall[1]+"<br>");

return sb.toString();
}

@ResponseBody
Expand All @@ -210,8 +217,22 @@ public String getOfficeUserDtls(@RequestParam(name="uid") String uid) {

@ResponseBody
@RequestMapping(value = {"/updateOfficeUser"}, method = RequestMethod.POST)
public boolean patchUser(@RequestParam(name="uid") String uid, @RequestParam(name="accountEnabled") String accountEnabled) {
return uou.patchOfficeUser(uid, accountEnabled);
public String patchUser(@RequestParam(name="uids") String uids, @RequestParam(name="accountEnabled") String accountEnabled) {
HashMap<String, int[]> map = uou.patchOfficeUser(uids, accountEnabled);

int [] overall = map.get("status_res");

StringBuilder sb = new StringBuilder();
if("true".equals(accountEnabled)) {
sb.append("用户启用成功:"+overall[0]+"<br>");
sb.append("用户启用失败:"+overall[1]+"<br>");
}
else {
sb.append("用户禁用成功:"+overall[0]+"<br>");
sb.append("用户禁用失败:"+overall[1]+"<br>");
}

return sb.toString();
}

@ResponseBody
Expand Down
55 changes: 37 additions & 18 deletions src/main/java/hqr/o365/service/DeleteOfficeUser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hqr.o365.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -28,9 +29,10 @@ public class DeleteOfficeUser {
@Value("${UA}")
private String ua;

public boolean deleteUser(String uid) {
boolean flag = false;

public HashMap<String, int[]> deleteUser(String uids) {
String uidArr[] = uids.split(",");
int succ = 0;
int fail = 0;
//get info
List<TaOfficeInfo> list = repo.getSelectedApp();
if(list!=null&&list.size()>0) {
Expand All @@ -39,26 +41,43 @@ public boolean deleteUser(String uid) {
if(vai.checkAndGet(ta.getTenantId(), ta.getAppId(), ta.getSecretId())) {
accessToken = vai.getAccessToken();
}

if(!"".equals(accessToken)) {
String endpoint = "https://graph.microsoft.com/v1.0/users/"+uid;
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.USER_AGENT, ua);
String body = "";
headers.add("Authorization", "Bearer "+accessToken);
HttpEntity<String> requestEntity = new HttpEntity<String>(body, headers);
try {
ResponseEntity<String> response = restTemplate.exchange(endpoint, HttpMethod.DELETE, requestEntity, String.class);
if(response.getStatusCodeValue()==204) {
flag =true;
for (String uid : uidArr) {
String endpoint = "https://graph.microsoft.com/v1.0/users/"+uid;
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.USER_AGENT, ua);
String body = "";
headers.add("Authorization", "Bearer "+accessToken);
HttpEntity<String> requestEntity = new HttpEntity<String>(body, headers);
try {
ResponseEntity<String> response = restTemplate.exchange(endpoint, HttpMethod.DELETE, requestEntity, String.class);
if(response.getStatusCodeValue()==204) {
succ ++;
}
else {
fail ++;
}
}
catch (Exception e) {
e.printStackTrace();
fail ++;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
else {
succ = 0;
fail = uidArr.length;
}
}
else {
succ = 0;
fail = uidArr.length;
}
return flag;

HashMap<String, int[]> map = new HashMap<String, int[]>();
int [] overall = new int[] {succ, fail};
map.put("delete_res", overall);
return map;
}

}
56 changes: 39 additions & 17 deletions src/main/java/hqr/o365/service/UpdateOfficeUser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hqr.o365.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -30,8 +31,11 @@ public class UpdateOfficeUser {
@Value("${UA}")
private String ua;

public boolean patchOfficeUser(String uid, String accountEnabled) {
boolean flag = false;
public HashMap<String, int[]> patchOfficeUser(String uids, String accountEnabled) {
String uidArr[] = uids.split(",");
int succ = 0;
int fail = 0;

List<TaOfficeInfo> list = repo.getSelectedApp();
if(list!=null&&list.size()>0) {
TaOfficeInfo ta = list.get(0);
Expand All @@ -41,26 +45,44 @@ public boolean patchOfficeUser(String uid, String accountEnabled) {
}

if(!"".equals(accessToken)) {
String endpoint = "https://graph.microsoft.com/v1.0/users/"+uid;
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.USER_AGENT, ua);
headers.add("Authorization", "Bearer "+accessToken);
headers.setContentType(MediaType.APPLICATION_JSON);
String body = "{\"accountEnabled\": \""+accountEnabled+"\"}";
HttpEntity<String> requestEntity = new HttpEntity<String>(body, headers);
try {
ResponseEntity<String> response= restTemplate.exchange(endpoint, HttpMethod.PATCH, requestEntity, String.class);
if(response.getStatusCodeValue()==204) {
flag =true;
for (String uid : uidArr) {
String endpoint = "https://graph.microsoft.com/v1.0/users/"+uid;
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.USER_AGENT, ua);
headers.add("Authorization", "Bearer "+accessToken);
headers.setContentType(MediaType.APPLICATION_JSON);
String body = "{\"accountEnabled\": \""+accountEnabled+"\"}";
HttpEntity<String> requestEntity = new HttpEntity<String>(body, headers);
try {
ResponseEntity<String> response= restTemplate.exchange(endpoint, HttpMethod.PATCH, requestEntity, String.class);
if(response.getStatusCodeValue()==204) {
succ ++;
}
else {
fail ++;
}
}
catch (Exception e) {
e.printStackTrace();
fail++;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
else {
succ = 0;
fail = uidArr.length;
}
}
else {
succ = 0;
fail = uidArr.length;
}

return flag;
HashMap<String, int[]> map = new HashMap<String, int[]>();
int [] overall = new int[] {succ, fail};
map.put("status_res", overall);

return map;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h2>欢迎来到O365管理系统,你可以使用它来方便的管理多个Off
<li>[用户]-><a href=javascript:addPanel("管理用户")>管理用户</a>页中,你可以添加(分配订阅),删除,批量创建,启用,禁用和搜索用户,你也可以提升一个用户为管理员或者撤销他的管理员权限</li>
<li>[用户]-><a href=javascript:addPanel("查看特权用户")>查看特权用户</a>页中,你可以查看身份是全局管理,用户管理,特权角色管理,特权认证管理的特殊用户</li>
<li>[许可证]-><a href=javascript:addPanel("查看许可证")>查看许可证</a>页中,你可查看以当前全局的许可证信息</li>
<li>[配置]-><a href=javascript:addPanel("Office配置")>Office配置</a>页中,你可以添加,修改,删除,切换全局,更新APP密钥,验证APP有效性</li>
<li>[配置]-><a href=javascript:addPanel("Office配置")>Office配置</a>页中,你可以添加,修改,删除,切换全局,更新APP密钥,验证APP有效性(<font color=red>不包含</font>权限的校验)</li>
<li>[配置]-><a href=javascript:addPanel("Office总览报告")>Office总览报告</a>页中,你可以查看Office配置中全局管理员的可用性报告</li>
<li>[配置]-><a href=javascript:addPanel("系统配置")>系统配置</a>页中,你可以查看或修改系统配置</li>
</ul>
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/tabs/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@
handler:function(){
$.messager.alert('帮助','<b>1.</b>请设置一个当前全局为是的全局<br>'+
'<b>2.</b>更新后的密钥结束日期为2099-12-31<br>' +
'<b>3.</b>更新密钥后,请等待1分钟之后再校验,否则可能会失败<br>','');
'<b>3.</b>更新密钥后,请等待1分钟之后再校验,否则可能会失败<br>'+
'<b>4.</b>校验只是对于租户ID,APPID和密钥ID正确性的校验,并<font color=red>不包含</font>权限的校验','');
}
}];

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/tabs/dialogs/massCreateUser.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
timeout:2000,
showType:'slide'
});
$('#dlg4').dialog('close');
$('#dlg5').dialog('close');
return;
}

Expand Down Expand Up @@ -136,10 +136,10 @@
}
});

$('#dlg4').dialog('close');
$('#dlg5').dialog('close');
}
function clearForm(){
$('#dlg4').dialog('close');
$('#dlg5').dialog('close');
}

function passwordGen() {
Expand Down
Loading

0 comments on commit a524d7f

Please sign in to comment.