Search in sources :

Example 6 with User

use of mingzuozhibi.persist.core.User in project mzzb-server by mingzuozhibi.

the class SessionController method onLoginSuccess.

private void onLoginSuccess(String username, boolean putNewToken) {
    dao.execute(session -> {
        User user = dao.lookup(User.class, "username", username);
        user.setLastLoggedIn(LocalDateTime.now().withNano(0));
        if (putNewToken) {
            autoLoginHeaper.buildAutoLoginToken(user);
        }
    });
}
Also used : User(mingzuozhibi.persist.core.User)

Example 7 with User

use of mingzuozhibi.persist.core.User in project mzzb-server by mingzuozhibi.

the class SessionController method sessionLogin.

@PostMapping(value = "/api/session", produces = MEDIA_TYPE)
public String sessionLogin(@JsonArg("$.username") String username, @JsonArg("$.password") String password) {
    User user = dao.lookup(User.class, "username", username);
    if (user == null) {
        if (LOGGER.isInfoEnabled()) {
            infoRequest("[用户名称不存在: username={}]", username);
        }
        return errorMessage("用户名称不存在");
    }
    UserDetails userDetails = new UserDetailsImpl(user);
    if (!userDetails.getPassword().equals(password)) {
        if (LOGGER.isInfoEnabled()) {
            infoRequest("[用户密码错误: username={}]", username);
        }
        return errorMessage("用户密码错误");
    }
    if (!userDetails.isEnabled()) {
        if (LOGGER.isWarnEnabled()) {
            warnRequest("[用户已被停用: username={}]", username);
        }
        return errorMessage("用户已被停用");
    }
    doLoginSuccess(userDetails);
    onLoginSuccess(username, true);
    JSONObject session = buildSession();
    if (LOGGER.isInfoEnabled()) {
        infoRequest("[用户成功登入: session={}]", session);
    }
    return objectResult(session);
}
Also used : UserDetailsImpl(mingzuozhibi.security.UserDetailsImpl) User(mingzuozhibi.persist.core.User) UserDetails(org.springframework.security.core.userdetails.UserDetails) JSONObject(org.json.JSONObject) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

User (mingzuozhibi.persist.core.User)7 JSONObject (org.json.JSONObject)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Transactional (org.springframework.transaction.annotation.Transactional)4 CsrfTokenResponseHeaderBindingFilter (com.allanditzel.springframework.security.web.csrf.CsrfTokenResponseHeaderBindingFilter)1 UserDetailsImpl (mingzuozhibi.security.UserDetailsImpl)1 PassUtil (mingzuozhibi.support.PassUtil)1 JSONArray (org.json.JSONArray)1 Logger (org.slf4j.Logger)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1