Ignore:
Timestamp:
03/03/24 21:45:56 (15 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
b78c0c1
Parents:
a3d63eb
Message:

RetaurantServiceImpl problemi
isAvailable od tableEntity...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/rezevirajmasa/demo/web/rest/AuthController.java

    ra3d63eb r303f51d  
    11package com.example.rezevirajmasa.demo.web.rest;
    22
     3import com.example.rezevirajmasa.demo.model.Customer;
     4import com.example.rezevirajmasa.demo.service.CustomerService;
     5import org.apache.coyote.Response;
    36import org.springframework.beans.factory.annotation.Autowired;
     7import org.springframework.http.HttpStatus;
     8import org.springframework.http.ResponseEntity;
    49import org.springframework.security.authentication.AuthenticationManager;
     10import org.springframework.security.crypto.password.PasswordEncoder;
     11import org.springframework.web.bind.annotation.CrossOrigin;
     12import org.springframework.web.bind.annotation.PostMapping;
     13import org.springframework.web.bind.annotation.RequestBody;
    514import org.springframework.web.bind.annotation.RestController;
    615
     16@CrossOrigin(origins = "http://localhost:3000/")
    717@RestController
    818public class AuthController {
     19    private final CustomerService customerService;
     20    private final PasswordEncoder passwordEncoder;
     21
     22    public AuthController(CustomerService customerService, PasswordEncoder passwordEncoder) {
     23        this.customerService = customerService;
     24        this.passwordEncoder = passwordEncoder;
     25    }
     26
     27    @PostMapping("/api/login")
     28    public ResponseEntity<String> login(@RequestBody Customer customer) {
     29        Customer exisitngCustomer = customerService.findByEmail(customer.getEmail());
     30
     31        if(passwordEncoder.matches(customer.getPassword(), exisitngCustomer.getPassword())) {
     32            String token = generateToken(exisitngCustomer);
     33            return ResponseEntity.ok(token);
     34        } else {
     35            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
     36        }
     37    }
     38
     39    private String generateToken(Customer customer) {
     40        // Implement your token generation logic here
     41        return "dummy_token";
     42    }
    943}
Note: See TracChangeset for help on using the changeset viewer.