我想在 Spring 中创建一个页面,其中包含 url
http://myapp.com/sign-in?email=myemail@provider.com&pw=password
password
是用户每次要登录时通过电子邮件收到的一次性密码。
每当用户访问此页面时,我希望发生两件事:
检查提供的凭据是否正确。
如果是,则显示页面的 HTML 内容。
我已经完成了第一部分:
@Autowired
private var userRepository: UserRepository? = null
@GetMapping
fun signIn(@RequestParam email:String, @RequestParam(name="pw") password:String): RedirectView {
// Is the password correct?
// TODO: Read password hash of the user
val existingUser: Optional<UserInfo>? = userRepository?.findById(email)
if (existingUser == null) {
return redirectToErrorPage("Please register with your e-mail address first")
}
if (!existingUser.isPresent) {
return redirectToErrorPage("Please register with your e-mail address first")
}
val hashInDb = existingUser.get().passwordHash
val hashInParam = PasswordHashCalculator.calculateHash(password)
if (!hashInDb.equals(hashInParam)) {
return redirectToErrorPage("Invalid user name and/or password")
}
// TODO: Display the main page
return null
}
我需要如何更改代码才能显示主页(HTML 文件 in src/main/resources/static),但前提是通过身份验证检查?
更新 1:按照此处return ClassPathResource("main.html")的建议使用没有帮助。
POPMUISE
泛舟湖上清波郎朗
慕勒3428872
相关分类