Exemplo n.º 1
0
        /// <summary>
        /// Converts dbUser to User and adds it to Users list
        /// </summary>
        /// <param name="dbUser"></param>
        public void addUserFromDB(DBUser dbUser)
        {
            User user = new User(dbUser, this);

            Ship ship = new ShipBuilder().BuildShip(user,
                new PresetShipRepository().GetShip(dbUser.ShipPresetId),
                dbUser.CellTypes);

            //Form array of Cells to be used in JavaScript
            ArrayInstance[] array = new ArrayInstance[ship.cells.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = user.engine.Array.New(ship.cells[i]);

                for (int j = 0; j < ship.cells[i].Length; j++)
                {
                    if (ship.cells[i][j] is CellEngine)
                    {
                        ((CellEngine)ship.cells[i][j]).repository = this;
                    }
                }
            }
            user.engine.SetGlobalValue("cells", user.engine.Array.New(array));
            user.engine.SetGlobalValue("radar", new Radar(user));

            Action<string> logAction = delegate(string s) { user.Log.Add(s); };
            user.engine.SetGlobalFunction("log", logAction);

            user.Login = dbUser.Username;
            user.PasswordHash = dbUser.PasswordHash;
            user.Code = dbUser.Code;
            user.Credits = dbUser.Credits;
            user.ship = ship;
            _users.Add(user);
        }
Exemplo n.º 2
0
        public object Register(RegisterModel addUserModel)
        {
            User userWithSameLogin = repository.Users
                .Where(u => u.Login == addUserModel.Login)
                .FirstOrDefault();
            if (userWithSameLogin != null)
                return new { error = "The username already taken" };

            if (addUserModel.Password != addUserModel.PasswordRepeat)
                return new { error = "Passwords does not match" };

            if (addUserModel.Password.Length < 3)
                return new { error = "Password too short" };

            DBUser user = new DBUser();
            user.Username = addUserModel.Login;
            user.PasswordHash = helper.CreateHash(addUserModel.Password);
            user.ShipPresetId = 1;
            user.Code = "";

            user.CellTypes = new PresetShipRepository()
                .GetShip(user.ShipPresetId)
                .DefaultLayout;

            context.Users.Add(user);
            context.SaveChanges();

            repository.UpdateFromDB(context);
            return new { success = true };
        }
Exemplo n.º 3
0
        private void butNewReg_Click(object sender, EventArgs e)
        {
            DBUser u = new DBUser();

            u.Login    = textBoxNewLogin.Text;
            u.Password = textBoxNewPass.Text;
            u.Name     = textBoxNewName.Text;
            db.DBUser.Add(u);
            db.SaveChanges();
            Close();
        }
Exemplo n.º 4
0
        private void butSignIn_Click(object sender, EventArgs e)
        {
            DBUser user = db.DBUser.FirstOrDefault(u => u.Login == login.Text && u.Password == pass.Text);

            if (user != null)
            {
                FocusForm2(user.Name, user.Id);
            }
            else
            {
                MessageBox.Show("Нет такого!");
            }
        }