首页 > 代码库 > sso接口的调用
sso接口的调用
之前一直想sso接口已经写好了,登录注册功能是怎么调用的呢?原来在登录注册的jsp页面实现的接口的调用,页面的校验和验证功能在jsp页面即可实现。
注册页面:
<%@ 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>注册-个人用户</title> <link type="text/css" rel="stylesheet" href="http://www.mamicode.com/css/regist.personal.css"/> <link type="text/css" rel="stylesheet" href="http://www.mamicode.com/css/passport.base.css"/> <script type="text/javascript" src="http://www.mamicode.com/js/jquery-1.6.4.js"></script> </head> <body> <div class="w" id="logo"> <div> <a href="http://localhost:8082"> <img src="http://www.mamicode.com/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">个人用户</li> </ul> <div class="extra"> <span>我已经注册,现在就 <a href="http://www.mamicode.com/page/login" class="flk13">登录</a> </span> </div> </div> <div class="mc"> <form id="personRegForm" method="post" onsubmit="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" onpaste="return false;" value="" onfocus="if(this.value=http://www.mamicode.com/=‘‘) this.value=‘‘;this.style.color=‘#333‘" onblur="if(this.value=http://www.mamicode.com/=‘‘) {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>请设置密码:</span> <div class="fl item-ifo"> <input type="password" id="pwd" name="password" class="text" tabindex="2" style="ime-mode:disabled;" onpaste="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>请确认密码:</span> <div class="fl item-ifo"> <input type="password" id="pwdRepeat" name="pwdRepeat" class="text" tabindex="3" onpaste="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>验证手机:</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> <label id="phone_succeed" class="blank"></label> <label id="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" onclick="agreeonProtocol();"> <label for="protocol">我已阅读并同意<a href="http://www.mamicode.com/#" class="blue" id="protocol">《淘淘用户注册协议》</a></label> <span class="clr"></span> <label id="protocol_error" class="error hide">请接受服务条款</label> </div> </div> <div class="item"> <span class="label"> </span> <input type="button" class="btn-img btn-regist" id="registsubmit" value="http://www.mamicode.com/立即注册" tabindex="8" clstag="regist|keycount|personalreg|07" onclick="REGISTER.reg();"/> </div> </div> <div class="phone"> <img width="180" height="180" src="http://www.mamicode.com/images/phone-bg.jpg"> </div> <span class="clr"></span> </form> </div> <script type="text/javascript"> var REGISTER={ param:{ //单点登录系统的url surl:"" }, inputcheck:function(){ //不能为空检查 if ($("#regName").val() == "") { alert("用户名不能为空"); $("#regName").focus(); return false; } if ($("#pwd").val() == "") { alert("密码不能为空"); $("#pwd").focus(); return false; } if ($("#phone").val() == "") { alert("手机号不能为空"); $("#phone").focus(); return false; } //密码检查 if ($("#pwd").val() != $("#pwdRepeat").val()) { alert("确认密码和密码不一致,请重新输入!"); $("#pwdRepeat").select(); $("#pwdRepeat").focus(); return false; } return true; }, beforeSubmit:function() { //检查用户是否已经被占用 $.ajax({
//这是校验的接口调用,通过接口中的url来实现的 url : REGISTER.param.surl + "/user/check/"+escape($("#regName").val())+"/1?r=" + Math.random(), success : function(data) { if (data.data) { //检查手机号是否存在 $.ajax({ url : REGISTER.param.surl + "/user/check/"+$("#phone").val()+"/2?r=" + Math.random(), success : function(data) { if (data.data) { REGISTER.doSubmit(); } else { alert("此手机号已经被注册!"); $("#phone").select(); } } }); } else { alert("此用户名已经被占用,请选择其他用户名"); $("#regName").select(); } } }); }, doSubmit:function() {
//这是注册的接口,通过注册接口的URL来实现的调用 $.post("/user/register",$("#personRegForm").serialize(), function(data){ if(data.status == 200){ alert(‘用户注册成功,请登录!‘); REGISTER.login(); } else { alert("注册失败!"); } }); }, login:function() { location.href = "http://www.mamicode.com/page/login"; return false; }, reg:function() { if (this.inputcheck()) { this.beforeSubmit(); } } }; </script> </body> </html>
登录页面
<%@ 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="http://www.mamicode.com/css/login.css"/> <script type="text/javascript" src="http://www.mamicode.com/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="http://www.mamicode.com/images/taotao-logo.gif" alt="淘淘" width="170" height="60"/> </a><b></b> </div> </div> <form id="formlogin" method="post" onsubmit="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>键盘大写锁定已打开,请注意大小写</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="http://www.mamicode.com/登录" tabindex="8" clstag="passport|keycount|login|06"/> </div> </div> </div> <div class="free-regist"> <span><a href="http://www.mamicode.com/page/register" clstag="passport|keycount|login|08">免费注册>></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() {
//这里是一样的功能,调用登录的接口来实现的
$.post("/user/login", $("#formlogin").serialize(),function(data){ if (data.status == 200) { alert("登录成功!"); if (redirectUrl == "") { location.href = "http://localhost:8082"; } else { location.href = http://www.mamicode.com/redirectUrl;"登录失败,原因是:" + data.msg); $("#loginname").select(); } }); }, login:function() { if (this.checkInput()) { this.doLogin(); } } }; $(function(){ $("#loginsubmit").click(function(){ LOGIN.login(); }); }); </script> </body> </html>
sso接口的调用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。