add user register and login

pangu
PeterAlbus 3 years ago
parent 7e001bfbc3
commit 75b6189e64

1
.gitignore vendored

@ -36,4 +36,3 @@ build/
application.yml
5963105_www.peteralbus.com.pfx
SmsUtil.java
SmsUtil

@ -82,6 +82,16 @@
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>

@ -51,7 +51,7 @@ public class UserController
}
@RequestMapping("/mailLogin")
public SaTokenInfo doLogin(String userMail, String userPassword)
public SaTokenInfo mailLogin(String userMail, String userPassword)
{
User user=userService.authByMail(userMail, userPassword);
if(user!=null)
@ -62,6 +62,18 @@ public class UserController
return null;
}
@RequestMapping("/phoneLogin")
public SaTokenInfo phoneLogin(String userPhone, String userPassword)
{
User user=userService.authByPhone(userPhone, userPassword);
if(user!=null)
{
StpUtil.login(user.getUserId());
return StpUtil.getTokenInfo();
}
return null;
}
@RequestMapping("/isLogin")
public User isLogin()
{
@ -86,6 +98,14 @@ public class UserController
@RequestMapping("/applyMailVerifyCode")
public String applyMailVerifyCode(String account)
{
if(redisUtils.exists("verifyCode:"+account))
{
return "haveVerifyCode";
}
if(userService.haveAccount(account))
{
return "haveAccount";
}
String verifyCode=RandomUtil.generateVerifyCode(6);
try {
MimeMessage message=javaMailSender.createMimeMessage();
@ -106,6 +126,14 @@ public class UserController
@RequestMapping("/applyPhoneVerifyCode")
public String applyPhoneVerifyCode(String account)
{
if(redisUtils.exists("verifyCode:"+account))
{
return "haveVerifyCode";
}
if(userService.haveAccount(account))
{
return "haveAccount";
}
final String success ="smsSendSuccess";
String result="";
String verifyCode=RandomUtil.generateVerifyCode(4);
@ -115,7 +143,7 @@ public class UserController
if(Objects.equals(result, success))
{
redisUtils.set("verifyCode:"+account,verifyCode,10L, TimeUnit.MINUTES);
return "sendMailSuccess";
return "sendSmsSuccess";
}
}
catch (ClientException e)

@ -61,4 +61,11 @@ public interface UserService
*/
int changePassword(Long userId,String oldPassword,String newPassword);
/**
* Have account boolean.
*
* @param account the account
* @return the boolean
*/
boolean haveAccount(String account);
}

@ -105,4 +105,12 @@ public class UserServiceImpl implements UserService
}
return -1;
}
@Override
public boolean haveAccount(String account)
{
QueryWrapper<User> userQueryWrapper=new QueryWrapper<>();
userQueryWrapper.eq("user_mail",account).or().eq("user_phone",account);
return userMapper.selectCount(userQueryWrapper) > 0;
}
}

Loading…
Cancel
Save