Beispiel #1
0
 public IActionResult ResetPassword([Bind("password, passwordValidation")] ResetPassword model)
 {
     if (ModelState.IsValid)
     {
         string email = TempData["Email"].ToString();
         if (model.password != model.passwordValidation)
         {
             ModelState.AddModelError("PasswordResetError", "De ingevulde wachtwoorden zijn niet gelijk aan elkaar");
             return(View());
         }
         else
         {
             var userData = db.ProfileData.Where(e => e.Email == email).FirstOrDefault();
             if (userData != null)
             {
                 HashSalt newPassword     = HashSalt.GenerateHashSalt(16, model.password);
                 var      userCredentials = db.AccountData.Where(user => user.ProfileId == userData.Id).FirstOrDefault();
                 userCredentials.Hash = newPassword.hash;
                 userCredentials.Salt = newPassword.salt;
                 db.SaveChanges();
                 return(RedirectToAction("ResetPasswordConfirmation"));
             }
             else
             {
                 return(RedirectToAction("ForgotPassword"));
             }
         }
     }
     else
     {
         return(View());
     }
 }
        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());
            }
        }