CRM顧客関係管理システムログインモジュール分析とログオン終了
4739 ワード
フロント
ログインページにアクセスし、ブラウザがバックグラウンドログインボタンを要求してonclickイベントをバインド
SpringMVCにはフロントページへのパスが配置されているのでreturnはファイル名を書くだけでそのファイルを指すことができます
jsコード:1.ユーザ名とパスワードの空でないチェック
ajaxリクエストの送信
リクエストはバックグラウンドに入り、ControllerレイヤはUserInfoクラス、フィールドを作成しました.
サービス層の呼び出し
2.ユーザ名でユーザ3を問い合わせる.一致するパスワード
ブレークスルークラスとStringUtilを使用して文字列が空でないことを判断
判断完了パラメータをUserInfoに設定
dao層
UserMapper.xmlの構成
ログインを終了してクッキー情報をクリアし、ログインページにジャンプ
ログインページにアクセスし、ブラウザがバックグラウンドログインボタンを要求してonclickイベントをバインド
@Controller
public class IndexController extends BaseController {
@RequestMapping("index")
public String index(HttpServletRequest request){
return "index";
}
}
SpringMVCにはフロントページへのパスが配置されているのでreturnはファイル名を書くだけでそのファイルを指すことができます
onclick="login()"
jsコード:1.ユーザ名とパスワードの空でないチェック
if(isEmpty(userName)){
alert(" ");
return;
}
if(isEmpty(userPwd)){
alert(" ");
return;
}
ajaxリクエストの送信
var userName = $('#username').val();
var userPwd = $('#password').val();
$.ajax({
url:ctx+"/user/login",
type:'post',
data:{
userName:userName,
userPwd:userPwd,
},
success:function (data) {
// console.log(data
if (data.code==200){
alert(data.msg); //
// cookie
$.cookie('userIdStr',data.result.userIdStr);
$.cookie('userName',data.result.userName);
$.cookie('realName',data.result.realName);
//
window.location.href=ctx+`/main`;
}else {
alert(data.msg);
}
}
});
リクエストはバックグラウンドに入り、ControllerレイヤはUserInfoクラス、フィールドを作成しました.
private String userIdStr; //id
private String userName;
private String realName;
@RequestMapping("login")
@ResponseBody
public ResultInfo login(String userName,String userPwd){
UserInfo userInfo= userService.login(userName,userPwd);
return success(" ",userInfo);}
サービス層の呼び出し
2.ユーザ名でユーザ3を問い合わせる.一致するパスワード
ブレークスルークラスとStringUtilを使用して文字列が空でないことを判断
Util , lang3
public static boolean isBlank(CharSequence cs) {
int strLen;
if (cs != null && (strLen = cs.length()) != 0) {
for(int i = 0; i < strLen; ++i) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
} else {
return true;
}
}
//1. userName userPwd
AssertUtil.isTrue(StringUtils.isBlank(userName)," !");
AssertUtil.isTrue(StringUtils.isBlank(userPwd)," !");
//2.
User user= userMapper.queryUserByName(userName);
AssertUtil.isTrue(user==null," ");
//3. , ,
AssertUtil.isTrue(!Md5Util.encode(userPwd).equals(user.getUserPwd())," ");
return createUserInfo(user);`
判断完了パラメータをUserInfoに設定
private UserInfo createUserInfo(User user) {
UserInfo userInfo = new UserInfo();
// id
userInfo.setUserIdStr(UserIDBase64.encoderUserID(user.getId()));
userInfo.setUserName(user.getUserName());
userInfo.setRealName(user.getTrueName());
return userInfo;
}
dao層
//
public User queryUserByName(String userName);
UserMapper.xmlの構成
ログインを終了してクッキー情報をクリアし、ログインページにジャンプ
//
function logout() {
/**
* 1. cookie
* 2.
*/
$.messager.confirm(' crm',' ?',function (r) {
if (r){
$.removeCookie("userIdStr");
$.removeCookie("userName");
$.removeCookie("realName");
window.location.href=ctx+'/index';
}
});
}