Esempio n. 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            model.userSession = false;

            //creates a new account if the form has passed validation
            if (ModelState.IsValid)
            {
                Account account = new Account
                {
                    firstName   = model.firstName,
                    lastName    = model.lastName,
                    email       = model.email,
                    password    = model.password.Encrypt(model.email), //encrypts the user's password
                    birthDate   = model.birthDate,
                    dateCreated = DateTime.Now,
                };

                //returns error message if the email is already in use
                if (accountService.EmailInUse(account.email))
                {
                    return(Content("That email is already being used. Please try again with another email"));
                }

                //otherwise creates an account and sends verification email
                else
                {
                    model.userSession = false;
                    accountDAO.CreateAccount(account);
                    emails.SendEmailAddressVerificationEmail(account.email, account.email);
                    TempData["successMessage"] = "You have created an account ! A confirmation has been sent to your email";
                    return(RedirectToAction("EmailConfirmation", "Account"));
                }
            }
            return(View(model));
        }
        public ActionResult <Account> CreateAccount(Account account)
        {
            bool accountCreated = accountDAO.CreateAccount(account);

            return(Ok(accountCreated));
        }