|
@@ -0,0 +1,90 @@
|
|
|
+package cn.efunbox.audio.controller;
|
|
|
+
|
|
|
+import cn.efunbox.audio.entity.Admin;
|
|
|
+import cn.efunbox.audio.entity.Channel;
|
|
|
+import cn.efunbox.audio.service.AdminService;
|
|
|
+import cn.efunbox.audio.service.ChannelService;
|
|
|
+import cn.efunbox.audio.util.ApiCode;
|
|
|
+import cn.efunbox.audio.util.Common;
|
|
|
+import cn.efunbox.audio.util.HttpUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.tomcat.util.security.MD5Encoder;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import sun.security.provider.MD5;
|
|
|
+import sun.security.rsa.RSASignature;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by yao on 17-9-26.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+@RequestMapping(value = "/admin")
|
|
|
+public class AdminController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AdminService adminService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/login" ,method = RequestMethod.POST)
|
|
|
+ public void Search(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ String name = request.getParameter("name");
|
|
|
+ String pwd = request.getParameter("pwd");
|
|
|
+ if(name==null && pwd==null){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Admin> list = adminService.SearchByName(name);
|
|
|
+ if(list==null || list.size()<1){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Admin admin = list.get(0);
|
|
|
+ String pwdMD5 = Common.getMD5(Common.getMD5(pwd)+admin.getSalt());
|
|
|
+// System.out.println(pwdMD5);
|
|
|
+// System.out.println(admin.getPwd());
|
|
|
+ if(pwdMD5.equalsIgnoreCase(admin.getPwd()))
|
|
|
+ HttpUtil.responseOk(request, response);
|
|
|
+ else
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.INVALID_TOKEN);
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/register", method = RequestMethod.POST)
|
|
|
+ public void Insert(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ String name = request.getParameter("name");
|
|
|
+ String pwd = request.getParameter("pwd");
|
|
|
+ String idChannel = request.getParameter("idChannel");
|
|
|
+ if(name==null || name.length()<4 || pwd==null || pwd.length()<4){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.PARAMETER_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(idChannel==null || idChannel.length()==0)
|
|
|
+ idChannel = "0";
|
|
|
+ String salt = UUID.randomUUID().toString().substring(0, 16);
|
|
|
+ String pwdMD5 = Common.getMD5(Common.getMD5(pwd) + salt);
|
|
|
+
|
|
|
+ List<Admin> list = adminService.SearchByName(name);
|
|
|
+ if(list!=null && list.size()>0){
|
|
|
+ HttpUtil.responseApiCode(request, response, ApiCode.RECORD_EXIST);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Admin admin = new Admin();
|
|
|
+ admin.setName(name);
|
|
|
+ admin.setPwd(pwdMD5);
|
|
|
+ admin.setSalt(salt);
|
|
|
+ admin.setIdChannel(Long.valueOf(idChannel));
|
|
|
+ admin = adminService.Insert(admin);
|
|
|
+
|
|
|
+ HttpUtil.responseOutWithJson(request, response, admin);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|