44import info .xiaomo .core .exception .UserNotFoundException ;
55import info .xiaomo .core .model .AdminModel ;
66import info .xiaomo .core .service .AdminUserService ;
7+ import info .xiaomo .core .untils .MD5 ;
78import org .springframework .beans .factory .annotation .Autowired ;
89import org .springframework .data .domain .Page ;
910import org .springframework .data .domain .PageRequest ;
10- import org .springframework .web .bind .annotation .PathVariable ;
11- import org .springframework .web .bind .annotation .RequestMapping ;
12- import org .springframework .web .bind .annotation .RequestParam ;
13- import org .springframework .web .bind .annotation .RestController ;
11+ import org .springframework .web .bind .annotation .*;
1412
1513import java .util .HashMap ;
1614import java .util .Map ;
@@ -44,14 +42,14 @@ public class AdminUserController extends BaseController {
4442 @ Autowired
4543 AdminUserService service ;
4644
47- @ RequestMapping ("login" )
45+ @ RequestMapping (value = "login" , method = RequestMethod . POST )
4846 public Map <String , Object > login (@ RequestParam String userName , @ RequestParam String password ) {
4947 HashMap <String , java .lang .Object > result = new HashMap <>();
5048 AdminModel adminModel = service .findAdminUserByUserName (userName );
5149 if (adminModel == null ) {
5250 result .put (code , notFound );
5351 } else {
54- if (password .equals (adminModel .getPassword ())) {
52+ if (MD5 . encode ( password ) .equals (adminModel .getPassword ())) {
5553 result .put (code , success );
5654 result .put ("adminUser" , adminModel );
5755 } else {
@@ -61,7 +59,7 @@ public Map<String, Object> login(@RequestParam String userName, @RequestParam St
6159 return result ;
6260 }
6361
64- @ RequestMapping ("findById/{id}" )
62+ @ RequestMapping (value = "findById/{id}" , method = RequestMethod . GET )
6563 public HashMap <String , Object > findUserById (@ PathVariable ("id" ) Long id ) {
6664 HashMap <String , Object > result = new HashMap <>();
6765 AdminModel adminModel = service .findAdminUserById (id );
@@ -76,7 +74,7 @@ public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
7674 }
7775
7876
79- @ RequestMapping ("findAll/{start}/{pageSize}" )
77+ @ RequestMapping (value = "findAll/{start}/{pageSize}" , method = RequestMethod . GET )
8078 public HashMap <String , Object > getAll (@ PathVariable ("start" ) int start , @ PathVariable ("pageSize" ) int page ) {
8179 HashMap <String , Object > result = new HashMap <>();
8280 Page <AdminModel > pages = service .getAdminUsers (new PageRequest (start - 1 , page ));
@@ -98,11 +96,11 @@ public HashMap<String, Object> deleteUserById(@PathVariable("id") Long id) throw
9896 return result ;
9997 }
10098
101- @ RequestMapping ("update/{userName}/{password}/{authLevel}" )
99+ @ RequestMapping (value = "update" , method = RequestMethod . POST )
102100 public HashMap <String , Object > update (
103- @ PathVariable ("userName" ) String userName ,
104- @ PathVariable ("password" ) String password ,
105- @ PathVariable ("authLevel" ) int authLevel
101+ @ RequestParam ("userName" ) String userName ,
102+ @ RequestParam ("password" ) String password ,
103+ @ RequestParam ("authLevel" ) int authLevel
106104 ) {
107105 HashMap <String , Object > result = new HashMap <>();
108106 AdminModel adminModel = service .findAdminUserByUserName (userName );
@@ -118,7 +116,7 @@ public HashMap<String, Object> update(
118116 return result ;
119117 }
120118
121- @ RequestMapping ("forbid/{id}" )
119+ @ RequestMapping (value = "forbid/{id}" , method = RequestMethod . GET )
122120 public HashMap <String , Object > forbid (@ PathVariable ("id" ) Long id ) throws UserNotFoundException {
123121 HashMap <String , Object > result = new HashMap <>();
124122 AdminModel model = service .findAdminUserById (id );
@@ -127,7 +125,7 @@ public HashMap<String, Object> forbid(@PathVariable("id") Long id) throws UserNo
127125 } else {
128126 model = service .forbidAdminUserById (id );
129127 result .put (code , success );
130- result .put ("user " , model );
128+ result .put ("adminUser " , model );
131129 }
132130 return result ;
133131 }
0 commit comments