Mall - registered user - user name and password based on user queries
The user name and password to query the user
7.1. Interface Description
Function Description
Queries, query the user according to the parameters specified in the user name and password
Interface path
GET /query
Parameter Description:
form Form format
parameter | Explanation | Do you have to | type of data | Defaults |
---|---|---|---|---|
username | User name in the form of 4 to 30 letters, numbers, underscores | Yes | String | no |
password | User password, the format of 4 to 30 letters, numbers, underscores | Yes | String | no |
Return result:
User data format json
{
"id": 6572312,
"username":"test",
"phone":"13688886666",
"created": 1342432424
}
status code:
- 200: Registration successful
- 400: The user name or password is incorrect
- 500: Internal Server exceptions, failed to register
7.2.controller
/**
* 根据用户名和密码查询用户
* @param username
* @param password
* @return
*/
@GetMapping("query")
public ResponseEntity<User> queryUser(
@RequestParam("username") String username,
@RequestParam("password") String password
) {
User user = this.userService.queryUser(username, password);
if (user == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
}
return ResponseEntity.ok(user);
}
7.3.service
public User queryUser(String username, String password) {
// 查询
User record = new User();
record.setUsername(username);
User user = this.userMapper.selectOne(record);
// 校验用户名
if (user == null) {
return null;
}
// 校验密码
if (!user.getPassword().equals(CodecUtils.md5Hex(password, user.getSalt()))) {
return null;
}
// 用户名密码都正确
return user;
}
Note that after the password encryption should determine whether the same query.
7.4. Test
We RestClient test:
8. Test at the registration page
Fill in the information in the registration page:
Submit discover page automatically jump to the login page, check the database: