邮箱-注册
This commit is contained in:
@@ -128,8 +128,8 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByEmail(String email, String code, DeviceInfo deviceInfo, String ipAddress) throws Exception {
|
||||
Account account = accountService.getAccountByEmail(email);
|
||||
public UserDetails loadUserByEmail(String email, String code, DeviceInfo deviceInfo, String ipAddress) {
|
||||
Account account = accountManageService.getOrGenAccountByEmail(email, code, deviceInfo, ipAddress);
|
||||
if (account == null) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.USER_NOT_EXISTED,
|
||||
BusiStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
|
@@ -31,6 +31,7 @@ import com.accompany.oauth2.event.UserRegisterSuccessEvent;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -108,6 +109,33 @@ public class AccountManageService {
|
||||
}
|
||||
|
||||
|
||||
public Account getOrGenAccountByEmail(String email, String code, DeviceInfo deviceInfo, String ipAddress) {
|
||||
log.info("getOrGenAccountByPhone email:{},code:{}", email, code);
|
||||
String lockVal = jedisLockService.lock(RedisKey.lock_register_by_email.getKey(email));
|
||||
try {
|
||||
if (BlankUtil.isBlank(lockVal)) {
|
||||
throw new ServiceException(BusiStatus.REQUEST_FAST);
|
||||
}
|
||||
Account account = accountService.getAccountByEmail(email);
|
||||
if (account == null) {
|
||||
account = saveSignUpByEmail(email, null, deviceInfo, ipAddress);
|
||||
} else {
|
||||
String state = account.getState();
|
||||
if (Constant.AccountState.block.equals(state)) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.INVALID_USER,
|
||||
"用户账号异常,请联系官方客服uid=" + account.getUid());
|
||||
}
|
||||
account.setLastLoginTime(new Date());
|
||||
account.setLastLoginIp(ipAddress);
|
||||
account.setUpdateTime(new Date());
|
||||
accountService.updateById(account);
|
||||
}
|
||||
return account;
|
||||
} finally {
|
||||
jedisLockService.unlock(RedisKey.lock_register_by_email.getKey(email), lockVal);
|
||||
}
|
||||
}
|
||||
|
||||
public Account getOrGenAccountByOpenid(String openid, Byte type, DeviceInfo deviceInfo, String ipAddress, String unionId) throws Exception {
|
||||
log.info("getOrGenAccountByOpenid openId:{},type:{},unionId:{}", openid, type, unionId);
|
||||
final String locKey = RedisKey.lock_register_by_openid.getKey(openid, unionId, String.valueOf(type));
|
||||
@@ -220,6 +248,38 @@ public class AccountManageService {
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private Account saveSignUpByEmail(String email, String password, DeviceInfo deviceInfo, String ipAddress) {
|
||||
checkRegisterLimit(deviceInfo.getDeviceId(), ipAddress);
|
||||
|
||||
Date date = new Date();
|
||||
Account account = new Account();
|
||||
account.setEmail(email);
|
||||
if (StringUtils.hasText(password)) {
|
||||
account.setPassword(encryptPassword(password));
|
||||
}
|
||||
account.setNeteaseToken(UUIDUtil.get());
|
||||
account.setLastLoginTime(date);
|
||||
account.setLastLoginIp(ipAddress);
|
||||
account.setUpdateTime(date);
|
||||
account.setRegisterIp(ipAddress);
|
||||
account.setSignTime(date);
|
||||
account.setState(Constant.AccountState.normal);
|
||||
account.setErbanNo(erBanNoService.getErBanNo());
|
||||
account = fillDeviceInfo(account, deviceInfo);
|
||||
|
||||
accountMapper.insert(account);
|
||||
accountService.writeAche(account);
|
||||
String uidStr = String.valueOf(account.getUid());
|
||||
TokenRet tokenRet = netEaseService.createNetEaseAcc(uidStr, account.getNeteaseToken(), "", "", null);
|
||||
if (tokenRet.getCode() != 200) {
|
||||
log.error("邮件email {} 注册异常,异常原因code {}", email, tokenRet.getCode());
|
||||
throw new ServiceException(BusiStatus.SERVERBUSY);
|
||||
}
|
||||
applicationContext.publishEvent(new UserRegisterSuccessEvent(account));
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过手机号码注册,独立账号系统,不掺杂业务
|
||||
*
|
||||
|
@@ -67,7 +67,8 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
||||
GrantTypeEnum.REFRESH_TOKEN.getValue(),
|
||||
GrantTypeEnum.OPENID.getValue(),
|
||||
GrantTypeEnum.APPLE.getValue(),
|
||||
GrantTypeEnum.VERIFY_CODE.getValue()
|
||||
GrantTypeEnum.VERIFY_CODE.getValue(),
|
||||
GrantTypeEnum.EMAIL.getValue()
|
||||
).scopes("read", "write")
|
||||
.authorities("oauth2")
|
||||
.secret(finalSecret)
|
||||
|
@@ -5,6 +5,7 @@ import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
import com.accompany.oauth2.service.MyUserDetailsServiceImpl;
|
||||
import com.accompany.oauth2.service.account.AccountH5LoginService;
|
||||
import com.accompany.oauth2.support.email.EmailAuthenticationProvider;
|
||||
import com.accompany.oauth2.support.h5.H5TokenGranter;
|
||||
import com.accompany.oauth2.support.h5.PasswordH5TokenGranter;
|
||||
import com.accompany.oauth2.support.h5.VerifyCodeH5TokenGranter;
|
||||
@@ -48,7 +49,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
}
|
||||
|
||||
@Bean
|
||||
PasswordEncoder passwordEncoder() {
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
}
|
||||
|
||||
@@ -70,7 +71,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) {
|
||||
auth.authenticationProvider(passwordAuthenticationProvider())
|
||||
.authenticationProvider(verifyCodeAuthenticationProvider());
|
||||
.authenticationProvider(verifyCodeAuthenticationProvider())
|
||||
.authenticationProvider(eamilAuthenticationProvider());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -83,6 +85,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
return new VerifyCodeAuthenticationProvider(myUserDetailsService(), phoneBlackService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthenticationProvider eamilAuthenticationProvider() {
|
||||
return new EmailAuthenticationProvider(myUserDetailsService());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public H5TokenGranter passwordH5TokenGranter() {
|
||||
return new PasswordH5TokenGranter(myUserDetailsService(), accountH5LoginService);
|
||||
|
Reference in New Issue
Block a user