Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #1

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d7ac4a2
feat:signup template design implemented
kazi-sahabuddin Nov 21, 2024
1b321f9
feat: user registration in progress
kazi-sahabuddin Nov 25, 2024
ec9f2a9
feat: server validation implemented
kazi-sahabuddin Nov 25, 2024
88c4e64
feat: server side validation fully implemented
kazi-sahabuddin Nov 27, 2024
ac91e36
feat: spring security initiated
kazi-sahabuddin Nov 27, 2024
6579bea
feat: spring security
kazi-sahabuddin Nov 28, 2024
383dead
feat: user dashboard
kazi-sahabuddin Nov 28, 2024
2b593af
feat:user dashboard design compleleted
kazi-sahabuddin Dec 1, 2024
4eaab5c
feat: add contact
kazi-sahabuddin Dec 2, 2024
8bc8334
feat: add contact implemented
kazi-sahabuddin Dec 2, 2024
fd8364f
feat: images upload implemented
kazi-sahabuddin Dec 3, 2024
1185c51
feat: view contacts ongoing
kazi-sahabuddin Dec 3, 2024
8e27300
feat: view contacts implemented
kazi-sahabuddin Dec 4, 2024
6795a24
pagination
kazi-sahabuddin Dec 5, 2024
bd60921
pagination completed
kazi-sahabuddin Dec 7, 2024
f47b9b2
feat: showing single contact details
kazi-sahabuddin Dec 8, 2024
ba5a4af
feat: contact delete feature implemented
kazi-sahabuddin Dec 9, 2024
924dccf
feat:contact update
kazi-sahabuddin Dec 10, 2024
efdbc6f
feat: user profile
kazi-sahabuddin Dec 12, 2024
b2900e9
fix: some link
kazi-sahabuddin Dec 13, 2024
68b92da
feat: search contact by name
kazi-sahabuddin Dec 19, 2024
31fd4df
feat: password change
kazi-sahabuddin Dec 21, 2024
9c49849
feat: implementing forget password in progress
kazi-sahabuddin Dec 29, 2024
f798135
feat:otp send using email in progress
kazi-sahabuddin Dec 31, 2024
b2e2087
fix: otp with emial sending success
kazi-sahabuddin Jan 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.sahabuddin.contactmanager.controllers;

import com.sahabuddin.contactmanager.entities.User;
import com.sahabuddin.contactmanager.helper.Message;
import com.sahabuddin.contactmanager.respositories.UserRepository;
import com.sahabuddin.contactmanager.services.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Controller
@RequiredArgsConstructor
public class HomeController {

private final UserRepository userRepository;

@GetMapping(value = "/home")
public String home(Model model) {
model.addAttribute("title", "Home | Contact Manager");
Expand All @@ -22,6 +33,36 @@ public String about(Model model) {
@GetMapping(value = "/signup")
public String signup(Model model) {
model.addAttribute("title", "Sign up | Contact Manager");
model.addAttribute("user", new User());
return "signup";
}

@PostMapping(value = "/do-register")
public String userSignup(@ModelAttribute("user") User user, @RequestParam(value = "agreement", defaultValue = "false") boolean agreement, Model model, HttpSession session) {
try{
if (!agreement) {
log.info("Agreement not available");
}
model.addAttribute("title", "Sign up | Contact Manager");
user.setRole("ROLE_USER");
user.setEnabled(true);
user.setImageUrl("default.png");
User saved = userRepository.save(user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a function in UserService to register user. Call this function from this controller.

log.info("User registered successfully {}", saved);
log.info("user info: {}", user.toString());
log.info("agreement: {}", agreement);

model.addAttribute("user", new User());
session.setAttribute("message", new Message("Registration successfully !", "alert-success"));


} catch (Exception e){
model.addAttribute("title", "Sign up | Contact Manager");
model.addAttribute("user", new User());
model.addAttribute("error", e.getMessage());
log.error("error: {}", e.getMessage());
session.setAttribute("message", new Message("Something went wrong!"+e.getMessage(), "alert-error"));
}
return "signup";
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/sahabuddin/contactmanager/helper/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sahabuddin.contactmanager.helper;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Message {

private String content;
private String type;
}
3 changes: 3 additions & 0 deletions src/main/resources/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
</div>
</nav>
<!--Navbar end-->
<div class="alert alert-primary" role="alert">
A simple primary alert—check it out!
</div>


<div th:replace="${content}"></div>
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
</div>

<h1 class="text-center">Register Here !!</h1>
<form th:action="@{/do-register}" method="post">
<form th:action="@{/do-register}" method="post" th:object="${user}">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" placeholder="Enter your name">
<input type="text" name="name" class="form-control" id="name" th:value="${user.name}" placeholder="Enter your name">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" placeholder="Enter your email">
<input type="email" name="email" class="form-control" id="email" th:value="${user.email}" placeholder="Enter your email">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter your password">
<input type="password" name="password" class="form-control" id="password" th:value="${user.password}" placeholder="Enter your password">
</div>
<div class="mb-3">
<label for="about">About</label>
<textarea class="form-control" rows="6" placeholder="about your self" id="about"></textarea>
<textarea name="about" th:value="user.about" class="form-control" rows="6" placeholder="about your self" id="about"></textarea>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
<input type="checkbox" name="agreement" class="form-check-input" id="agreement">
<label class="form-check-label" for="agreement">Accept terms and conditions</label>
</div>
<div class="container text-center">
<button type="submit" class="btn btn-primary d-block mb-2 w-100">Submit</button>
Expand Down