I have the next code that is now working fine but Im trying to validate the oldPassword, but ever appear the error message that it dont match.
Aspersoft\DirectorioBundle\Entity\User:
properties:
password:
- NotBlank: { groups: [change_password] }
- Length: { min: 3, max: 20, minMessage: "La cotraseña debe de contener minimo {{ limit }} caracteres de longitud.", maxMessage: "La cotraseña debe de contener maximo {{ limit }} caracteres de longitud.", groups: [change_password]}
oldPassword:
- Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
groups: [change_password]
and in my entity class:
/**
* User
*
* #ORM\Table(name="user", indexes={#ORM\Index(name="user_index_1", columns={"id_municipality"})})
* #ORM\Entity(repositoryClass="Aspersoft\DirectorioBundle\Entity\UserRepository")
*/
class User implements AdvancedUserInterface, \Serializable {
public $oldPassword;
// more properties, getters and setters...
somebody knows what can be the problem? and how I would create the property OldPassword or maybe if it would be serialized in entity, In the symfony page there is poor information about Constraint UserPassword.
I found the solution.
I needed create the form from a Type to work properly with validation class.
Related
My config :
Spring 4
Jackson 2.9
Angular 8
I have a pojo with two constructors :
public Notification(int code, String message, List<T> objets) {
this.code = code;
this.message = message;
this.objets = objets;
}
public Notification(int code, String message, T objet) {
this.code = code;
this.message = message;
this.objet = objet;
}
The purpose of this pojo is adding an internal code and a string message to the result of a request, the request can either result in a object or in a list of objects (or no object at all but i did not wanted to write every constructor above).
My problem is that when my query result is a list, and i think i am using the constructor with the list of objects . However the query response in my browser terminal is a null object. So I suppose the second constructor is used.
why is it not using my first constructor?
Here is my repository :
public Notification<Prelevement> findActiveTransferts(int id){
LocalDateTime currentTime = LocalDateTime.now();
Date date = java.sql.Date.valueOf(currentTime.toLocalDate());
String sql = "from Prelevement pre where :date between pre.dateDebut and pre.dateFin and pre.compte =:idCompte";
try {
Compte acc = (Compte)this.getCurrentSession().createQuery("from Compte acc where acc.id =:id").setParameter("id", id).getSingleResult();
List<Prelevement> list = (List<Prelevement>) this.getCurrentSession().createQuery(sql).setParameter("date", date).setParameter("idCompte", acc).getResultList();
return new Notification<Prelevement>(Notification.OPERATION_SUCCESSFUL, "Nous avons trouvé "+list.size()+" éléments correspondants à votre recherche", list);
}catch(NoResultException nre) {
return new Notification<Prelevement>(Notification.DB_NO_DATA_FOUND, "Nous avons trouvé aucun élément correspondant à votre recherche");
}
}
and my RestController :
#PostMapping("/pre/get")
public ResponseEntity<Notification<Prelevement>> get(#RequestBody DTOAcc dto){
Notification<Prelevement> result = ((PrelevementRepository)repository).findActiveTransferts(dto.getId());
System.out.println(result);
return new ResponseEntity<Notification<Prelevement>>(result, HttpStatus.OK);
}
I expect the json string in my browser terminal to be a list of objects and not an object when a list is expected.
Result json string is :
{"code":0,"message":"Nous avons trouvé 1 éléments correspondants à votre recherche","objet":null}
and should be :
{"code":0,"message":"Nous avons trouvé 1 éléments correspondants à votre recherche","objets":[
{"id":"0", ... other attributes}
]}
the toString method of the object sent by Spring to the browser is as follow
Notification [code=0, message=Nous avons trouvé 1 éléments correspondants à votre recherche, objets=[pro.logikal.comptes.entity.Prelevement#16b51ef6]] so we can see that my request has found a list of object (a list of one object to be accurate).
Can you please show me the way?
Found out my mistake, I did not generate any getter nor setter for this list. The constructor resulted invisible so it got to the next constructor.
I'm currently tying to make a formflow in C# using bot framework, here's my code so far:
[Serializable]
[Template(TemplateUsage.EnumSelectOne, "Selecciona un estadio: {||}", ChoiceStyle = ChoiceStyleOptions.PerLine)]
public class StadiumInfoForm
{
[Prompt("Selecciona un estadio: ", ChoiceFormat = "{1}")]
public StadiumOptions? estadio;
public static IForm<StadiumInfoForm> BuildForm()
{
var form = new FormBuilder<StadiumInfoForm>()
.Message($"¿De qué estadio te gustaría saber?")
.AddRemainingFields();
PromptAttribute title = new PromptAttribute();
List<string> quitCommands = new List<string>();
quitCommands.Add("Salir");
quitCommands.Add("Cancelar");
quitCommands.Add("No");
quitCommands.Add("Quiero salir");
quitCommands.Add("Nada");
form.Configuration.Commands[FormCommand.Quit].Terms = quitCommands.ToArray();
return form.Build();
}
}
As you can see the form will be in spanish, the problem is that the prompt displayed at the top of the form always reads "Please select an estadio", I tried changing it following this documentation but to no avail, how can I change this attribute of the form to display something like "Seleccione un estadio por favor"
I'll upload more code if needed.
Maybe the template of the class "confusing" the FormFlow?
[Serializable]
[Template(TemplateUsage.NavigationFormat, "{&}")]
public class StadiumInfoForm
{
[Prompt("Seleccione un estadio por favor{||}", ChoiceFormat = "{1}")]
public StadiumOptions? estadio;
{&} is a pattern language
With only these changes it works for me
P.S. If you want to change the language of the entire FormFlow you can add activity.Locale = "es-ES"; in the Post method of your "MessagesController"
i would like to do a custom Range Validator but i'm not sure how to proceed in this.
I need the Range validator to be active only if a boolean stay false, if the bool is true, the validation should not apply. Something like the RequiredIfFalse of foolproof validation.
[RequiredIfFalse("UnEquip", ErrorMessage = "Le champ 'Nombre de salariés' doit être renseigné")]
[Range(1, 1000000, ErrorMessage = "Le nombre de salariés doit être compris entre 1 et 1000000")]
public int Salaries { get; set; }
something like this, but combining those 2 type of validation.
Thanks in advance
You need to perform this validation at model level, because it implies several properties at once. Check this link, for a similar issue : Make the email field required based on the dropdown list value selection
In your case, Validate will test your boolean and Salaries value, if false and Salaries > 1000000 or Salaries < 1, you'll return a new ValidationResult containing your error message.
I don't know why matches function doesn't run. I want user introduce a password and confirm it introducing it again. The problem is that when I use matches function in order to compare both passwords Codeigniter indicates that passwords are not equal after introducing both equals.
Here is the code:
public function validacion_registro()
{
$this->input->post('correo');
$this->input->post('usuario');
$this->input->post('contrasenya');
$this->form_validation->set_rules('correo','Dirección de correo','trim|required|valid_email|xss_clean');
$this->form_validation->set_rules('usuario','Nombre de usuario','trim|required|min_length[5]|xss_clean');
$this->form_validation->set_rules('contrasenya','Contraseña','trim|required|md5|xss_clean|matches[repcontrasenya]');
$this->form_validation->set_rules('repcontrasenya','Confirmación de contraseña','trim|required|md5|xss_clean');
$this->form_validation->set_rules('privacidad','Política de privacidad','trim|required|md5|xss_clean');
if ($this->form_validation->run())
{
redirect('anuncios/test');
echo ("validación válida");
}
else {
$this->load->view('anuncios/login');
}
}
The error is in the comparison between contrasenya and repcontrasenya. When both are equal Codigniter indicates that are different.
Whats wrong?
Thanks.
The command: $this->form_validation->run() returns true if you don't have errors.
Modify the code with:
if ($this->form_validation->run() == FALSE)
{
redirect('anuncios/test');
echo ("validación válida");
}
else
{
$this->load->view('anuncios/login');
}
I have an object Customer with a 1-n relationship to Addresses.
I want to be able to take the first address. So i create a method:
public Address firstAddress
{
get
{
var f=from d in this.Addresses
select d;
return f;
}
}
I get the following error :
Error 5 Impossible to find an implementation ofsource 'System.Data.Objects.DataClasses.EntityCollection'. 'Select' introuvable. Une référence à 'System.Core.dll' ou une directive using pour 'System.Linq' est-elle manquante ?
I do not undertand why i can't query the collection of addresses...
Thanks
John
Well, the error message tells you where to start looking, presuming you can read French. :) Make sure your app has a reference to the System.Core assembly and your code file has using System.Linq; at the top.
Also, I think the query is wrong. I'm presuming that this.Addresses is an enumeration of the type Address. In this case you'd need:
public Address firstAddress
{
get
{
var f=(from d in this.Addresses
select d).FirstOrDefault();
return f;
}
}