开发工具与关键技术: Visual Studio 2015 mvc
作者:彭水清
撰写时间:2019/7/4
这是登录的多种判断 ,里面有前台登录和后台登录 ,当选择前台登录时会跳转到前台页面
,选择后台登录的话则跳转到后台页面。用户将用户名 、密码 、验证码填写完毕后 ,点击登录将用户填写的值提交到控制器中进行判断 ,判断其用户名 ,密码 ,验证码是否正确
,如果判断正确将会按照用户选择的登录类型(前台管理/后台管理)进行页面跳转
这里是HTML的代码:
这是两个单选按钮的HTML代码,主要作用是用于选择登录的类型,类型要根据用户账号密码到数据库进行查询,查询出该账号密码的用户类型来判断选择的类型是否正确。
<div class="custom-control
custom-radio custom-control-inline mb-3">
<input type="radio" id="customRadioInline1" name="customRadioInline1" class="custom-control-input" checked
value="2">
<label class="custom-control-label h5" for="customRadioInline1">前台管理</label> </div>
<div class="custom-control
custom-radio custom-control-inline float-right">
<input type="radio" id="customRadioInline2" name="customRadioInline1" class="custom-control-input" value="3">
<label class="custom-control-label h5" for="customRadioInline2">后台管理</label>
</div>
var customRadioInline1 = $('#fmLogin [name="customRadioInline1"]:checked').val();
if (data == "success") {
if
(document.getElementById("customRadioInline1").checked)
{
layer.msg('登录成功');
window.location.href = "/BackStageManagement/EssentialData/FrontDesk";
//setTimeout(function() { }, 1000)定时器
}
else if (document.getElementById("customRadioInline2").checked)
{
layer.msg('登录成功');
window.location.href = "/BackStageManagement/EssentialData/EssentialData";
}
这是控制器的判断:
先获取到它的ID然后再通过联表查询数据库中是否有该用户和其用户类型,如果有就说明该用户类型正确。
try
{
User dbUser = (from tbUser in myModels.User
where tbUser.UserAccount == strUserAccount select tbUser).Single();
//用加密后的密码和数据库查询到的密码比较
if (strUserPassword ==dbUser.UserPassword)
{
//验证用户登录的角色是否为前台 , 后台
var listUserType = (from
tbUser in myModels.User join tbUserRoleDetails in
myModels.UserRoleDetails on tbUser.UserID equals tbUserRoleDetails.UserID
join tbUserType in myModels.UserType on tbUserRoleDetails.UserTypeID equals tbUserType.UserTypeID
where tbUser.UserID == dbUser.UserID && tbUserType.UserTypeID == strIcustomRadioInline1
select new
{
tbUserType.UserTypeID,
tbUserType.UserTypes,
}).ToList();
判断成功的效果图:
前台管理登录成功效果图:
后台管理登录成功效果图: