-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f56c6e
commit d5a8306
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.sptp.backend.home; | ||
|
||
import com.sptp.backend.member.service.MemberService; | ||
import com.sptp.backend.member.web.dto.request.MemberLoginRequestDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class HomeController { | ||
|
||
private final MemberService memberService; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
@PostMapping("/login") | ||
public String login(String username, String password) { | ||
System.out.println(username + " " + password); | ||
memberService.login(MemberLoginRequestDto.builder() | ||
.userId(username) | ||
.password(password) | ||
.build()); | ||
|
||
return "redirect:/index"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var stompClient = null; | ||
|
||
function setConnected(connected) { | ||
$("#connect").prop("disabled", connected); | ||
$("#disconnect").prop("disabled", !connected); | ||
if (connected) { | ||
$("#conversation").show(); | ||
} | ||
else { | ||
$("#conversation").hide(); | ||
} | ||
$("#greetings").html(""); | ||
} | ||
|
||
function connect() { | ||
var socket = new SockJS('/ws-connection'); | ||
stompClient = Stomp.over(socket); | ||
stompClient.connect({}, function (frame) { | ||
setConnected(true); | ||
console.log('Connected: ' + frame); | ||
stompClient.subscribe('/topic/greetings', function (greeting) { | ||
showGreeting(JSON.parse(greeting.body).content); | ||
}); | ||
}); | ||
} | ||
|
||
function disconnect() { | ||
if (stompClient !== null) { | ||
stompClient.disconnect(); | ||
} | ||
setConnected(false); | ||
console.log("Disconnected"); | ||
} | ||
|
||
function sendName() { | ||
stompClient.send("/app/hello", {}, JSON.stringify({'name': $("#name").val()})); | ||
} | ||
|
||
function showGreeting(message) { | ||
$("#greetings").append("<tr><td>" + message + "</td></tr>"); | ||
} | ||
|
||
$(function () { | ||
$("form").on('submit', function (e) { | ||
e.preventDefault(); | ||
}); | ||
$( "#connect" ).click(function() { connect(); }); | ||
$( "#disconnect" ).click(function() { disconnect(); }); | ||
$( "#send" ).click(function() { sendName(); }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello WebSocket</title> | ||
<link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet"> | ||
<link href="/main.css" rel="stylesheet"> | ||
<script src="/webjars/jquery/jquery.min.js"></script> | ||
<script src="/webjars/sockjs-client/sockjs.min.js"></script> | ||
<script src="/webjars/stomp-websocket/stomp.min.js"></script> | ||
<script src="/app.js"></script> | ||
</head> | ||
<body> | ||
<noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websocket relies on Javascript being | ||
enabled. Please enable | ||
Javascript and reload this page!</h2></noscript> | ||
<div id="main-content" class="container"> | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<form class="form-inline"> | ||
<div class="form-group"> | ||
<label for="connect">WebSocket connection:</label> | ||
<button id="connect" class="btn btn-default" type="submit">Connect</button> | ||
<button id="disconnect" class="btn btn-default" type="submit" disabled="disabled">Disconnect | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="col-md-6"> | ||
<form class="form-inline"> | ||
<div class="form-group"> | ||
<label for="name">What is your name?</label> | ||
<input type="text" id="name" class="form-control" placeholder="Your name here..."> | ||
</div> | ||
<button id="send" class="btn btn-default" type="submit">Send</button> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<table id="conversation" class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Greetings</th> | ||
</tr> | ||
</thead> | ||
<tbody id="greetings"> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |