Changeset a436340 for src/main/java/edu


Ignore:
Timestamp:
02/05/23 19:55:10 (22 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
2b0a4db
Parents:
cc52b09
Message:

Adding customer registration

Location:
src/main/java/edu/gjoko/schedlr
Files:
5 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java

    rcc52b09 ra436340  
    4545        http.csrf()
    4646                .disable()
    47                 .authorizeRequests()
    48                 .antMatchers("/login").permitAll()
    49                 .antMatchers("/register_customer").permitAll()
    50                 .antMatchers("/register_business").permitAll()
    51                 .antMatchers("/homepage").permitAll()
    52                 .antMatchers("/css/**").permitAll()
    53                 .antMatchers("/js/**").permitAll()
    54                 .antMatchers("/anonymous*").anonymous()
    55                 .anyRequest()
    56                 .fullyAuthenticated()
    57                 .and()
    5847                .httpBasic()
    5948                .authenticationEntryPoint(new AppAuthenticationEntryPoint())
     
    6453                .loginProcessingUrl("/login")
    6554                .successHandler(authenticationSuccessHandler)
    66                 .defaultSuccessUrl("/homepage");
     55                .defaultSuccessUrl("/homepage")
     56                .and()
     57                .authorizeRequests()
     58                .antMatchers("/login").permitAll()
     59                .antMatchers("/register_customer").permitAll()
     60                .antMatchers("/register_business").permitAll()
     61                .antMatchers("/api/nomenclatures/*").permitAll()
     62                .antMatchers("/homepage").permitAll()
     63                .antMatchers("/css/**").permitAll()
     64                .antMatchers("/js/**").permitAll()
     65                .antMatchers("/anonymous*").anonymous()
     66                .anyRequest()
     67                .fullyAuthenticated();
    6768    }
    6869}
  • src/main/java/edu/gjoko/schedlr/controllers/HomePageController.java

    rcc52b09 ra436340  
    11package edu.gjoko.schedlr.controllers;
    22
    3 import edu.gjoko.schedlr.entity.Search;
    43import org.springframework.stereotype.Controller;
    54import org.springframework.ui.Model;
    65import org.springframework.web.bind.annotation.GetMapping;
    7 import org.springframework.web.bind.annotation.ModelAttribute;
    86import org.springframework.web.bind.annotation.PostMapping;
     7
     8import java.security.Principal;
    99
    1010@Controller
     
    1212
    1313    @GetMapping(name = "/homepage")
    14     public String getHomePageTemplate(Model model, @ModelAttribute("search")Search search ) {
    15         model.addAttribute("search", search);
     14    public String getHomePageTemplate(Model model, Principal principal) {
     15        System.out.println(principal);
    1616        return "homepage";
    1717    }
    1818
    1919    @PostMapping(name = "/homepage")
    20     public String postHomePageTemplate(Model model, @ModelAttribute("search")Search search) {
    21         model.addAttribute("search", search);
     20    public String postHomePageTemplate(Model model) {
    2221        return "homepage";
    2322    }
  • src/main/java/edu/gjoko/schedlr/controllers/LoginController.java

    rcc52b09 ra436340  
    1212
    1313    @GetMapping(path = "/login")
    14     public String getMapping(Model model) {
    15         model.addAttribute("stakeholder", new Stakeholder());
     14    public String getMapping(@ModelAttribute Stakeholder customer, Model model) {
    1615        return "login";
    1716    }
  • src/main/java/edu/gjoko/schedlr/controllers/RegisterController.java

    rcc52b09 ra436340  
    2929    public String registerCustomer(@ModelAttribute Stakeholder customer, Model model) {
    3030        Stakeholder user = stakeholderService.saveStakeholder(customer);
    31         model.addAttribute("user", user);
    32         return "redirect:homepage";
     31        return "redirect:login";
    3332    }
    3433
  • src/main/java/edu/gjoko/schedlr/entity/Business.java

    rcc52b09 ra436340  
    11package edu.gjoko.schedlr.entity;
    22
     3import com.fasterxml.jackson.annotation.JsonManagedReference;
    34import lombok.AllArgsConstructor;
    45import lombok.Getter;
     
    2526    private String name;
    2627
    27     @Column(name = "business_type")
    28     @Enumerated(EnumType.STRING)
     28    @OneToOne
     29    @JoinColumn(name = "business_type_id", referencedColumnName = "id")
    2930    private BusinessType businessType;
    3031
     
    3940    private Stakeholder owner;
    4041
     42    @OneToMany(mappedBy = "business")
     43    @JsonManagedReference
     44    private List<Service> services;
     45
    4146    @Column(name = "created")
    4247    private LocalDateTime created;
     
    4550    private LocalDateTime modified;
    4651
    47     @OneToMany(mappedBy = "business")
    48     private List<Service> services;
     52
    4953}
  • src/main/java/edu/gjoko/schedlr/entity/BusinessType.java

    rcc52b09 ra436340  
    11package edu.gjoko.schedlr.entity;
    22
    3 public enum BusinessType {
    4     TAILOR,
    5     NAIL_SALON,
    6     MASSAGE_PARLOR,
    7     MAKEUP_STUDIO,
    8     HAIRDRESSER,
    9     BARBER
     3import com.fasterxml.jackson.annotation.JsonIgnore;
     4import com.fasterxml.jackson.annotation.JsonManagedReference;
     5import com.fasterxml.jackson.annotation.JsonProperty;
     6import lombok.AllArgsConstructor;
     7import lombok.Getter;
     8import lombok.NoArgsConstructor;
     9import lombok.Setter;
     10import org.springframework.data.annotation.CreatedDate;
     11import org.springframework.data.annotation.LastModifiedDate;
     12import org.springframework.data.jpa.domain.support.AuditingEntityListener;
     13
     14import javax.persistence.*;
     15import java.time.LocalDateTime;
     16import java.util.List;
     17
     18@Entity
     19@EntityListeners(AuditingEntityListener.class)
     20@Table(name = "business_type")
     21@Getter
     22@Setter
     23@NoArgsConstructor
     24@AllArgsConstructor
     25public class BusinessType {
     26
     27    @Id
     28    @GeneratedValue(strategy = GenerationType.SEQUENCE)
     29    @JsonProperty("value")
     30    private Long id;
     31
     32    @Column(name = "name")
     33    @JsonProperty("text")
     34    private String name;
     35
     36    @OneToMany(mappedBy="businessType")
     37    @JsonManagedReference
     38    private List<ServiceType> serviceTypes;
     39
     40    @Column(name = "created")
     41    @CreatedDate
     42    @JsonIgnore
     43    private LocalDateTime created;
     44
     45    @Column(name = "modified")
     46    @LastModifiedDate
     47    @JsonIgnore
     48    private LocalDateTime modified;
    1049}
  • src/main/java/edu/gjoko/schedlr/entity/Service.java

    rcc52b09 ra436340  
    11package edu.gjoko.schedlr.entity;
    22
     3import com.fasterxml.jackson.annotation.JsonBackReference;
    34import lombok.AllArgsConstructor;
    45import lombok.Getter;
     
    3536    private Float price;
    3637
     38    @OneToOne
     39    @JoinColumn(name = "service_type_id", referencedColumnName = "id")
     40    private ServiceType serviceType;
     41
    3742    @ManyToOne
    38     @JoinColumn(name = "business_id")
     43    @JoinColumn(name="business_fk")
     44    @JsonBackReference
    3945    private Business business;
    4046
  • src/main/java/edu/gjoko/schedlr/services/StakeholderService.java

    rcc52b09 ra436340  
    44import edu.gjoko.schedlr.entity.StakeholderType;
    55import edu.gjoko.schedlr.repositories.StakeholderRepository;
     6import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    67import org.springframework.stereotype.Service;
    78
     
    1011
    1112    private StakeholderRepository stakeholderRepository;
     13    private BCryptPasswordEncoder bCryptPasswordEncoder;
    1214
    13     public StakeholderService(StakeholderRepository stakeholderRepository) {
     15    public StakeholderService(StakeholderRepository stakeholderRepository,
     16                              BCryptPasswordEncoder bCryptPasswordEncoder) {
    1417        this.stakeholderRepository = stakeholderRepository;
     18        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    1519    }
    1620
    1721    public Stakeholder saveStakeholder(Stakeholder stakeholder) {
     22        stakeholder.setPassword(bCryptPasswordEncoder.encode(stakeholder.getPassword()));
    1823        stakeholder.setStakeholderType(StakeholderType.CUSTOMER);
    1924        return stakeholderRepository.save(stakeholder);
Note: See TracChangeset for help on using the changeset viewer.