public IActionResult Register(RegisterUser registration)
        {
            bool.TryParse(_dataAccessor.GetSettingValue("AllowRegistration"), out bool allowRegister);
            if (!allowRegister)
            {
                return(View("SignIn", new AuthenticatedUser()));
            }

            if (!string.Equals(registration.ChosenPassword, registration.VerifyPassword, StringComparison.Ordinal))
            {
                return(View("PasswordsNotMatch"));
            }
            if (_dataAccessor.AccountAlreadyRegistered(registration.NameToRegister))
            {
                return(View("AlreadyRegistered", registration));
            }

            _dataAccessor.RegisterAccount(registration.NameToRegister, registration.ChosenPassword);

            //get a new session for this user
            DataAccess.Models.ISession session = _dataAccessor.GetSession(registration.NameToRegister, registration.ChosenPassword);
            if (session == null)
            {
                throw new InvalidCredentialsException();
            }

            //store the cookie
            Response.Cookies.Append("sessionId", session.SessionId);

            return(RedirectToAction("GetMatch"));
        }
Exemple #2
0
 public IActionResult Register(RegisterUser registration)
 {
     if (_dataAccessor.AccountAlreadyRegistered(registration.NameToRegister))
     {
         return(View("AlreadyRegistered", registration));
     }
     _dataAccessor.RegisterAccount(registration.NameToRegister, registration.ChosenPassword);
     return(RedirectToAction("GetMatch", new SecretMatch {
         Name = registration.NameToRegister, AllowReroll = true
     }));
 }