- 当存在多种登录方式时,可以为所有的字段设置不同的请求参数,后台判空进行自动判定使用的时哪种登录方式,无需前端传输登录方式的type值。
protected UsernamePasswordCaptchaToken shiroLogin() throws AuthenticationException { // #1 Username login, using password String username = getParameter("userName_login"); String password = getString("password_login"); // #2 Mobile login, using password String mobile = getString("mobile_login"); String countryCode = getParameter("country_code"); // #3 Email login, using one-time code String email = getString("email"); String code = getString("code"); String handle = nonNull(username, fullMobile(countryCode, mobile), email); String secret = nonNull(password, code); if (isEmpty(handle) || isEmpty(secret)) { throw new AuthenticationException("Account and password or code does not match."); } // 登录逻辑 } protected String nonNull(String... args) { for (String val : args) { if (isBlank(val)) { continue; } return val.trim(); } return null; }
07-06
3523
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-12
1307
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-06
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交