| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.DocUserMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.RSAUtil; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.UnknownAccountException; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | |
| | | int bl=mapper.delete(wrapper); |
| | | return new Response().setII(1,bl>0?true:false,bl,"删除返回"); |
| | | } |
| | | |
| | | public Response login(String name, String snId, HttpServletRequest request) { |
| | | Response response = new Response(); |
| | | String[] dataArr = RSAUtil.decryptFrontP(snId, RSAUtil.fontSeparator); |
| | | //验签md5 |
| | | if (!dataArr[1].equals(ActionUtil.EncryptionMD5(org.apache.commons.lang3.StringUtils.trim(dataArr[0])).toString())) { |
| | | return response.set(1, false, "密码验签失败"); |
| | | } |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(name, dataArr[0]); |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | try { |
| | | subject.login(userToken); |
| | | } catch (Exception e) { |
| | | if(e instanceof UnknownAccountException){ |
| | | return response.set(1,false,"账号不存在"); |
| | | } |
| | | return response.set(1,false,"密码错误"); |
| | | } |
| | | //登录成功 |
| | | //Session存储当前用户及权限组列表 |
| | | DocUser userDB = (DocUser) subject.getPrincipal(); |
| | | userDB.setSnId(null); |
| | | request.getSession().setAttribute("user", userDB); |
| | | return response.setII(1,true, userDB,"登录成功"); |
| | | } |
| | | } |