Exemple #1
0
        public async Task <IActionResult> Inscription(DtoTGA001InpDA01UtilisateurPourInscription dto)
        {
            dto.NomUtilisateur = dto.NomUtilisateur.ToLower();
            if (await _repo.UtilisateurExiste(dto.NomUtilisateur))
            {
                return(BadRequest($"L'utilisateur « { tinfo.ToTitleCase(dto.NomUtilisateur) } » existe déjà"));
            }
            if (await _repo.EmailExiste(dto.Email))
            {
                return(BadRequest($"L'e-mail « { dto.Email } » existe déjà"));
            }
            if (!Array.Exists(this._npa4Array, x => x == dto.CodePostal))
            {
                return(BadRequest($"Le code postal « { dto.CodePostal } » n'est pas supporté par cette application"));
            }
            var userToCreate = new DA01Utilisateur
            {
                NomUtilisateur = dto.NomUtilisateur,
                EMail          = dto.Email
            };
            var clientToCreate = new DA10Client
            {
                NomDeFamille = dto.NomDeFamille,
                Prenom       = dto.Prenom,
                Adresse      = dto.Adresse,
                CodePostal   = dto.CodePostal
            };
            var userCreate = await _repo.Inscription(userToCreate, clientToCreate, dto.MotDePasse);

            using (var message = new MailMessage())
            {
                message.To.Add(new MailAddress(userCreate.EMail, userCreate.Client.Prenom + " " + userCreate.Client.NomDeFamille));
                message.From    = new MailAddress("*****@*****.**", "Taxi Gestion");
                message.Subject = "TaxiGestion - Veuillez confirmer votre e-mail pour activer votre compte";
                string body = System.IO.File.ReadAllText("EMail/confirmation-email-client.html");
                body = body.Replace("#Prenom#", userCreate.Client.Prenom);
                body = body.Replace("#Nom#", userCreate.Client.NomDeFamille);
                body = body.Replace("#Url#", "https://www.taxi-gestion.ch/e-mail/confirmation-inscription/" + userCreate.Id + "/" + userCreate.MotDePasseEMailConfirmation);
                message.IsBodyHtml = true;
                message.Body       = body;
                using var client   = new SmtpClient(_config.GetSection("Email:Smtp").Value)
                      {
                          Port = Int32.Parse(_config.GetSection("Email:Port").Value)
                      };
                client.Send(message);
            }
            return(Ok());
        }
Exemple #2
0
        public async Task Inscription()
        {
            var dto = new DtoTGA001InpDA01UtilisateurPourInscription()
            {
                NomUtilisateur = "stephane",
                MotDePasse     = "password",
                Email          = "*****@*****.**",
                Prenom         = "Stéphane",
                NomDeFamille   = "Bressani",
                Adresse        = "16A ch. des Buclines",
                CodePostal     = "1224",
                Lieu           = "Chêne-Bougeries"
            };

            using var context = new DataContext(this.DA001TestDbContext().Options);
            // Connection au repository
            var repo = new AuthentificationRepository(context);

            context.Database.EnsureCreated();

            var userToCreate = new DA01Utilisateur
            {
                NomUtilisateur = dto.NomUtilisateur,
                EMail          = dto.Email
            };
            var clientToCreate = new DA10Client
            {
                Prenom       = dto.Prenom,
                NomDeFamille = dto.NomDeFamille,
                Adresse      = dto.Adresse,
                CodePostal   = dto.CodePostal,
                Lieu         = dto.Lieu
            };
            await repo.Inscription(userToCreate, clientToCreate, dto.MotDePasse);

            Assert.True(await repo.UtilisateurExiste(dto.NomUtilisateur));
        }