Skip to content

Commit

Permalink
feat 注册api
Browse files Browse the repository at this point in the history
  • Loading branch information
wyt1215819315 committed Oct 20, 2023
1 parent 1095196 commit 9a9441b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
26 changes: 26 additions & 0 deletions src/main/java/com/github/system/auth/controller/RegController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.system.auth.controller;

import com.github.system.auth.service.RegService;
import com.github.system.auth.vo.RegModel;
import com.github.system.base.dto.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/reg")
public class RegController {

@Resource
private RegService regService;

@RequestMapping("/doReg")
public AjaxResult doReg(@RequestBody @Validated RegModel regModel) {
return regService.doReg(regModel);
}


}
8 changes: 8 additions & 0 deletions src/main/java/com/github/system/auth/service/RegService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.system.auth.service;

import com.github.system.auth.vo.RegModel;
import com.github.system.base.dto.AjaxResult;

public interface RegService {
AjaxResult doReg(RegModel regModel);
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
package com.github.system.service;
package com.github.system.auth.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.github.system.auth.entity.SysUser;
import com.github.system.auth.service.RegService;
import com.github.system.auth.service.UserService;
import com.github.system.auth.vo.RegModel;
import com.github.system.base.configuration.SystemBean;
import com.github.system.base.dto.AjaxResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RegService {
public class RegServiceImpl implements RegService {

@Resource
private SystemBean systemBean;

@Resource
private UserService userService;

public AjaxResult doReg(String username, String password) {
if (StrUtil.isBlank(username) || StrUtil.isBlank(password)){
return AjaxResult.doError("用户名或密码不能为空!");
}
if (username.length() < 6 || username.length() > 20) {
return AjaxResult.doError("用户名必须为6-20位!");
} else if (password.length() < 8 || password.length() > 20) {
return AjaxResult.doError("密码长度需在8-20位之间!");
}
@Override
public AjaxResult doReg(RegModel regModel) {
String username = regModel.getUsername();
String password = regModel.getPassword();
if (userService.findUserByUsername(username) != null) {
return AjaxResult.doError("用户名已经存在!");
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/github/system/auth/vo/RegModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.system.auth.vo;

import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;

@Data
public class RegModel {

@NotBlank(message = "用户名不能为空")
@Length(min = 5, max = 20)
private String username;

@NotBlank
private String password;

}

0 comments on commit 9a9441b

Please sign in to comment.