..
This commit is contained in:
+1
-1
@@ -85,7 +85,7 @@ public class ClientAuthController {
|
||||
@ApiOperation(value = "短信登录", nickname = "/sms-login", httpMethod = "POST")
|
||||
public Object doSmsLogin(ClientLoginBody loginBody, HttpServletRequest req) {
|
||||
try {
|
||||
String token = clientAuthService.doSmsLogin(loginBody);
|
||||
String token = clientAuthService.doLogin(loginBody);
|
||||
return Result.success().addData(token);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
||||
@@ -48,6 +48,16 @@ public class Client_user extends BaseModel implements Serializable {
|
||||
@Comment("单位ID")
|
||||
private String unitId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
@Comment("密码")
|
||||
private String password;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
@Comment("盐")
|
||||
private String salt;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
@Comment("openId")
|
||||
|
||||
@@ -10,7 +10,7 @@ public interface ClientAuthService {
|
||||
* @param loginBody 登录信息
|
||||
* @return token
|
||||
*/
|
||||
String doSmsLogin(ClientLoginBody loginBody);
|
||||
String doLogin(ClientLoginBody loginBody);
|
||||
|
||||
/**
|
||||
* 注册
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.budwk.app.client.auth.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.client.auth.vo.ClientLoginBody;
|
||||
import com.budwk.app.client.auth.models.Client_user;
|
||||
import com.budwk.app.client.auth.vo.ClientRegisterBody;
|
||||
@@ -11,6 +13,9 @@ import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
public class ClientAuthServiceImpl implements ClientAuthService {
|
||||
@@ -21,23 +26,34 @@ public class ClientAuthServiceImpl implements ClientAuthService {
|
||||
private ValidateService validateService;
|
||||
|
||||
@Override
|
||||
public String doSmsLogin(ClientLoginBody loginBody) {
|
||||
public String doLogin(ClientLoginBody loginBody) {
|
||||
Client_user user = null;
|
||||
int count = dao.count(Client_user.class, Cnd.where(Client_user::getPhone, "=", loginBody.getPhone()));
|
||||
if (count == 0) {
|
||||
// // 自动注册
|
||||
// user = new Client_user();
|
||||
// user.setPhone(loginBody.getPhone());
|
||||
// user.setUserName("用户" + loginBody.getPhone());
|
||||
// dao.insert(user);
|
||||
throw new BaseException("手机号码不存在");
|
||||
}
|
||||
|
||||
validateService.checkSMSCode(loginBody.getPhone(), loginBody.getSmsCode());
|
||||
user = dao.fetch(Client_user.class, Cnd.where(Client_user::getPhone, "=", loginBody.getPhone()));
|
||||
|
||||
if (user == null) {
|
||||
throw new BaseException("用户登录失败");
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(loginBody.getLoginMethod()) || !List.of("sms", "password").contains(loginBody.getLoginMethod())) {
|
||||
throw new BaseException("登录方式不正确");
|
||||
}
|
||||
|
||||
if (loginBody.getLoginMethod().equals("sms")) {
|
||||
validateService.checkSMSCode(loginBody.getPhone(), loginBody.getSmsCode());
|
||||
}
|
||||
|
||||
if (loginBody.getLoginMethod().equals("password")) {
|
||||
String hashedPassword = PwdUtil.getPassword(loginBody.getPassword(), user.getSalt());
|
||||
if (!Strings.sNull(hashedPassword).equalsIgnoreCase(user.getPassword())) {
|
||||
throw new BaseException("密码不正确");
|
||||
}
|
||||
}
|
||||
|
||||
StpClientUtil.STP.login(user.getId());
|
||||
StpClientUtil.STP.checkLogin();
|
||||
return StpClientUtil.STP.getTokenValue();
|
||||
|
||||
@@ -9,4 +9,8 @@ public class ClientLoginBody {
|
||||
|
||||
private String smsCode;
|
||||
|
||||
private String password;
|
||||
|
||||
private String loginMethod;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user