Changeset a436340 for src


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

Adding customer registration

Location:
src/main
Files:
11 added
2 deleted
15 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);
  • src/main/resources/data.sql

    rcc52b09 ra436340  
    44insert into stakeholder (id, created, email, first_name, last_name, modified, password, stakeholder_type, username)
    55values (nextval('hibernate_sequence'), current_timestamp, 'user1@schedlr.com', 'gjoko', 'kostadinov', current_timestamp, '$2a$10$Zc28AcCpAgxB.e67UMF/2.FgchjH9QWB7z8nP0TdkrFneV4IHPXji','CUSTOMER', 'user');
     6
     7insert into business_type (id, created, modified, name)
     8values (1, current_timestamp, current_timestamp, 'tailor'),
     9       (2, current_timestamp, current_timestamp, 'nail salon'),
     10       (3, current_timestamp, current_timestamp, 'massage parlor'),
     11       (4, current_timestamp, current_timestamp, 'makeup studio'),
     12       (5, current_timestamp, current_timestamp, 'hairdresser'),
     13       (6, current_timestamp, current_timestamp, 'barber');
     14
     15insert into service_type (id, created, modified, name, business_type_id)
     16values (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'haircut', 5),
     17       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'beard shaving', 6),
     18       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'eye brow plucking', 6),
     19       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'waxing', 6),
     20       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'nail extensions', 2),
     21       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'dress shortening', 1),
     22       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'holes fixing', 1);
  • src/main/resources/static/css/fullcalendar.css

    rcc52b09 ra436340  
    658658}
    659659
    660 body {
    661         margin-top: 40px;
    662         text-align: center;
    663         font-size: 14px;
    664         font-family: "Helvetica Nueue",Arial,Verdana,sans-serif;
    665         background-color: #DDDDDD;
    666 }
    667 
    668660#wrap {
    669661        width: 1100px;
  • src/main/resources/static/css/homepage.css

    rcc52b09 ra436340  
    33    float:left;
    44}
     5
     6.navbar {
     7    margin-bottom: 50px;
     8}
     9
     10body {
     11    background-color: #dbdbdb;
     12}
     13header {
     14    background-color: white;
     15}
     16
     17.bd-placeholder-img {
     18    font-size: 1.125rem;
     19    text-anchor: middle;
     20    -webkit-user-select: none;
     21    -moz-user-select: none;
     22    user-select: none;
     23}
     24
     25@media (min-width: 768px) {
     26    .bd-placeholder-img-lg {
     27        font-size: 3.5rem;
     28    }
     29}
     30
     31.b-example-divider {
     32    height: 3rem;
     33    background-color: rgba(0, 0, 0, .1);
     34    border: solid rgba(0, 0, 0, .15);
     35    border-width: 1px 0;
     36    box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
     37}
     38
     39.b-example-vr {
     40    flex-shrink: 0;
     41    width: 1.5rem;
     42    height: 100vh;
     43}
     44
     45.bi {
     46    vertical-align: -.125em;
     47    fill: currentColor;
     48}
     49
     50.nav-scroller {
     51    position: relative;
     52    z-index: 2;
     53    height: 2.75rem;
     54    overflow-y: hidden;
     55}
     56
     57.nav-scroller .nav {
     58    display: flex;
     59    flex-wrap: nowrap;
     60    padding-bottom: 1rem;
     61    margin-top: -1px;
     62    overflow-x: auto;
     63    text-align: center;
     64    white-space: nowrap;
     65    -webkit-overflow-scrolling: touch;
     66}
  • src/main/resources/templates/homepage.html

    rcc52b09 ra436340  
    22<html>
    33<head>
    4     <title>FullCalendar by Creative Tim </title>
     4    <title>Schedlr</title>
    55
    66    <meta charset="utf-8"/>
     
    1616    <link href='css/fullcalendar.print.css' rel='stylesheet' media='print'/>
    1717    <link href="css/homepage.css" rel="stylesheet" />
     18    <link href="css/headers.css" rel="stylesheet">
    1819</head>
    1920<body>
     21
     22<!-- Navbar start -->
     23<header class="p-3 mb-3 border-bottom">
     24    <div class="container">
     25        <div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
     26            <a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-dark text-decoration-none">
     27                <svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"/></svg>
     28            </a>
     29
     30            <ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
     31                <li><a href="#" class="nav-link px-2 link-secondary">Overview</a></li>
     32                <li><a href="#" class="nav-link px-2 link-dark">Inventory</a></li>
     33                <li><a href="#" class="nav-link px-2 link-dark">Customers</a></li>
     34                <li><a href="#" class="nav-link px-2 link-dark">Products</a></li>
     35            </ul>
     36
     37            <form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" role="search">
     38                <input type="search" class="form-control" placeholder="Search..." aria-label="Search">
     39            </form>
     40
     41            <div class="dropdown text-end">
     42                <a href="#" class="d-block link-dark text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
     43                    <img src="https://github.com/mdo.png" alt="mdo" width="32" height="32" class="rounded-circle">
     44                </a>
     45                <ul class="dropdown-menu text-small">
     46                    <li><a class="dropdown-item" href="#">New project...</a></li>
     47                    <li><a class="dropdown-item" href="#">Settings</a></li>
     48                    <li><a class="dropdown-item" href="#">Profile</a></li>
     49                    <li><hr class="dropdown-divider"></li>
     50                    <li><a class="dropdown-item" href="#">Sign out</a></li>
     51                </ul>
     52            </div>
     53        </div>
     54    </div>
     55</header>
     56<!-- Navbar end -->
     57
    2058<div id='wrap'>
    2159    <div id='calendar'></div>
     
    4078<script src='js/fullcalendar.js' type="text/javascript"></script>
    4179<script src="js/homepage.js" type="text/javascript"></script>
     80<script src="js/bootstrap.bundle.min.js"></script>
    4281</body>
    4382</html>
  • src/main/resources/templates/login.html

    rcc52b09 ra436340  
    33<head>
    44    <meta charset="UTF-8">
    5     <title>Login</title>
     5    <title>Schedlr</title>
    66
    77    <!-- Font Awesome -->
     
    6060
    6161                        <div class="text-center">
    62                             <p>No account? <a href="/register_customer" class="link-primary">Register</a></p>
     62                            <p>No account? <a href="/register_customer" class="link-primary">Register customer</a></p>
     63                        </div>
     64                        <div class="text-center">
     65                            <p>Offering services? <a href="/register_business" class="link-primary">Register company</a></p>
    6366                        </div>
    6467                        <!-- Register buttons -->
  • src/main/resources/templates/register_business.html

    rcc52b09 ra436340  
    33<head>
    44    <meta charset="UTF-8">
    5     <title>Register business</title>
     5    <title>Schedlr</title>
    66
    77    <!-- Font Awesome -->
     
    2020            rel="stylesheet"
    2121    />
    22     <link rel="stylesheet" href="css/register.css">
     22    <link rel="stylesheet" href="css/login.css">
     23
    2324</head>
    2425<body>
     
    4041                    <div class="card-body py-5 px-md-5">
    4142                        <form>
     43                            <div class="text-center">
     44                                <p>Personal Info</p>
     45                            </div>
     46
    4247                            <!-- 2 column grid layout with text inputs for the first and last names -->
    4348                            <div class="row">
    4449                                <div class="col-md-6 mb-4">
    4550                                    <div class="form-outline">
    46                                         <input type="text" id="form3Example1" class="form-control" />
    47                                         <label class="form-label" for="form3Example1">First name</label>
     51                                        <input type="text" id="firstName" class="form-control" />
     52                                        <label class="form-label" for="firstName">First name</label>
    4853                                    </div>
    4954                                </div>
    5055                                <div class="col-md-6 mb-4">
    5156                                    <div class="form-outline">
    52                                         <input type="text" id="form3Example2" class="form-control" />
    53                                         <label class="form-label" for="form3Example2">Last name</label>
     57                                        <input type="text" id="lastName" class="form-control" />
     58                                        <label class="form-label" for="lastName">Last name</label>
    5459                                    </div>
    5560                                </div>
     
    5863                            <!-- Email input -->
    5964                            <div class="form-outline mb-4">
    60                                 <input type="email" id="form3Example3" class="form-control" />
    61                                 <label class="form-label" for="form3Example3">Email address</label>
     65                                <input type="email" id="email" class="form-control" />
     66                                <label class="form-label" for="email">Email address</label>
     67                            </div>
     68
     69                            <!-- Email input -->
     70                            <div class="form-outline mb-4">
     71                                <input type="email" id="username" class="form-control" />
     72                                <label class="form-label" for="username">Username</label>
    6273                            </div>
    6374
    6475                            <!-- Password input -->
    6576                            <div class="form-outline mb-4">
    66                                 <input type="password" id="form3Example4" class="form-control" />
    67                                 <label class="form-label" for="form3Example4">Password</label>
     77                                <input type="password" id="password" class="form-control" />
     78                                <label class="form-label" for="password">Password</label>
    6879                            </div>
    6980
    70                             <!-- Checkbox -->
    71                             <div class="form-check d-flex justify-content-center mb-4">
    72                                 <input class="form-check-input me-2" type="checkbox" value="" id="form2Example33" checked />
    73                                 <label class="form-check-label" for="form2Example33">
    74                                     Subscribe to our newsletter
    75                                 </label>
     81                            <div class="text-center">
     82                                <p>Company Info</p>
    7683                            </div>
     84
     85                            <div class="form-outline mb-4">
     86                                <input type="email" id="companyName" class="form-control" />
     87                                <label class="form-label" for="companyName">Company Name</label>
     88                            </div>
     89
     90                            <div class="form-outline mb-4">
     91                                <select class="form-select" id="companyType">
     92                                    <option value="" disabled selected hidden>Company Type</option>
     93                                </select>
     94                            </div>
     95
     96                            <div class="form-group form-outline mb-4">
     97                                <label for="services">Services</label>
     98                                <input type="text" class="form-control" placeholder="Services" list="list-timezone" id="services">
     99                                <datalist id="list-timezone">
     100                                </datalist>
     101                            </div>
     102
    77103
    78104                            <!-- Submit button -->
     
    80106                                Sign up
    81107                            </button>
    82 
    83                             <!-- Register buttons -->
    84                             <div class="text-center">
    85                                 <p>or sign up with:</p>
    86                                 <button type="button" class="btn btn-link btn-floating mx-1">
    87                                     <i class="fab fa-facebook-f"></i>
    88                                 </button>
    89 
    90                                 <button type="button" class="btn btn-link btn-floating mx-1">
    91                                     <i class="fab fa-google"></i>
    92                                 </button>
    93 
    94                                 <button type="button" class="btn btn-link btn-floating mx-1">
    95                                     <i class="fab fa-twitter"></i>
    96                                 </button>
    97 
    98                                 <button type="button" class="btn btn-link btn-floating mx-1">
    99                                     <i class="fab fa-github"></i>
    100                                 </button>
    101                             </div>
    102108                        </form>
    103109                    </div>
     
    107113    </div>
    108114</div>
    109 <!-- Jumbotron -->
    110 <!-- MDB -->
     115<script src='js/jquery-1.10.2.js' type="text/javascript"></script>
    111116<script
    112117        type="text/javascript"
    113118        src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/5.0.0/mdb.min.js"
    114119></script>
     120<script src="js/register_business.js" type="text/javascript"></script>
     121<script src="js/bootstrap-autocomplete.min.js"></script>
    115122</body>
    116123</html>
  • src/main/resources/templates/register_customer.html

    rcc52b09 ra436340  
    33<head>
    44    <meta charset="UTF-8">
    5     <title>Register customer</title>
     5    <title>Schedlr</title>
     6
     7    <meta charset="utf-8"/>
     8    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    69
    710    <!-- Font Awesome -->
     
    2023            rel="stylesheet"
    2124    />
     25
    2226    <link rel="stylesheet" href="css/register.css">
    2327</head>
     
    110114    </div>
    111115</div>
    112 <!-- Jumbotron -->
    113 <!-- MDB -->
    114116<script
    115117        type="text/javascript"
    116118        src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/5.0.0/mdb.min.js"
    117119></script>
     120
    118121</body>
    119122</html>
Note: See TracChangeset for help on using the changeset viewer.