sso接口的调用
之前一直想sso接口已經(jīng)寫(xiě)好了,登錄注冊(cè)功能是怎么調(diào)用的呢?原來(lái)在登錄注冊(cè)的jsp頁(yè)面實(shí)現(xiàn)的接口的調(diào)用,頁(yè)面的校驗(yàn)和驗(yàn)證功能在jsp頁(yè)面即可實(shí)現(xiàn)。
?
注冊(cè)頁(yè)面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache,must-revalidate"><title>注冊(cè)-個(gè)人用戶</title><link type="text/css" rel="stylesheet" href="/css/regist.personal.css"/><link type="text/css" rel="stylesheet" href="/css/passport.base.css"/><script type="text/javascript" src="/js/jquery-1.6.4.js"></script> </head> <body> <div class="w" id="logo"><div><a href="http://localhost:8082"><img src="/images/taotao-logo.gif" alt="淘淘商城" width="170" height="60"/></a> <b></b></div> </div><div class="w" id="regist"><div class="mt"><ul class="tab"><li class="curr">個(gè)人用戶</li></ul><div class="extra"><span>我已經(jīng)注冊(cè),現(xiàn)在就?<a href="/page/login" class="flk13">登錄</a></span></div></div><div class="mc"><form id="personRegForm" method="post" οnsubmit="return false;"><div class="form" onselectstart="return false;"><div class="item" id="select-regName"><span class="label"><b class="ftx04">*</b>用戶名:</span><div class="fl item-ifo"><div class="o-intelligent-regName"><input type="text" id="regName" name="username" class="text" tabindex="1" autoComplete="off"οnpaste="return false;"value=""οnfοcus="if(this.value=='') this.value='';this.style.color='#333'"οnblur="if(this.value=='') {this.value='';this.style.color='#999999'}"/><i class="i-name"></i><ul id="intelligent-regName" class="hide"></ul><label id="regName_succeed" class="blank"></label><label id="regName_error" class="hide"></label></div></div></div><div id="o-password"><div class="item"><span class="label"><b class="ftx04">*</b>請(qǐng)?jiān)O(shè)置密碼:</span><div class="fl item-ifo"><input type="password" id="pwd" name="password" class="text" tabindex="2"style="ime-mode:disabled;"οnpaste="return false" autocomplete="off"/><i class="i-pass"></i><label id="pwd_succeed" class="blank"></label><label id="pwd_error"></label><span class="clr"></span></div></div><div class="item"><span class="label"><b class="ftx04">*</b>請(qǐng)確認(rèn)密碼:</span><div class="fl item-ifo"><input type="password" id="pwdRepeat" name="pwdRepeat" class="text" tabindex="3"οnpaste="return false" autocomplete="off"/><i class="i-pass"></i><label id="pwdRepeat_succeed" class="blank"></label><label id="pwdRepeat_error"></label></div></div><div class="item" id="dphone"><span class="label"><b class="ftx04">*</b>驗(yàn)證手機(jī):</span><div class="fl item-ifo"><input type="text" id="phone" maxlength="11" name="phone"class="text" tabindex="4"autocomplete="off" /> <i class="i-phone"></i> <labelid="phone_succeed" class="blank"></label> <labelid="phone_error"></label></div></div></div><div class="item item-new"><span class="label">?</span><div class="fl item-ifo"><input type="checkbox" class="checkbox" checked="checked" id="readme"οnclick="agreeonProtocol();"><label for="protocol">我已閱讀并同意<a href="#" class="blue" id="protocol">《淘淘用戶注冊(cè)協(xié)議》</a></label><span class="clr"></span><label id="protocol_error" class="error hide">請(qǐng)接受服務(wù)條款</label></div></div><div class="item"><span class="label">?</span><input type="button" class="btn-img btn-regist" id="registsubmit" value="立即注冊(cè)" tabindex="8"clstag="regist|keycount|personalreg|07"οnclick="REGISTER.reg();"/></div></div><div class="phone"><img width="180" height="180" src="/images/phone-bg.jpg"></div><span class="clr"></span></form></div> <script type="text/javascript">var REGISTER={param:{//單點(diǎn)登錄系統(tǒng)的urlsurl:""},inputcheck:function(){//不能為空檢查if ($("#regName").val() == "") {alert("用戶名不能為空");$("#regName").focus();return false;}if ($("#pwd").val() == "") {alert("密碼不能為空");$("#pwd").focus();return false;}if ($("#phone").val() == "") {alert("手機(jī)號(hào)不能為空");$("#phone").focus();return false;}//密碼檢查if ($("#pwd").val() != $("#pwdRepeat").val()) {alert("確認(rèn)密碼和密碼不一致,請(qǐng)重新輸入!");$("#pwdRepeat").select();$("#pwdRepeat").focus();return false;}return true;},beforeSubmit:function() {//檢查用戶是否已經(jīng)被占用$.ajax({//這是校驗(yàn)的接口調(diào)用,通過(guò)接口中的url來(lái)實(shí)現(xiàn)的url : REGISTER.param.surl + "/user/check/"+escape($("#regName").val())+"/1?r=" + Math.random(),success : function(data) {if (data.data) {//檢查手機(jī)號(hào)是否存在$.ajax({url : REGISTER.param.surl + "/user/check/"+$("#phone").val()+"/2?r=" + Math.random(),success : function(data) {if (data.data) {REGISTER.doSubmit();} else {alert("此手機(jī)號(hào)已經(jīng)被注冊(cè)!");$("#phone").select();}}});} else {alert("此用戶名已經(jīng)被占用,請(qǐng)選擇其他用戶名");$("#regName").select();} }});},doSubmit:function() {
//這是注冊(cè)的接口,通過(guò)注冊(cè)接口的URL來(lái)實(shí)現(xiàn)的調(diào)用$.post("/user/register",$("#personRegForm").serialize(), function(data){if(data.status == 200){alert('用戶注冊(cè)成功,請(qǐng)登錄!');REGISTER.login();} else {alert("注冊(cè)失敗!");}});},login:function() {location.href = "/page/login";return false;},reg:function() {if (this.inputcheck()) {this.beforeSubmit();}}}; </script> </body> </html>
登錄頁(yè)面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"/><title>登錄淘淘</title><link type="text/css" rel="stylesheet" href="/css/login.css"/><script type="text/javascript" src="/js/jquery-1.6.4.js"></script> </head> <body> <div class="w"><div id="logo"><a href="http://localhost:8082" clstag="passport|keycount|login|01"><img src="/images/taotao-logo.gif" alt="淘淘" width="170" height="60"/></a><b></b></div> </div> <form id="formlogin" method="post" οnsubmit="return false;"><div class=" w1" id="entry"><div class="mc " id="bgDiv"><div id="entry-bg" clstag="passport|keycount|login|02" style="width: 511px; height: 455px; position: absolute; left: -44px; top: -44px; background: url(/images/544a11d3Na5a3d566.png) 0px 0px no-repeat;"></div><div class="form "><div class="item fore1"><span>用戶名</span><div class="item-ifo"><input type="text" id="loginname" name="username" class="text" tabindex="1" autocomplete="off"/><div class="i-name ico"></div><label id="loginname_succeed" class="blank invisible"></label><label id="loginname_error" class="hide"><b></b></label></div></div><script type="text/javascript">setTimeout(function () {if (!$("#loginname").val()) {$("#loginname").get(0).focus();}}, 0);</script><div id="capslock"><i></i><s></s>鍵盤(pán)大寫(xiě)鎖定已打開(kāi),請(qǐng)注意大小寫(xiě)</div><div class="item fore2"><span>密碼</span><div class="item-ifo"><input type="password" id="nloginpwd" name="password" class="text" tabindex="2" autocomplete="off"/><div class="i-pass ico"></div><label id="loginpwd_succeed" class="blank invisible"></label><label id="loginpwd_error" class="hide"></label></div></div><div class="item login-btn2013"><input type="button" class="btn-img btn-entry" id="loginsubmit" value="登錄" tabindex="8" clstag="passport|keycount|login|06"/></div></div></div><div class="free-regist"><span><a href="/page/register" clstag="passport|keycount|login|08">免費(fèi)注冊(cè)>></a></span></div></div> </form> <script type="text/javascript">var redirectUrl = "${redirect}";var LOGIN = {checkInput:function() {if ($("#loginname").val() == "") {alert("用戶名不能為空");$("#loginname").focus();return false;}if ($("#nloginpwd").val() == "") {alert("密碼不能為空");$("#nloginpwd").focus();return false;}return true;},doLogin:function() {//這里是一樣的功能,調(diào)用登錄的接口來(lái)實(shí)現(xiàn)的
$.post("/user/login", $("#formlogin").serialize(),function(data){if (data.status == 200) {alert("登錄成功!");if (redirectUrl == "") {location.href = "http://localhost:8082";} else {location.href = redirectUrl;}} else {alert("登錄失敗,原因是:" + data.msg);$("#loginname").select();}});},login:function() {if (this.checkInput()) {this.doLogin();}}};$(function(){$("#loginsubmit").click(function(){LOGIN.login();});}); </script> </body> </html>
轉(zhuǎn)載于:https://www.cnblogs.com/fengli9998/p/6403418.html
總結(jié)
- 上一篇: hihocoder A Game 区间d
- 下一篇: 一流大学计算机专业,计算机专业一流大学太