SCPPO(八):登录实现逻辑
2016-07-10 22:50
218 查看
【前言】
我们项目最近快要验收,验收的标准之一就是通过公司的安全检查!其中有一项标准:要求系统在登录五次失败后锁定系统!具体这个功能实现小编将在下篇博文为大家讲解。组长把这个任务安排给我,于是我就开始了探索之旅,在探索过程中发现许多好玩的东西,后来又经过组长的点播有所收获,在此与大家共享。
【登录逻辑分析】
基础:领完任务不敢稍有懈怠,打开代码看逻辑,首先不可绕过去的就是登录的逻辑:捋了半天,他丫的没找到在哪。。。非常郁闷~~~,好在经过组长点播:原来登录不是在这个项目中,而是在另外的项目,我们项目是通过引用DLL来通过那个项目控制。详情见下图:
登录逻辑详解:
1.界面表单提交:
<form class="form" id="signupForm"> <div class="search"> <form action="" method="post" class="form"> <div id="sea_text"> <input id="username" name="username" type="text" class="put" size="14" tabindex="1" placeholder="请输入用户名" value="@ViewBag.userName" style="background:#f5f6f7 url('../Content/Login/images/people.png') no-repeat 10px center; margin-left:10px"> <input type="password" id="userpass" name="userpass" class="put" size="14" tabindex="2" placeholder="不能小于{6}个字符!" value="" style="background:#f5f6f7 url('../Content/Login/images/key.png') no-repeat 10px center" /> <a href="javascript:void(0)" title="看不清,点击切换" style="line-height:30px;padding-bottom:5px;" onclick="changeCheckCode();return false;"><img id="imgCode" class="code" src="@Url.Action("GetValidateCode")?n=@System.DateTime.Now.Millisecond" /></a> <input type="text" id="code" name="code" value="1111" placeholder="输入验证码" tabindex="3" class="put" size="14" style=" width:70px; text-indent:inherit; margin-left:0px;" /> </div> <div id="btn"> <input name="button" type="button" class="btn1" tabindex="4" onclick="subm()" /></div> <div class="clear"></div> </form> </div> </form>
2.提交后执行的JS方法:
function subm() { <span style="font-family:KaiTi_GB2312;">//点击登录后进行操作</span> var check = $("#signupForm").valid(); if (check) { var strPassword = $.trim($("#userpass").val()); <span style="font-family:KaiTi_GB2312;"> //获取用户输入的密码</span> var userName = $.trim($("#username").val()); //<span style="font-family:KaiTi_GB2312;">获取用户输入的用户名</span> var code = $.trim($("#code").val()); //获取用户输入的<span style="font-family:KaiTi_GB2312;">验证码</span> $.ajax({ url: "../TotalManager/User/SavePassword", //<span style="font-family:KaiTi_GB2312;">调用Controller中的方法将密码保存到Session中</span> data: { password: strPassword }, type: "post", success: function (text) { $("#signupForm").submit(); <span style="font-family:KaiTi_GB2312;">//将表单进行提交</span> } }); } else { fnPosTri(); //输入内容不合法进行<span style="font-family:KaiTi_GB2312;">提示</span> } }
3.Ajax调用controller中的SavePassword方法(供系统之间跳转核实用):
<span style="font-family:KaiTi_GB2312;"> </span> /// <summary> /// 将输入的密码保存在Session中 /// </summary> /// <returns></returns> public JsonResult SavePassword() { string strPasswrod = Request["password"].ToString(); Session["Password"] = strPasswrod; return Json("", JsonRequestBehavior.AllowGet); }
4.存储Session成功后通过Submit方法将表单提交后,执行的PIMS.RP.UI.DLL中的方法[注此DLL是另外项目发布形成]:
/// <summary> /// 登录 /// </summary> /// <returns></returns> public ActionResult Login() { //获取用户名<span style="font-family:KaiTi_GB2312;">、</span>密码和验证码 string userName = Request.QueryString["us"] == null ? "" : Request.QueryString["us"]; string password = Request.QueryString["up"] == null ? "" : Request.QueryString["up"]; string code = Request.QueryString["code"] == null ? "" : Request.QueryString["code"]; string sCode = string.Empty; if (Session["ValidateCode"] != null) { sCode = Session["ValidateCode"].ToString(); } bool flag = true; if (code == sCode) flag = false; if (flag) { return View("Login"); } //验证用户输入 userName = ValidateMember.ValidateUserInputString(userName); password = ValidateMember.ValidateUserInputString(password); string sysId = ConfigurationManager.AppSettings["SysId"]; UpUsersComm user = PermissionManager.Instance.LoginVerify(userName, password, sysId); //判断用户是否登录 if (user != null) { PlatformContext.Current[Session.SessionID] = user; HttpContext.Session["userName"] = userName; Session["ValidateCode"] = null; Session["realName"] = user.RealName; FormsAuthentication.SetAuthCookie(userName, false); return RedirectToAction("Index", "Home"); } else { log.Error("用户名或密码无效"+userName+""+password); ViewBag.userName = string.IsNullOrEmpty(userName) ? "" : userName; return View(); } }温馨提示:在这个过程中我一直有个疑问,View中能直接调引用DLL中的方法吗?在网上找到个案例证明打消我的疑问:http://www.cnblogs.com/sunjie9606/p/4329815.html
【总结】
1.经过这么个流程将登录整个流程给搞懂了!2.发现一种新的方式,View能对应引用DLL中的Controller。
3.更加深刻体会到编程的乐趣。
相关文章推荐
- CSP考试 2013年12月第5题 I’m stuck! C语言实现
- C++11多线程之promise
- 巩固基础篇:数独彩色版(计算时间) 经典回溯法(可与八皇后问题对比)
- C++中括号()操作符的重载举例及解析
- Qt/C++ 数据库SQL 增删改查 语句示例
- 条款02:尽量以const,enum,inline替换#define
- 嵌入式开发为什么选择C语言?
- 巩固基础篇:八皇后问题:经典回溯法
- C++中临时对象及返回值优化
- 动态规划--最小调整代价
- C++之“using namespace std”的浅析
- 485ser.c
- C语言培训_005
- c语言实现的推箱子小游戏-1
- VS调试C++项目实例
- DEV调试C++项目实例
- C++之静态联编与动态联编及virtual关键字的作用
- C语言数据类型转换
- C++ virtual关键字深入理解
- 以下是C++的不同数据类型值的比较语句,请问这些判断语句中作为条件部分的语句编写有问题的有: