|
@@ -1,174 +0,0 @@
|
|
|
-package com.miekir.shibei.controller.api;
|
|
|
|
|
-
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
|
-import com.miekir.shibei.bean.PasswordBean;
|
|
|
|
|
-import com.miekir.shibei.bean.ResponseResult;
|
|
|
|
|
-import com.miekir.shibei.bean.ResultCode;
|
|
|
|
|
-import com.miekir.shibei.repository.PasswordRepository;
|
|
|
|
|
-import com.miekir.shibei.repository.UserRepository;
|
|
|
|
|
-import com.miekir.shibei.tool.TextUtils;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
-
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
-@Controller
|
|
|
|
|
-public class PasswordController {
|
|
|
|
|
-
|
|
|
|
|
- // 自动装配
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private PasswordRepository passwordRepository;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private UserRepository userRepository;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 新增密码记事,接收的是纯JSON数据 严格来说,也要传递id和token过来校验的
|
|
|
|
|
- */
|
|
|
|
|
- @RequestMapping(value = "/api/addPassword", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public String addPassword(String email, String token, String password_bean) {
|
|
|
|
|
- ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
|
|
- responseResult.setMessage("保存失败");
|
|
|
|
|
-
|
|
|
|
|
- PasswordBean bean;
|
|
|
|
|
- try {
|
|
|
|
|
- //bean = JSON.parseObject(password_bean, PasswordBean.class);
|
|
|
|
|
- bean = JSON.parseObject(password_bean, PasswordBean.class);
|
|
|
|
|
- bean.setUpdateTime(System.currentTimeMillis());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- PasswordBean dbPasswordBean;
|
|
|
|
|
- try {
|
|
|
|
|
- dbPasswordBean = passwordRepository.save(bean);
|
|
|
|
|
-
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- responseResult.setContent(JSON.toJSONString(dbPasswordBean));
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
- responseResult.setMessage("保存成功");
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 删除密码记事
|
|
|
|
|
- */
|
|
|
|
|
- @RequestMapping(value = "/api/delPassword", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public String delPassword(String email, String token, int passwordBeanId) {
|
|
|
|
|
- ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
|
|
- responseResult.setMessage("操作失败");
|
|
|
|
|
-
|
|
|
|
|
- PasswordBean dbPasswordBean;
|
|
|
|
|
- try {
|
|
|
|
|
- dbPasswordBean = passwordRepository.findPasswordBeanById(passwordBeanId);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 密码不属于该用户
|
|
|
|
|
- if (dbPasswordBean == null || !TextUtils.equals(email, dbPasswordBean.getUserId())) {
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- passwordRepository.delete(passwordBeanId);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
- responseResult.setMessage("删除成功");
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 查询密码记事
|
|
|
|
|
- */
|
|
|
|
|
- @RequestMapping(value = "/api/getPassword", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public String getPassword(String email, String token) {
|
|
|
|
|
- ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
|
|
- responseResult.setMessage("获取失败");
|
|
|
|
|
-
|
|
|
|
|
- List<PasswordBean> passwordBeanList;
|
|
|
|
|
- try {
|
|
|
|
|
- passwordBeanList = passwordRepository.findPasswordNotesByEmail(email);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- responseResult.setContent(JSON.toJSONString(passwordBeanList));
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
- responseResult.setMessage("获取成功");
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 更新密码记事
|
|
|
|
|
- */
|
|
|
|
|
- @RequestMapping(value = "/api/updatePassword", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public String updatePassword(String email, String token, String mixedPasswordBean) {
|
|
|
|
|
- ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
|
|
- responseResult.setMessage("更新失败");
|
|
|
|
|
-
|
|
|
|
|
- PasswordBean clientBean;
|
|
|
|
|
- try {
|
|
|
|
|
- //bean = JSON.parseObject(password_bean, PasswordBean.class);
|
|
|
|
|
- clientBean = JSON.parseObject(mixedPasswordBean, PasswordBean.class);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 发送方的用户和该记事的所有者不是同一个人,没有权限
|
|
|
|
|
- PasswordBean oldBean = passwordRepository.findPasswordBeanById(clientBean.getId());
|
|
|
|
|
- if (!TextUtils.equals(email, oldBean.getUserId())) {
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- passwordRepository.updatePasswordBean(clientBean.getPlatform(), clientBean.getUrl(), clientBean.getAccount(),
|
|
|
|
|
- clientBean.getPassword(), clientBean.getDescription(), clientBean.getId(), System.currentTimeMillis());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*try {
|
|
|
|
|
- responseResult.setResultObj(SecureManager.getInstance().encrypt(JSON.toJSONString(dbPasswordBean)));
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
- responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
- responseResult.setMessage("更新成功");
|
|
|
|
|
- return JSON.toJSONString(responseResult);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|