Exemplo n.º 1
0
        public bool CreateUserAccount(string username, string emailAddress, string password, string confirmPassword, int empireID, Coordinates focus, out UserAccount user, out string errors)
        {
            string validatedErrors;
            if(this.Validate(username, emailAddress, password, confirmPassword, out validatedErrors))
            {
                var created = DateTime.UtcNow;
                created = created.AddMilliseconds(-created.Millisecond); // strip off milliseconds so SQL doesn't do it for us
                var salt = _cryptographyManager.CreateSalt();
                var hash = _cryptographyManager.CreateHash(created, password, salt);

                var securityUser = new SecurityUserAccount
                {
                    CreateTS = created,
                    EmailAddress = emailAddress,
                    PasswordSalt = salt,
                    PasswordHash = hash,
                    Username = username
                };

                _users.CreateUserAccount(securityUser, empireID, focus);
                user = _users.GetUserByUsername(username);
                errors = null;
                return true;
            }
            else
            {
                errors = validatedErrors;
                user = null;
                return false;
            }
        }
Exemplo n.º 2
0
        public Ship CreateShip(SolarSystem located, UserAccount owner, string name)
        {
            int id;
            var query = string.Concat("INSERT INTO Ships (", string.Join(", ", RequiredFields), ") VALUES (", string.Join(", ", RequiredFields.Select(f => string.Concat("@", f))), ") SELECT Scope_Identity()");
            using (var cmd = this.SessionManager.GetCurrentUnitOfWork().CreateCommand(query))
            {
                cmd.AddParameter("UserAccountID", DbType.Int32, owner.UserAccountID);
                cmd.AddParameter("Name", DbType.String, name);
                cmd.AddParameter("SolarSystemID", DbType.Int64, located.SolarSystemID);
                cmd.AddParameter("IsSelected", DbType.Boolean, 0);
                cmd.AddParameter("JobID", DbType.Int64, DBNull.Value);
                cmd.AddParameter("EmpireID", DbType.Int32, owner.EmpireID);

                id = (int)(decimal)cmd.ExecuteScalar();
            }

            return this.GetShip(id);
        }
Exemplo n.º 3
0
 public bool RegisterUser(string username, string emailAddress, string password, string confirmPassword, out UserAccount user, out string error)
 {
     UserAccount createdUser;
     string createUserError;
     var empire = _empireManager.CreateEmpire(string.Concat(username, "'s Empire"));
     var randomSolarSystem = _solarSystemRepository.GetRandomUnoccupiedSolarSystem();
     if (_securityManager.CreateUserAccount(username, emailAddress, password, confirmPassword, empire.EmpireID, randomSolarSystem.Coordinates, out createdUser, out createUserError))
     {
         var ship = _shipRepository.CreateShip(randomSolarSystem, createdUser, "New Ship");
         user = createdUser;
         error = null;
         return true;
     }
     else
     {
         user = null;
         error = createUserError;
         return false;
     }
 }
 public static Mock<ISecurityManager> SetupGetCurrentUserAccountToReturnUserAccount(this Mock<ISecurityManager> securityManager, UserAccount userAccountResult = null)
 {
     var userAccount = userAccountResult ?? Create.DomainClasses.UserAccount();
     securityManager.Setup(x => x.GetCurrentUserAccount()).Returns(userAccount);
     return securityManager;
 }
Exemplo n.º 5
0
 private static NavigationManager CreateNavigationManagerToReturnSolarSystem(SolarSystem solarSystem, UserAccount userAccount = null)
 {
     var securityManager = new Mock<ISecurityManager>();
     securityManager.SetupGetCurrentUserAccountToReturnUserAccount(userAccount);
     var solarSystems = new Mock<ISolarSystems>();
     solarSystems.SetupFindSystemsInLocalArea(solarSystem);
     var manager = Create.BusinessLogicClass.NavigationManager(securityManager.Object, solarSystems.Object);
     return manager;
 }
Exemplo n.º 6
0
        public UserAccount Update(UserAccount userAccount)
        {
            if (userAccount == null) throw new ArgumentNullException("userAccount");

            using (var cmd = this.SessionManager.GetCurrentUnitOfWork().CreateCommand("UPDATE UserAccounts SET X = @X, Y = @Y, Z = @Z WHERE UserAccountID = @ID"))
            {
                cmd.AddParameter("ID", DbType.Int32, userAccount.UserAccountID);
                cmd.AddParameter("X", DbType.Int32, userAccount.FocusCoordinates.X);
                cmd.AddParameter("Y", DbType.Int32, userAccount.FocusCoordinates.Y);
                cmd.AddParameter("Z", DbType.Int32, userAccount.FocusCoordinates.Z);

                cmd.ExecuteNonQuery();

                return userAccount;
            }
        }