Browse Source

Changes to error model and login/registration cards

Added json property names to error model
Switched to grid offset instead of changing card width using CSS
master
Rohan Sircar 5 years ago
parent
commit
febfaeec9a
  1. 16
      chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java
  2. 5
      chatto/src/main/java/org/ros/chatto/error/ErrorModel.java
  3. 3
      chatto/src/main/java/org/ros/chatto/error/ErrorResponse.java
  4. 1
      chatto/src/main/java/org/ros/chatto/service/ChatService.java
  5. 15
      chatto/src/main/resources/static/css/master.css
  6. 4
      chatto/src/main/resources/templates/chat.html
  7. 4
      chatto/src/main/resources/templates/home.html
  8. 2
      chatto/src/main/resources/templates/login.html
  9. 4
      chatto/src/main/resources/templates/registration.html
  10. 79
      chatto/src/main/resources/templates/user/home.html

16
chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java

@ -17,7 +17,6 @@ import org.ros.chatto.error.ErrorResponse;
import org.ros.chatto.service.ChatService;
import org.ros.chatto.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
@ -45,19 +44,18 @@ public class ChatMessageController {
@PostMapping(value = "/post/message", consumes = { "application/json" })
@ResponseBody
public ResponseEntity<?> newMessage(@RequestBody @Valid ChatMessageDTO chatMessageDTO,
Principal principal) {
// if (bindingResult.hasErrors()) {
//
//// return new ResponseEntity<List<FieldError>>(bindingResult.getFieldErrors(),HttpStatus.BAD_REQUEST);
// return new ResponseEntity<ErrorResponse>(handleException(bindingResult), HttpStatus.BAD_REQUEST);
// }
BindingResult bindingResult, Principal principal) {
if (bindingResult.hasErrors()) {
// return new ResponseEntity<List<FieldError>>(bindingResult.getFieldErrors(),HttpStatus.BAD_REQUEST);
return new ResponseEntity<ErrorResponse>(handleException(bindingResult), HttpStatus.BAD_REQUEST);
}
MessageCipherDTO messageCipher = chatMessageDTO.getMessageCipher();
String fromUser = principal.getName();
String toUser = chatMessageDTO.getToUser();
System.out.println("Message cipher = " + messageCipher);
chatMessageDTO = chatService.saveNewMessage(fromUser, toUser, messageCipher);
HttpHeaders responseHeader = new HttpHeaders();
return new ResponseEntity<ChatMessageDTO>(chatMessageDTO, responseHeader, HttpStatus.CREATED);
return new ResponseEntity<ChatMessageDTO>(chatMessageDTO, HttpStatus.CREATED);
}
/**

5
chatto/src/main/java/org/ros/chatto/error/ErrorModel.java

@ -1,5 +1,7 @@
package org.ros.chatto.error;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -8,8 +10,11 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public class ErrorModel{
@JsonProperty("field_name")
private String fieldName;
@JsonProperty("rejected_value")
private Object rejectedValue;
@JsonProperty("error_message")
private String messageError;

3
chatto/src/main/java/org/ros/chatto/error/ErrorResponse.java

@ -2,6 +2,8 @@ package org.ros.chatto.error;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -12,6 +14,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public class ErrorResponse {
@JsonProperty("errors")
private List<ErrorModel> errorMessage;
}

1
chatto/src/main/java/org/ros/chatto/service/ChatService.java

@ -8,7 +8,6 @@ import javax.validation.Valid;
import org.ros.chatto.dto.ChatMessageDTO;
import org.ros.chatto.dto.MessageCipherDTO;
import org.ros.chatto.dto.ReencryptionDTO;
import org.ros.chatto.model.ChatMessage;
import org.springframework.data.domain.PageRequest;
public interface ChatService {

15
chatto/src/main/resources/static/css/master.css

@ -109,18 +109,13 @@ textarea {
width: 80%;
}
#login-card {
/* #login-card {
width: 40%;
/* margin: 0 auto; */
/* Added */
/* float: none; */
/* Added */
/* margin-bottom: 10px; */
/* Added */
}
} */
@media only screen and (max-width: 600px) {
#login-card {
/* #login-card {
width: 90%;
}
} */
}

4
chatto/src/main/resources/templates/chat.html

@ -84,8 +84,8 @@
<label for="passphrase">Passphrase: </label>
<input class="form-control" type="password" id="passphrase" required>
</div>
<div class="form-group">
<button class="btn btn-secondary">Submit</button>
<div class="form-group text-center">
<button class="btn btn-secondary mx-auto">Submit</button>
</div>
</div>
</div>

4
chatto/src/main/resources/templates/home.html

@ -1,5 +1,5 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<div th:replace="fragments/head :: headFragment">
@ -29,7 +29,7 @@
<!-- <div class="jumbotron bg-primary"> -->
<div class="d-flex rounded">
<div class="p-4 align-self-end">
<div class="">
<h1 class="display-4">Chatto - Self Hosted, Minimal E2E Chat</h1>
<!-- <p th:if="${chatUser}" th:text="'username: ' + ${chatUser.userName}">You need to login</p>
<th:block th:each="userName: ${userNames}">

2
chatto/src/main/resources/templates/login.html

@ -38,7 +38,7 @@
<header>
<div class="container">
<div class="row">
<div class="col-sm py-5">
<div class=" col-lg-5 offset-lg-3 py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div class="card text-white bg-primary mb-3 text-center card-form rounded mx-auto" id="login-card">

4
chatto/src/main/resources/templates/registration.html

@ -15,9 +15,9 @@
<header>
<div class="container">
<div class="row">
<div class="col-sm py-5">
<div class="col-lg-5 offset-lg-3 py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div class="card text-white bg-primary mb-3 card-form rounded mx-auto" id="login-card">
<div class="card text-white bg-primary mb-3 card-form rounded mx-auto" id="registration-card">
<div class="card-body rounded">
<!-- <h4 class="card-title">Chat</h4> -->

79
chatto/src/main/resources/templates/user/home.html

@ -2,56 +2,51 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<div th:replace="fragments/head :: headFragment">
<title id="pageTitle">User Home</title>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" th:if="false"></script>
<script
src="http://blackpeppersoftware.github.io/thymeleaf-fragment.js/thymeleaf-fragment.js"
data-template-prefix="../" defer="defer" th:if="false"></script>
<link th:href="@{/css/master.css}" href="../../static/css/master.css"
rel="stylesheet" th:if="false">
<link th:href="@{/css/colors.css}" href="../../static/css/colors.css"
rel="stylesheet" th:if="false">
<div th:replace="fragments/head :: headFragment">
<title id="pageTitle">User Home</title>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" th:if="false"></script>
<script src="http://blackpeppersoftware.github.io/thymeleaf-fragment.js/thymeleaf-fragment.js" data-template-prefix="../" defer="defer" th:if="false"></script>
<link th:href="@{/css/master.css}" href="../../static/css/master.css" rel="stylesheet" th:if="false">
<link th:href="@{/css/colors.css}" href="../../static/css/colors.css" rel="stylesheet" th:if="false">
</head>
<body>
<div th:include="fragments/navbar :: navbarFragment"></div>
<header>
<div class="container ">
<div class="row">
<div class="col-sm py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div
class="card text-white bg-primary mb-3 text-center card-form rounded mx-auto">
<h1 class="display-4">User Page</h1>
<div class="card-body rounded">
<!-- <h4 class="card-title">Chat</h4> -->
<!-- <div class="form-group">
<div th:include="fragments/navbar :: navbarFragment"></div>
<header>
<div class="container ">
<div class="row">
<div class="col-sm py-5">
<!-- <h4 class="display-4 text-center py-2">Chat</h4> -->
<div class="card text-white bg-primary mb-3 text-center card-form rounded mx-auto">
<h1 class="display-4">User Page</h1>
<div class="card-body rounded">
<!-- <h4 class="card-title">Chat</h4> -->
<!-- <div class="form-group">
<textarea id="chatTextArea" class="form-control-lg py-2" disabled></textarea>
</div> -->
<!-- <form action="#" th:action="@{/seedstartermng}" th:object="${seedStarter}" method="post"> -->
<!-- th:action="@{/api/chat}" -->
<!-- <form action="#" th:action="@{/seedstartermng}" th:object="${seedStarter}" method="post"> -->
<!-- th:action="@{/api/chat}" -->
<div class="card-text">
<div class="card-text">
<div class="form-group">
<form action="#" th:action="@{/logout}" method="POST">
<!-- <input type="submit" value="logout"> -->
<!-- <input type="hidden" th:name="${_csrf.parameterName}"
<div class="form-group">
<form action="#" th:action="@{/logout}" method="POST">
<!-- <input type="submit" value="logout"> -->
<!-- <input type="hidden" th:name="${_csrf.parameterName}"
th:value="${_csrf.token}" /> -->
<button class="btn btn-secondary form-control">Logout</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<button class="btn btn-secondary form-control">Logout</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
</body>
Loading…
Cancel
Save