Javashop電商系統-會員登錄方式


Javashop電商系統國內基於Java開發的企業級電商平台。

關於會員的安全認證,采用token機制鑒權,結合SpringSecurity來實現安全配置。

下面結合代碼簡單介紹一下會員的多種登錄方式:

 

1.賬號密碼登錄

用戶選擇賬號登錄,輸入賬號密碼,實現方式為驗證賬號密碼是否正確。

2.手機號快捷登錄

用戶選擇快捷登錄,通過輸入的手機號和驗證碼進行驗證登錄。

3.信任登錄

第三方掃碼登錄,包括QQ,微信,微博,支付寶等多種登錄方式

信任登錄需要配置登錄參數,在配置文件中配置您的買家端域名以及回調地址

 

歡迎訪問Javashop登錄界面

以下為為信任登錄統一回調地址源碼展示:

    @ApiOperation(value = "信任登錄統一回調地址")
    @GetMapping("/connect/{port}/{type}/callback")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "登錄類型", required = true, dataType = "String", allowableValues = "QQ,WEIBO,WECHAT,ALIPAY", paramType = "path"),
            @ApiImplicitParam(name = "port", value = "登錄客戶端", required = true, dataType = "String", allowableValues = "PC,WAP", paramType = "path"),
            @ApiImplicitParam(name = "uid", value = "會員id", required = true, dataType = "Integer", paramType = "query")
    })
    public void callBack(@PathVariable("type") String type, @PathVariable("port") String port, @ApiIgnore Long uid) {
        try {
            uid = getUidForCookies(uid);
            if (uid != null && uid != 0) {
                bindCallBackMethod(type, port, uid);
            } else {
                String uuid = UUID.randomUUID().toString();

                debugger.log("生成uuid:");
                debugger.log(uuid);

                MemberVO memberVO = connectManager.callBack(type, port, null, uuid);

                HttpServletResponse httpResponse = ThreadContextHolder.getHttpResponse();
                //主域名
                String main = domainHelper.getTopDomain();
                String buyer = domainHelper.getBuyerDomain();
                //如果是wap站點,需要跳轉到wap對應的綁定頁面或者是首頁
                if (StringUtil.isWap()) {
                    buyer = domainHelper.getMobileDomain();
                }
                String redirectUri = buyer + binder + "?uuid=" + uuid;
                //如果會員存在則直接跳轉到首頁
                if (memberVO != null) {
                    Cookie accessTokenCookie new Cookie("access_token", memberVO.getAccessToken());
                    Cookie refreshTokenCookie new Cookie("refresh_token", memberVO.getRefreshToken());
                    Cookie uidCookie new Cookie("uid", StringUtil.toString(memberVO.getUid()));
                    accessTokenCookie.setDomain(main);
                    accessTokenCookie.setPath("/");
                    accessTokenCookie.setMaxAge(javashopConfig.getAccessTokenTimeout());

                    refreshTokenCookie.setDomain(main);
                    refreshTokenCookie.setPath("/");
                    refreshTokenCookie.setMaxAge(javashopConfig.getRefreshTokenTimeout());

                    uidCookie.setDomain(main);
                    uidCookie.setPath("/");
                    uidCookie.setMaxAge(javashopConfig.getRefreshTokenTimeout());

                    httpResponse.addCookie(uidCookie);
                    httpResponse.addCookie(accessTokenCookie);
                    httpResponse.addCookie(refreshTokenCookie);
                    redirectUri = buyer + index + "?uuid=" + uuid;
                }
                //如果會員存在則登錄此會員並將uuid及token信息存入cookie
                Cookie cookie = new Cookie("uuid_connect", uuid);
                cookie.setDomain(main);
                cookie.setPath("/");
                cookie.setMaxAge(javashopConfig.getRefreshTokenTimeout());
                httpResponse.addCookie(cookie);
                //無會員則跳轉至綁定頁
                httpResponse.sendRedirect(redirectUri);
                return;
            }

        } catch (IOException e) {
            this.logger.error(e.getMessage(), e);
            throw new ServiceException(MemberErrorCode.E131.name(), "聯合登錄失敗");
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM