Skip to content

Commit c68c240

Browse files
adding warning and password rules on signup page
1 parent 265172a commit c68c240

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/main/java/com/example/treaders/controller/AllController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424

2525

26+
//Sanjay@123
27+
2628
@Controller
2729
public class AllController {
2830

@@ -86,10 +88,17 @@ public String Signup(){
8688
}
8789

8890
@PostMapping("/newuser")
89-
public String addNewUser(@RequestParam String email,@RequestParam String username, @RequestParam String password){
91+
public String addNewUser(@RequestParam String email,@RequestParam String username, @RequestParam String password,Model model){
9092
UserFormat user=new UserFormat();
9193
user.setEmail(email);
9294
user.setUsername(username);
95+
String regex = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@#]).+$";
96+
if(!password.matches(regex)){
97+
model.addAttribute("errorMessage", "Password must be at least 6 characters long and include at least one capital letter and one special character (@, #, or $).");
98+
model.addAttribute("email", email);
99+
model.addAttribute("username", username);
100+
return "signup";
101+
}
93102
user.setPassword(passwordEncoder.encode(password));
94103
UserRepo.save(user);
95104
return "redirect:/";

src/main/resources/static/css/signup.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ body {
6969
.login-link a:hover {
7070
text-decoration: underline;
7171
}
72+
73+
/* New CSS for Error Message */
74+
.signup-container .error {
75+
color: #d9534f; /* Bootstrap error color */
76+
background-color: #f2dede; /* Light red background for error messages */
77+
border: 1px solid #ebccd1; /* Border color matching the background */
78+
padding: 10px; /* Add some padding */
79+
margin-bottom: 20px; /* Space below the error message */
80+
border-radius: 5px; /* Slightly rounded corners */
81+
font-size: 0.9em; /* Slightly smaller font size */
82+
text-align: center; /* Center the error text */
83+
}

src/main/resources/templates/signup.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ <h2>Sign Up</h2>
1515
<input type="email" name="email" placeholder="Email Id" required>
1616
<input type="text" name="username" placeholder="User Name" required>
1717
<input type="password" name="password" placeholder="Password" required>
18+
<!-- Display the error message if there is one -->
19+
<div th:if="${errorMessage != null}" th:text="${errorMessage}" class="error"></div>
1820
<input type="submit" value="Sign Up">
1921
</form>
2022
<p class="login-link">Already have an account? <a href="/">Login</a></p>

0 commit comments

Comments
 (0)