|
@@ -0,0 +1,86 @@ |
|
|
|
|
|
package cc.smtweb.system.bpm.web.login; |
|
|
|
|
|
|
|
|
|
|
|
import cc.smtweb.framework.core.annotation.*; |
|
|
|
|
|
import cc.smtweb.framework.core.common.R; |
|
|
|
|
|
import cc.smtweb.framework.core.session.SessionManager; |
|
|
|
|
|
import cc.smtweb.framework.core.session.UserSession; |
|
|
|
|
|
import cc.smtweb.framework.core.db.DbEngine; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils; |
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
|
@SwService |
|
|
|
|
|
public class AuthService { |
|
|
|
|
|
@SwParam |
|
|
|
|
|
private DbEngine dbEngine; |
|
|
|
|
|
|
|
|
|
|
|
@SwParam |
|
|
|
|
|
private SessionManager sessionManager; |
|
|
|
|
|
|
|
|
|
|
|
@SwPerm(SwPerm.NONE) |
|
|
|
|
|
public R login(@SwBody LoginVO loginPO) { |
|
|
|
|
|
if (StringUtils.isBlank(loginPO.getUsername())) { |
|
|
|
|
|
return R.error("账号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(loginPO.getPassword())) { |
|
|
|
|
|
return R.error("密码不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UserPO user = dbEngine.queryEntity("select user_id,user_nick_name,user_nick_code,user_pwd,user_create_party_id from sw_user.sys_user where user_nick_code=?", UserPO.class, loginPO.getUsername()); |
|
|
|
|
|
|
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
return R.error("账号不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// digest:md5("goodpj" + user.userId + password) |
|
|
|
|
|
String pass = DigestUtils.md5Hex("goodpj" + user.getUserId() + loginPO.getPassword()); |
|
|
|
|
|
|
|
|
|
|
|
if (!pass.equals(user.getUserPwd())) { |
|
|
|
|
|
return R.error("账号或者密码出错"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UserSession userSession = new UserSession(); |
|
|
|
|
|
userSession.setUserId(user.getUserId()); |
|
|
|
|
|
userSession.setSiteId(user.getUserCreatePartyId()); |
|
|
|
|
|
|
|
|
|
|
|
String token = sessionManager.login(userSession); |
|
|
|
|
|
|
|
|
|
|
|
LoginAckVO data = new LoginAckVO(); |
|
|
|
|
|
|
|
|
|
|
|
data.setUserId(user.getUserId()); |
|
|
|
|
|
data.setUserName(user.getUserNickName()); |
|
|
|
|
|
data.setUserAvatar(user.getUserAvatar()); |
|
|
|
|
|
data.setToken(token); |
|
|
|
|
|
|
|
|
|
|
|
return R.success(data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SwPerm() |
|
|
|
|
|
public R ping(@SwParam("msg") String msg) { |
|
|
|
|
|
return R.success(msg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SwPerm("user:edit") |
|
|
|
|
|
public R config(@SwParam("username") String username) { |
|
|
|
|
|
return R.success("config: " + username); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 退出登录 |
|
|
|
|
|
* @return code |
|
|
|
|
|
*/ |
|
|
|
|
|
public R logout() { |
|
|
|
|
|
sessionManager.logout(); |
|
|
|
|
|
return R.success(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// defaultRun 命名的函数是默认函数 |
|
|
|
|
|
// @SwPerm(SwPerm.NONE) |
|
|
|
|
|
// public R defaultRun(@SwPathParam String path) { |
|
|
|
|
|
// return R.success(path).put("dao", authDao); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
} |