77: Spring login

jk·2024년 4월 23일
0

kdt 풀스택

목록 보기
117/127



1. eshopper - 에서 로그인후 메인페이지로 가도록 셋팅 하시오.

<!-- code1 -->
					<div class="login-form">
					</div>
					<script src="js/login.js"></script>
//code2
$("<h2>").appendTo($(".login-form"))
	.text("Login to your account")
;
$("<form>").appendTo($(".login-form"))
	.attr("id", "formLogin")
	.attr("action", "#")
;
$("<input>").appendTo($("#formLogin"))
	.attr("id", "inputLoginName")
	.attr("type", "text")
	.attr("placeholder", "Name")
;
$("<input>").appendTo($("#formLogin"))
	.attr("id", "inputLoginPassword")
	.attr("type", "password")
	.attr("placeholder", "Password")
;
$("<span>").appendTo($("#formLogin"))
	.attr("id", "spanLoginCheckbox")
;
$("<input>").appendTo($("#spanLoginCheckbox"))
	.attr("id", "inputLoginCheckbox")
	.attr("type", "checkbox")
	.addClass("checkbox")
;
$("<span>").appendTo($("#spanLoginCheckbox"))
	.attr("id", "spanLoginCheckboxText")
	.text("Keep me signed in")
;
$("<button>").appendTo($("#formLogin"))
	.attr("id", "buttonLoginSubmit")
	.attr("type", "submit")
	.addClass("btn btn-default")
	.text("Login")
	.on("click", function() {
		let username = $("#inputLoginName").val();
		let password = $("#inputLoginPassword").val();
		if (username != "" && password != "") {
			$.ajax({
				type: "post",
				url: "/eshopper/ajaxLogin",
				data: 
				{
					'username': username,
					'password': password
				},
				success: function(data, status) {
					if (data.length > 0) {
						sessionStorage.setItem('username', data[0]);
						console.log(sessionStorage.getItem('username'));
						window.location.replace("/eshopper/main");
					};
				},
			});
		};
		$("#inputLoginName").val("");
		$("#inputLoginPassword").val("");
	})
;
console.log("js/Login.js here.");
//code3
	@RequestMapping("/ajaxLogin")
	public List<String> ajaxLogin(@RequestParam("username") String username,
			@RequestParam("password") String password) {
		log.info("ajaxLogin()..");
		return eshopperService.login(username, password);
	}
//code4
	List<String> login(String username, String password);
//code5
	@Override
	public List<String> login(String username, String password) {
		log.info("login()..");
		return userMapper.selectUser(username, password);
	}
//code6
	List<String> selectUser(String username, String password);
<!-- code7 -->
    <select id="selectUser" resultType="String">
        <![CDATA[
			select username from users where username = #{username} and password = #{password}
        ]]>
    </select>
profile
Brave but clumsy

0개의 댓글