- restore generic signatures, scoped variables and missing code from original bytecode - remove decompiler artifacts and document classes, methods, fields and packages - restore resources, add Batik/BouncyCastle dependencies and build/runtime docs
99 lines
4.1 KiB
Java
99 lines
4.1 KiB
Java
package com.midm.controller;
|
||
|
||
import com.midm.model.org.User;
|
||
import com.midm.model.org.UserToken;
|
||
import com.mitac.cell.utils.McUuidUtils;
|
||
import java.util.UUID;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import org.springframework.security.core.Authentication;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.ui.Model;
|
||
import org.springframework.web.bind.annotation.RequestHeader;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RequestMethod;
|
||
import org.springframework.web.bind.annotation.RequestParam;
|
||
import org.springframework.web.bind.annotation.ResponseBody;
|
||
import org.springframework.web.server.NotAcceptableStatusException;
|
||
|
||
/**
|
||
* 【Web 控制器】{@code UserController}
|
||
*
|
||
* 类职责:
|
||
* <ul>
|
||
* <li>接收 HTTP 请求、做参数绑定/鉴权,并把业务委托给 Service。</li>
|
||
* </ul>
|
||
*
|
||
* 学习提示:先看类上的 @RequestMapping 路径,再沿 public 方法里的 service 调用链阅读。
|
||
*/
|
||
@Controller
|
||
public class UserController extends BaseController {
|
||
/**
|
||
* 处理home。
|
||
*
|
||
* 实现要点:包含 2 个条件分支、0 个循环。
|
||
*
|
||
* 框架注解:{@code @RequestMapping(value = {"/resetPassword"}, method = {RequestMethod.GET})}。
|
||
*
|
||
* @param request HTTP 请求({@code HttpServletRequest})
|
||
* @param response HTTP 响应({@code HttpServletResponse})
|
||
* @param authentication Spring Security 认证信息({@code Authentication})
|
||
* @param model 参数 {@code model}({@code Model})
|
||
* @param passwordTokenUid 参数 {@code passwordTokenUid}({@code String})
|
||
* @param language 参数 {@code language}({@code String})
|
||
* @return 字符串结果
|
||
*/
|
||
@RequestMapping(
|
||
value = {"/resetPassword"},
|
||
method = {RequestMethod.GET}
|
||
)
|
||
public String home(HttpServletRequest request, HttpServletResponse response, Authentication authentication, Model model, @RequestParam(name = "token") String passwordTokenUid, @RequestParam(required = false) String language) {
|
||
this.init(request, response, authentication, language);
|
||
model.addAttribute("theme", this.theme);
|
||
UUID passwordTokenUuid = McUuidUtils.toUuidFromBase64(passwordTokenUid);
|
||
UserToken token = this.userService.findToken(passwordTokenUuid);
|
||
if (token != null && token.isExpired()) {
|
||
this.userService.deleteTokenByType(token);
|
||
}
|
||
|
||
if (token != null && token.getTokenType() == 'P') {
|
||
model.addAttribute("error", false);
|
||
User user = this.userService.findUserByUserUuid(token.getUserUuid());
|
||
model.addAttribute("token", token);
|
||
model.addAttribute("user", user);
|
||
return this.getView(authentication, "/resetPassword");
|
||
} else {
|
||
model.addAttribute("error", true);
|
||
return this.getView(authentication, "/resetPassword");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取设置列表。
|
||
*
|
||
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new NotAcceptableStatusException。
|
||
*
|
||
* 框架注解:{@code @RequestMapping(value = {"/keepSession"}, method = {RequestMethod.GET}, produces = {"text/plain"})}、{@code @ResponseBody}。
|
||
*
|
||
* @param request HTTP 请求({@code HttpServletRequest})
|
||
* @param authentication Spring Security 认证信息({@code Authentication})
|
||
* @param accessToken 参数 {@code accessToken}({@code String})
|
||
* @return 字符串结果
|
||
* @throws NotAcceptableStatusException 当 NotAcceptableStatusException 条件不满足或底层调用失败时抛出。
|
||
*/
|
||
@RequestMapping(
|
||
value = {"/keepSession"},
|
||
method = {RequestMethod.GET},
|
||
produces = {"text/plain"}
|
||
)
|
||
@ResponseBody
|
||
public String getSettings(HttpServletRequest request, Authentication authentication, @RequestHeader(value = "Authorization",required = false) String accessToken) {
|
||
User loggedUser = this.userService.authorizedUser(authentication, accessToken);
|
||
if (loggedUser == null) {
|
||
throw new NotAcceptableStatusException("");
|
||
} else {
|
||
return "ok";
|
||
}
|
||
}
|
||
}
|