Пример #1
0
 public DataCache(ApplicationDbContext context, ApplicationUser user, Corporation corporation)
 {
     db = context;
     User = user;
     Corporation = corporation;
     RefreshCache();
 }
Пример #2
0
 public Corporation(ApplicationUser user, string name)
 {
     User = user;
     Name = name;
     RD = 0;
     Reputation = 0;
     Readiness = 0;
     Cash = 10000;
     PublicInterest = 0;
     TurnsRemaining = 10;
     TurnCount = 1;
 }
Пример #3
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            _applicationUser = db.Users.FirstOrDefault(u => u.Id == User.GetUserId());

            if (_applicationUser != null)
            {
                _corporation = db.Corporations.FirstOrDefault(c => c.User.Id == _applicationUser.Id);
                //if (_corporation == null)
                //    context.Result = new RedirectToRouteResult(
                //        new RouteValueDictionary
                //        {
                //            {"Controller", "Corporations"},
                //            {"Action", "Create"}
                //        });
            }
        }
Пример #4
0
        public static void InitializeIfFreshDB(IServiceProvider serviceProvider)
        {
            var context = serviceProvider.GetService<ApplicationDbContext>();

            //If this table is empty, we know the DB is fresh
            if (context.Dev.FirstOrDefault() != null) return;

            context.Dev.Add(new Dev
            {
                ProductName = "Text RPG Adventure",
                Version = "0.0.1",
                Author = "Taylor"
            });

            var user = new ApplicationUser()
            {
                Id = "a312887d-6242-4537-b7b2-3c6d6473c04d",
                AccessFailedCount = 0,
                ConcurrencyStamp = "645355e8-cade-4815-9219-36a792c80461",
                Email = "*****@*****.**",
                EmailConfirmed = false,
                LockoutEnabled = true,
                LockoutEnd = null,
                NormalizedEmail = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash = "AQAAAAEAACcQAAAAEEv6pe6NxpSgbuOQ9k3zrGYqUo6fHzxM6knslraP71+QxfeJRJjD4bvW/FVRY5bQ7w==",
                PhoneNumber = null,
                SecurityStamp = "0e88fa93-e579-4354-9e20-7d0f0cd36b30",
                TwoFactorEnabled = false,
                UserName = "******"
            };

            var corporation = new Corporation()
            {
                Name = "SpaceCo Industries, Inc",
                Cash = 10000,
                PublicInterest = 20,
                RD = 20,
                Readiness = 20,
                Reputation = 20,
                TurnsRemaining = 10,
                BusinessMultiplier = 1.00,
                User = user
            };

            var person1 = new Person()
            {
                Name = "Hans Grosserman",
                Description = "One wily German dude.",
                Position = "Engineer",
                TurnSalary = 100,
                Celebrity = false,
                Business = 5,
                Experience = 5,
                Fitness = 5,
                Intelligence = 5,
                SigningBonus = 1000,
                SeverancePayout = 1000
            };

            var person2 = new Person()
            {
                Name = "Jim Johannsen",
                Description = "A smart businessman.",
                Position = "Financier",
                TurnSalary = 80,
                Celebrity = true,
                Business = 5,
                Experience = 5,
                Fitness = 2,
                Intelligence = 2,
                SigningBonus = 800,
                SeverancePayout = 800

            };

            var person3 = new Person()
            {
                Name = "Li Chen",
                Description = "A guy from China who is really good at putting shit together.",
                Position = "Technician",
                TurnSalary = 80,
                Celebrity = false,
                Business = 0,
                Experience = 7,
                Fitness = 4,
                Intelligence = 2,
                SigningBonus = 1000,
                SeverancePayout = 1000
            };

            var persons = new List<Person> {person1, person2, person3};

            var cp1 = new CorporationPerson()
            {
                Corporation = corporation,
                Hired = false,
                Person = person1
            };

            var cp2 = new CorporationPerson()
            {
                Corporation = corporation,
                Hired = false,
                Person = person2
            };

            var cp3 = new CorporationPerson()
            {
                Corporation = corporation,
                Hired = false,
                Person = person3
            };

            var contract = new Contract()
            {
                Name = "The Road to Damnation",
                Script = File.ReadAllText(@"scripts\contracts\testcontract.txt")
            };

            var corpPersons = new List<CorporationPerson> { cp1, cp2, cp3};

            context.Users.Add(user);
            context.Corporations.Add(corporation);
            persons.ForEach(p => context.Persons.Add(p));
            corpPersons.ForEach(c => context.CorporationPersons.Add(c));
            context.Contracts.Add(contract);

            ResearchTree.CreateTestTreeInDB(context, corporation);

            context.SaveChanges();
        }
Пример #5
0
        public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
        {
            if (User.IsSignedIn())
            {
                return RedirectToAction(nameof(ManageController.Index), "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await _userManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);
                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent: false);
                        _logger.LogInformation(6, "User created an account using {Name} provider.", info.LoginProvider);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewData["ReturnUrl"] = returnUrl;
            return View(model);
        }
Пример #6
0
        public async Task<IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await _userManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    await _signInManager.SignInAsync(user, isPersistent: false);
                    _logger.LogInformation(3, "User created a new account with password.");
                    return RedirectToAction("Create", "Corporations");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }