mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Merge pull request #103 from cheapy-ispp/015-Registro-#62
015 registro #62
This commit is contained in:
commit
3ae808a2c5
9 changed files with 39 additions and 112 deletions
|
@ -36,6 +36,7 @@ public class Client extends BaseEntity {
|
|||
private String address;
|
||||
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
@NotNull
|
||||
private Municipio municipio;
|
||||
|
||||
// Hora de apertura del local
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
public enum Municipio {
|
||||
sevilla,dosHermanas,carmona,bollullos,pilas,montellano,mairenaAljarafe,mairenaAlcor
|
||||
sevilla,dos_hermanas,carmona,bollullos,pilas,montellano,mairena_aljarafe,mairena_alcor
|
||||
}
|
||||
|
|
|
@ -90,14 +90,6 @@ public class Usuario extends BaseEntity{
|
|||
}
|
||||
|
||||
|
||||
public User getUsuar() {
|
||||
return usuar;
|
||||
}
|
||||
|
||||
public void setUsuar(User username) {
|
||||
this.usuar = username;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,12 @@
|
|||
*/
|
||||
package org.springframework.cheapy.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.Authorities;
|
||||
import org.springframework.cheapy.repository.AuthoritiesRepository;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class AuthoritiesService {
|
||||
|
|
|
@ -53,9 +53,6 @@ public class ClientService {
|
|||
return this.clientRepository.findByUsername(username);
|
||||
}
|
||||
|
||||
public void saveClient(final Client client) throws DataAccessException {
|
||||
this.clientRepository.save(client);
|
||||
}
|
||||
@Transactional
|
||||
public List<Client> findAllClient() throws DataAccessException {
|
||||
return this.clientRepository.findAllClient();
|
||||
|
|
|
@ -5,15 +5,6 @@ import java.util.List;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.Usuario;
|
||||
|
||||
package org.springframework.cheapy.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.model.Usuario;
|
||||
import org.springframework.cheapy.repository.UserRepository;
|
||||
|
||||
import org.springframework.cheapy.repository.UsuarioRepository;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.springframework.cheapy.system;
|
|||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -10,16 +11,15 @@ import org.springframework.cheapy.model.Authorities;
|
|||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.Code;
|
||||
import org.springframework.cheapy.model.Municipio;
|
||||
import org.springframework.cheapy.model.Owner;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.model.Usuario;
|
||||
import org.springframework.cheapy.service.AuthoritiesService;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.OwnerService;
|
||||
import org.springframework.cheapy.service.UserService;
|
||||
import org.springframework.cheapy.service.UsuarioService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -51,11 +51,21 @@ public class SingUpController {
|
|||
this.usuarioService = usuarioService;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
private boolean checkTimes(final Client client) {
|
||||
boolean res = false;
|
||||
if(client.getFinish()==null || client.getInit()==null || client.getFinish().isAfter(client.getInit())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@GetMapping("/users/new")
|
||||
public String singUpUserForm(Map<String, Object> model) {
|
||||
|
@ -106,9 +116,9 @@ public class SingUpController {
|
|||
}
|
||||
|
||||
@PostMapping("/clients/new")
|
||||
public String singUpClientForm(/*@Valid User user,*/ @Valid Client cliente, BindingResult result) {
|
||||
public String singUpClientForm(/*@Valid User user,*/ @Valid Client cliente, final BindingResult result, final ModelMap model,
|
||||
HttpServletRequest request) {
|
||||
Authorities auth=new Authorities();
|
||||
System.out.println(cliente.getCode().getCode());
|
||||
String cod=cliente.getCode().getCode();
|
||||
Code code=this.clientService.findCodeByCode(cod);
|
||||
User user= cliente.getUsuar();
|
||||
|
@ -116,13 +126,17 @@ public class SingUpController {
|
|||
cliente.setUsuar(user);
|
||||
auth.setUsername(user.getUsername());
|
||||
auth.setAuthority("client");
|
||||
if(!this.checkTimes(cliente)) {
|
||||
result.rejectValue("finish","" ,"La hora de cierre debe ser posterior a la hora de apertura");
|
||||
|
||||
}
|
||||
if (result.hasErrors()) {
|
||||
model.put("municipio", Municipio.values());
|
||||
model.put("cliente", cliente);
|
||||
return "singup/singUpClient";
|
||||
}else if(code.getActivo().equals(false)) {
|
||||
return "error";
|
||||
}else {
|
||||
//auth.setId(1);
|
||||
//this.authoritiesService.saveAuthorities(auth);
|
||||
code.setActivo(false);
|
||||
this.clientService.saveCode(code);
|
||||
cliente.setCode(code);
|
||||
|
@ -134,65 +148,4 @@ public class SingUpController {
|
|||
return "redirect:/";
|
||||
}
|
||||
}
|
||||
// @GetMapping("/owners/find")
|
||||
// public String initFindForm(Map<String, Object> model) {
|
||||
// model.put("owner", new Owner());
|
||||
// return "owners/findOwners";
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/owners")
|
||||
// public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {
|
||||
//
|
||||
// // allow parameterless GET request for /owners to return all records
|
||||
// if (owner.getLastName() == null) {
|
||||
// owner.setLastName(""); // empty string signifies broadest possible search
|
||||
// }
|
||||
//
|
||||
// // find owners by last name
|
||||
// Collection<Owner> results = this.ownerService.findByLastName(owner.getLastName());
|
||||
// if (results.isEmpty()) {
|
||||
// // no owners found
|
||||
// result.rejectValue("lastName", "notFound", "not found");
|
||||
// return "owners/findOwners";
|
||||
// }
|
||||
// else if (results.size() == 1) {
|
||||
// // 1 owner found
|
||||
// owner = results.iterator().next();
|
||||
// return "redirect:/owners/" + owner.getId();
|
||||
// }
|
||||
// else {
|
||||
// // multiple owners found
|
||||
// model.put("selections", results);
|
||||
// return "owners/ownersList";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/owners/{ownerId}/edit")
|
||||
// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||
// Owner owner = this.ownerService.findOwnerById(ownerId);
|
||||
// model.addAttribute(owner);
|
||||
// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/owners/{ownerId}/edit")
|
||||
// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
|
||||
// @PathVariable("ownerId") int ownerId) {
|
||||
// if (result.hasErrors()) {
|
||||
// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
// }
|
||||
// else {
|
||||
// owner.setId(ownerId);
|
||||
// this.ownerService.saveOwner(owner);
|
||||
// return "redirect:/owners/{ownerId}";
|
||||
// }
|
||||
// }
|
||||
// @GetMapping("/owners/{ownerId}")
|
||||
// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
|
||||
// ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
||||
// Owner owner = this.ownerService.findOwnerById(ownerId);
|
||||
//
|
||||
// mav.addObject(owner);
|
||||
// return mav;
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
|
|
@ -1,34 +1,22 @@
|
|||
INSERT INTO owners VALUES (1, 'Javi', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023');
|
||||
INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749');
|
||||
INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763');
|
||||
INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198');
|
||||
INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765');
|
||||
INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654');
|
||||
INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387');
|
||||
INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683');
|
||||
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||
|
||||
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE );
|
||||
INSERT INTO users (username,password,enabled) VALUES ('admin','admin', TRUE );
|
||||
INSERT INTO authorities (username,authority) VALUES ('admin','admin');
|
||||
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE );
|
||||
INSERT INTO users (username,password,enabled) VALUES ('manoli','manoli', TRUE );
|
||||
INSERT INTO authorities (username,authority) VALUES ('manoli','client');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE );
|
||||
INSERT INTO users (username,password,enabled) VALUES ('david','david', TRUE );
|
||||
INSERT INTO authorities (username,authority) VALUES ('david','client');
|
||||
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','paco','paco', TRUE );
|
||||
INSERT INTO users (username,password,enabled) VALUES ('paco','paco', TRUE );
|
||||
INSERT INTO authorities (username,authority) VALUES ('paco','usuario');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','lolo','lolo', TRUE );
|
||||
INSERT INTO users (username,password,enabled) VALUES ('lolo','lolo', TRUE );
|
||||
INSERT INTO authorities (username,authority) VALUES ('lolo','usuario');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','pepe','pepe', TRUE );
|
||||
INSERT INTO users (username,password,enabled) VALUES ('pepe','pepe', TRUE );
|
||||
INSERT INTO authorities (username,authority) VALUES ('pepe','usuario');
|
||||
|
||||
|
||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (1, 'admin', 'admin', 'C/admin', 'carmona', 'admin@gmail.com','admin');
|
||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (2, 'Paco', 'Naranjo', 'C/Esperanza', 'sevilla', 'Paco@gmail.com','paco');
|
||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (3, 'Lolo', 'Lopez', 'C/Macarena', 'dosHermanas', 'Lolo@gmail.com','lolo');
|
||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (3, 'Lolo', 'Lopez', 'C/Macarena', 'dos_hermanas', 'Lolo@gmail.com','lolo');
|
||||
INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (4, 'Pepe', 'Lopez', 'C/Macarena', 'carmona', 'Pepe@gmail.com','pepe');
|
||||
|
||||
INSERT INTO codes (id,code,activo) VALUES (1,'code1',FALSE);
|
||||
|
@ -37,7 +25,7 @@ INSERT INTO codes (id,code,activo) VALUES (3,'code3',TRUE);
|
|||
INSERT INTO codes (id,code,activo) VALUES (4,'code4',TRUE);
|
||||
|
||||
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis', 'sevilla','10:00','22:00','608726190', 'description 1', 'ESPAÑOLA','manoli', 'code1');
|
||||
INSERT INTO clients (id, name, email, address, init, municipio, finish, telephone, description, food, username, code) VALUES (2,'bar david','david@gmail.com','C/Sevilla', 'dosHermanas','09:30','22:00','608726190', 'description 2', 'americana','david', 'code2');
|
||||
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (2,'bar david','david@gmail.com','C/Sevilla', 'dosHermanas','09:30','22:00','608726190', 'description 2', 'americana','david', 'code2');
|
||||
|
||||
|
||||
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15);
|
||||
|
|
|
@ -274,10 +274,10 @@
|
|||
</style>
|
||||
<cheapy:layout pageName="singUp">
|
||||
<h2 style="text-align:center;padding:5px">
|
||||
<fmt:message key="new"/><fmt:message key="user"/>
|
||||
<fmt:message key="new"/><fmt:message key="client"/>
|
||||
</h2>
|
||||
<form:form modelAttribute="cliente" class="form-horizontal"
|
||||
id="add-foodOffer-form">
|
||||
id="add-client-form">
|
||||
<div class="form-group has-feedback">
|
||||
<cheapy:inputField label="Nombre" placeholder="Ponga aqui su nombre"
|
||||
name="name" />
|
||||
|
@ -291,9 +291,9 @@
|
|||
</c:forEach>
|
||||
</select>
|
||||
</div>
|
||||
<cheapy:inputField label="Hora de apertura" placeholder="Ponga aqui su hora de apertura"
|
||||
<cheapy:inputField label="Hora de apertura" placeholder="Ponga aqui su hora de apertura (formato HH:mm)"
|
||||
name="init" />
|
||||
<cheapy:inputField label="Hora de cierre" placeholder="Ponga aqui su hora de cierre"
|
||||
<cheapy:inputField label="Hora de cierre" placeholder="Ponga aqui su hora de cierre (formato HH:mm)"
|
||||
name="finish" />
|
||||
<cheapy:inputField label="Teléfono" placeholder="Ponga aqui el teléfono del local"
|
||||
name="telephone" />
|
||||
|
|
Loading…
Reference in a new issue