Ignore:
Timestamp:
02/04/23 19:01:47 (23 months ago)
Author:
milamihajlovska <mila.mihajlovska01@…>
Branches:
master
Children:
e097c1c
Parents:
27adfc8
Message:

login method

Location:
src/main/java/com/example/moviezone
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/model/Customer.java

    r27adfc8 r6032d44  
    2525    Integer points;
    2626
    27 //    public Customer(String password, String first_name, String last_name, String address, String contact_number, String username) {
    28 //        super(password, first_name, last_name, address, contact_number, username);
    29 //    }
     27    public Customer(String password, String first_name, String last_name, String address, String contact_number, String username) {
     28        super(password, first_name, last_name, address, contact_number, username);
     29    }
     30
     31    public Customer() {
     32
     33    }
    3034
    3135    @Override
  • src/main/java/com/example/moviezone/model/Worker.java

    r27adfc8 r6032d44  
    2828    Cinema cinema;
    2929
    30 //    public Worker(String password, String first_name, String last_name, String address, String contact_number, String username) {
    31 //        super(password, first_name, last_name, address, contact_number, username);
    32 //    }
     30    public Worker(String password, String first_name, String last_name, String address, String contact_number, String username) {
     31        super(password, first_name, last_name, address, contact_number, username);
     32    }
     33
     34    public Worker() {
     35
     36    }
    3337
    3438    @Override
  • src/main/java/com/example/moviezone/service/Impl/UserServiceImpl.java

    r27adfc8 r6032d44  
    3838    }
    3939
    40 //    @Override
    41 //    public User register(String first_name, String last_name, String username, String email, String number, String password, String role) {
    42 //        if(role.equals("worker"))
    43 //        {
    44 //            return userRepository.save(new Worker(passwordEncoder.encode(password),first_name,last_name,username,email,number));
    45 //        }
    46 //        else if (role.equals("user"))
    47 //            return userRepository.save(new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number));
    48 //    }
     40    @Override
     41    public User register(String first_name, String last_name, String username, String email, String number, String password, String role) {
     42        if(role.equals("worker"))
     43        {
     44            return userRepository.save(new Worker(passwordEncoder.encode(password),first_name,last_name,username,email,number));
     45        }
     46        else
     47            return userRepository.save(new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number));
     48    }
     49
     50    @Override
     51    public User login(String username, String password) {
     52        return userRepository.findAllByUsernameAndPassword(username,password).stream().findFirst().orElseThrow(UserNotFoundException::new);
     53    }
    4954
    5055
  • src/main/java/com/example/moviezone/service/UserService.java

    r27adfc8 r6032d44  
    1010    User findByUsername(String username);
    1111
    12 //    User register(String first_name, String last_name,String username, String email, String number, String password, String role);
    13 
     12  User register(String first_name, String last_name,String username, String email, String number, String password, String role);
     13    User login(String username,String password);
    1414}
  • src/main/java/com/example/moviezone/web/HomeController.java

    r27adfc8 r6032d44  
    2424    }
    2525
     26   
    2627
    2728}
Note: See TracChangeset for help on using the changeset viewer.