Search in sources :

Example 1 with AjaxResult

use of com.besscroft.aurora.mall.common.result.AjaxResult in project aurora-mall by besscroft.

the class UserServiceImpl method login.

@Override
public AjaxResult login(String username, String password) {
    if (StrUtil.isEmpty(username) || StrUtil.isEmpty(password)) {
        log.error("用户名或密码不能为空!");
    }
    Map<String, String> params = new HashMap<>();
    params.put("client_id", AuthConstants.ADMIN_CLIENT_ID);
    params.put("client_secret", "123456");
    params.put("grant_type", "password");
    params.put("username", username);
    params.put("password", password);
    AjaxResult accessToken = authFeignClient.getAccessToken(params);
    log.info("accessToken:{}", accessToken);
    redisTemplate.opsForValue().set(AuthConstants.ADMIN_CLIENT_ID + ":token:user:" + username, accessToken.get("access_token").toString());
    return accessToken;
}
Also used : AjaxResult(com.besscroft.aurora.mall.common.result.AjaxResult) HashMap(java.util.HashMap)

Example 2 with AjaxResult

use of com.besscroft.aurora.mall.common.result.AjaxResult in project aurora-mall by besscroft.

the class UserServiceTest method login.

@Test
void login() throws Exception {
    String username = "admin";
    String password = "666666";
    AjaxResult result = userService.login(username, password);
    LOGGER.info("result:{}", objectMapper.writeValueAsString(result));
}
Also used : AjaxResult(com.besscroft.aurora.mall.common.result.AjaxResult) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AjaxResult

use of com.besscroft.aurora.mall.common.result.AjaxResult in project aurora-mall by besscroft.

the class UserController method login.

@WebLog(description = "登录接口")
@ApiOperation(value = "登录并返回token")
@PostMapping(value = "/login")
public AjaxResult login(@Validated @RequestBody UserLoginParam userLoginParam) {
    log.info("请求进来了,打印UserLoginParam:{}", userLoginParam);
    AjaxResult result = userService.login(userLoginParam.getUsername(), userLoginParam.getPassword());
    log.info("请求进来了,oauth2Token:{}", result);
    return AjaxResult.success(result);
}
Also used : AjaxResult(com.besscroft.aurora.mall.common.result.AjaxResult) WebLog(com.besscroft.aurora.mall.common.annotation.WebLog) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

AjaxResult (com.besscroft.aurora.mall.common.result.AjaxResult)3 WebLog (com.besscroft.aurora.mall.common.annotation.WebLog)1 ApiOperation (io.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1