示例#1
0
        /// <summary>
        /// This method sends an automated e-mail
        /// </summary>
        /// <param name="user">Userprofile of user who mail will be sent to</param>
        /// <param name="token">Generated encrypted token</param>
        /// <param name="config">E-mailconfiguration from appsettings.json</param>
        public static void SendPasswordForgottenEmail(ProfileDatum user, string token, IConfiguration config)
        {
            SendEmailConfiguration mailConfiguration = SendEmailConfiguration.GetEmailConfiguration(config);

            System.Text.StringBuilder mailcontent = new System.Text.StringBuilder();
            mailcontent.Append("<img src='https://www.ruilwinkelvaals.nl/ruilwinkelvaals.nl/images/ruilwinkel/logo_ruilwinkel_vaalsWEB.jpg'style='width:20%; height:10%;'>");
            mailcontent.Append("<br />");
            mailcontent.Append("<br />");
            mailcontent.Append(String.Format("<p>Beste {0},</p>", user.Voornaam));
            mailcontent.Append(String.Format("<p>Wat vervelend dat u uw wachtwoord vergeten bent.</p>"));
            mailcontent.Append(String.Format("<p>Via de onderstaande link kunt u uw wachtwoord weer herstellen.</p>"));
            mailcontent.Append(String.Format("<p><em>Deze link is 60 minuten geldig. Bij een ongeldige link kunt u onze <a href='https://ruilwinkelvaalscore.azurewebsites.net/ForgotPassword/ForgotPassword'>wachtwoord herstelpagina</a> bezoeken om een nieuwe herstellink te ontvangen.</em></p>"));
            mailcontent.Append(String.Format("<p><a style='background-color:#8b0000; display:inline-block; color:white; padding:8px 16px; margin:8px 0px;border:none;cursor:pointer;border-radius:8px;font-size:12px;text-transform:uppercase;font-family:Helvetica;' href='https://ruilwinkelvaalscore.azurewebsites.net/ForgotPassword/ResetPassword?email={0}&token={1}'>Reset wachtwoord</a></p>", user.Email, token));
            mailcontent.Append(String.Format("<br />"));
            mailcontent.Append(String.Format("<p><em>Heeft u deze email ontvangen terwijl u uw wachtwoord niet wilt herstellen? Neem dan contact met ons op via het telefoonnummer +31 6 20 74 98 86</em></p>"));
            mailcontent.Append(String.Format("<p>Met vriendelijke groet,</p>"));
            mailcontent.Append(String.Format("<p>Ruilwinkel Vaals</p>"));

            EmailMessage emailMessage = new EmailMessage();

            emailMessage.FromAddresses.Add(new EmailAddress("Ruilwinkel Vaals", "*****@*****.**"));
            emailMessage.subject = "Wachtwoord herstellen";
            emailMessage.ToAddresses.Add(new EmailAddress(user.Voornaam + " " + user.Achternaam, user.Email));
            emailMessage.content = mailcontent.ToString();

            SendEmailService sendEmailService = new SendEmailService(mailConfiguration);

            sendEmailService.SendMessage(emailMessage);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Email,Voornaam,Achternaam,Balans,AccountType,Ledenpas,Straat,Huisnummer,Woonplaats,Postcode,DateCreated,Geboortedatum")] ProfileDatum profileDatum)
        {
            if (id != profileDatum.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(profileDatum);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfileDatumExists(profileDatum.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountType"] = new SelectList(_context.AccountTypeLts, "Id", "Id", profileDatum.AccountType);
            ViewData["Ledenpas"]    = new SelectList(_context.LedenpasLts, "Id", "Id", profileDatum.Ledenpas);
            return(View(profileDatum));
        }
        public async Task <IActionResult> Create([Bind("Id,Email,Voornaam,Achternaam,Balans,AccountType,Ledenpas,Straat,Huisnummer,Woonplaats,Postcode,DateCreated,Geboortedatum")] ProfileDatum profileDatum)
        {
            if (ModelState.IsValid)
            {
                _context.Add(profileDatum);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountType"] = new SelectList(_context.AccountTypeLts, "Id", "Id", profileDatum.AccountType);
            ViewData["Ledenpas"]    = new SelectList(_context.LedenpasLts, "Id", "Id", profileDatum.Ledenpas);
            return(View(profileDatum));
        }
        public IActionResult Register([Bind("Email, Password, ValidationPassword, Voornaam, Achternaam, Straat, Huisnummer, Woonplaats, Postcode, Geboortedatum, Zakelijk")] Register model)
        {
            if (ModelState.IsValid)
            {
                //Try to get an Profile where email is similar to the userinput
                var profileExists = db.ProfileData.Where(user => user.Email == model.Email).FirstOrDefault();
                if (profileExists == null) //If there is not an registered user with the given Email
                {
                    var ProfileAge = GetAge(Convert.ToDateTime(model.Geboortedatum).Date);
                    if (ProfileAge >= 16)                                //Customer is old enough to register
                    {
                        if (model.Password == model.ValidationPassword)  //Given passwords are equal
                        {
                            ProfileDatum newProfile = new ProfileDatum() //Create new ProfileObject
                            {
                                Email         = model.Email,
                                Voornaam      = model.Voornaam,
                                Achternaam    = model.Achternaam,
                                Straat        = model.Straat,
                                Huisnummer    = model.Huisnummer,
                                Woonplaats    = model.Woonplaats,
                                Postcode      = model.Postcode,
                                Geboortedatum = Convert.ToDateTime(model.Geboortedatum).Date,
                                DateCreated   = DateTime.Today.Date,
                            };

                            if (model.Zakelijk == true)
                            {
                                newProfile.AccountType = 2;
                            }
                            else
                            {
                                newProfile.AccountType = 1;
                            }
                            //Save profile to DB
                            db.ProfileData.Add(newProfile);
                            db.SaveChanges();

                            //Get ProfileId for Foreign relation
                            var ProfileId = db.ProfileData.Where(profile => profile.Email == model.Email).FirstOrDefault();
                            //Create new Account with relation to ProfileData
                            HashSalt     hashSalt   = HashSalt.GenerateHashSalt(16, model.Password);
                            AccountDatum newAccount = new AccountDatum()
                            {
                                ProfileId = ProfileId.Id,
                                Hash      = hashSalt.hash,
                                Salt      = hashSalt.salt,
                            };
                            db.AccountData.Add(newAccount);
                            db.SaveChanges();
                            return(RedirectToAction("Index", "Home"));
                        }
                        else //Passwords are not equal
                        {
                            ModelState.AddModelError("RegisterError", "De gegeven wachtwoorden komen niet overeen met elkaar.");
                            return(View());
                        }
                    }
                    else //Customer is not old enough to register
                    {
                        ModelState.AddModelError("RegisterError", "U dient minimaal 16jaar te zijn om te registreren.");
                        return(View());
                    }
                }
                else //If there is an user with the given Email
                {
                    ModelState.AddModelError("RegisterError", "Er bestaat al een account met dit Email adres.");
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }