Changes between Version 17 and Version 18 of UseCaseImplementation


Ignore:
Timestamp:
02/20/25 16:04:08 (2 days ago)
Author:
222077
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCaseImplementation

    v17 v18  
    539539
    540540
     541== **ID-6** - Register
     542The `/register` endpoint provides user registration functionality, allowing new users to create accounts in the system.
     543It supports basic user registration with name, surname, email, and password validation.
     544
     545=== Registration Flow
     546The registration process follows these steps:
     547 1. User accesses the registration page: `/register`
     548 2. User fills out the registration form with required information
     549 3. System validates the input and creates a new account
     550 4. User is redirected to login page upon successful registration
     551
     552===
     553{{{
     554    @Controller
     555    @RequestMapping("/register")
     556    public class RegisterController {
     557        private final AccountService accountService;
     558
     559        @GetMapping
     560        public String registerPage(@RequestParam(required = false) String error,
     561                                   Model model) {
     562            if (error != null) {
     563                model.addAttribute("errorMessage", error);
     564            }
     565            model.addAttribute("display", "register");
     566            return "master";
     567        }
     568
     569        @PostMapping
     570        private String registerUser(@RequestParam String name,
     571                                    @RequestParam String surname,
     572                                    @RequestParam String email,
     573                                    @RequestParam String password,
     574                                    @RequestParam String confirmPassword) {
     575            try {
     576                accountService.save(email, name, surname, password, confirmPassword);
     577            } catch (Exception e) {
     578                return String.format("redirect:/register?error=%s", e.getMessage());
     579            }
     580            return "redirect:/login";
     581        }
     582    }
     583}}}
     584===
     585
     586==== Controller Details: 
     587- **URL Mapping:** `/register` 
     588- **Methods:**
     589  - `GET`: Displays registration form
     590  - `POST`: Processes registration request
     591- **Functionality:** 
     592  - Displays registration form with error handling
     593  - Processes user registration with field validation
     594  - Handles registration errors and displays appropriate messages
     595  - Redirects to login page upon successful registration
     596- **View:** Uses the `master` template and dynamically embeds `register` view
     597
     598==== Registration Fields:
     599- **Required Information:**
     600  - Name
     601  - Surname
     602  - Email (used as username for login)
     603  - Password
     604  - Password Confirmation
     605
     606
     607===
     608==== Result of `/register` page
     609[[Image(register.png, 100%)]]
     610===