Example #1
0
 public async Task SendMessageToGroup(string message)
 {
     string       group = GetCurrentGroup();
     MonopolyUser user  = GetCurrentUser();
     string       name  = user.FirstName + " " + user.LastName;
     await Clients.Group(group).SendAsync("ReceiveGroupMessage", name ?? "anonymous", message);
 }
Example #2
0
 public async Task SendJoinedRoomMessage()
 {
     string       group = GetCurrentGroup();
     MonopolyUser user  = GetCurrentUser();
     string       name  = user.FirstName + " " + user.LastName;
     await Clients.Group(group).SendAsync("JoinedRoomMessage", name ?? "anonymous", "has joined the room.");
 }
Example #3
0
        public string GetCurrentPlayerName()
        {
            MonopolyUser user   = _userManager.FindByEmailAsync(Context.User.Identity.Name).Result;
            string       player = user.FirstName + " " + user.LastName;

            return(player);
        }
Example #4
0
 public async Task SendMessage(string message)
 {
     MonopolyUser user     = GetCurrentUser();
     string       name     = user.FirstName + " " + user.LastName;
     string       dateTime = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + " - " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
     await Clients.All.SendAsync("ReceiveMessage", name ?? "anonymous", message, dateTime);
 }
Example #5
0
 public async Task RollDices(string dice1, string dice2)
 {
     MonopolyUser currentPlayer = GetCurrentUser();
     string       player        = currentPlayer.FirstName + " " + currentPlayer.LastName;
     int          roomId        = Int32.Parse(GetCurrentGroup());
     string       pawn          = roomDatabaseOperations.GetPlayersForGame(roomId).Where(x => x.Name == player).FirstOrDefault().Pawn;
     await Clients.Group(GetCurrentGroup()).SendAsync("DisplayRollDices", dice1, dice2, pawn);
 }
Example #6
0
        public string GetCurrentGroup()
        {
            MonopolyUser user            = _userManager.FindByEmailAsync(Context.User.Identity.Name).Result;
            string       player          = user.FirstName + " " + user.LastName;
            var          gameRoomContext = new MonopolyDbContext();
            string       group           = gameRoomContext.Rooms.Where(x => x.Player1 == player || x.Player2 == player || x.Player3 == player || x.Player4 == player).First().RoomId.ToString();

            return(group);
        }
Example #7
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new MonopolyUser {
                    UserName = Input.Email, Email = Input.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("User created an account using {Name} provider.", info.LoginProvider);

                        var userId = await _userManager.GetUserIdAsync(user);

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = userId, code = code },
                            protocol: Request.Scheme);

                        await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                          $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
Example #8
0
        public async Task PlayerLeavesGame()
        {
            MonopolyUser currentPlayer = GetCurrentUser();
            string       player        = currentPlayer.FirstName + " " + currentPlayer.LastName;
            int          roomId        = Int32.Parse(GetCurrentGroup());
            string       pawn          = roomDatabaseOperations.GetPlayersForGame(roomId).Where(x => x.Name == player).FirstOrDefault().Pawn;
            await Clients.Group(GetCurrentGroup()).SendAsync("LeavesGame", pawn);

            roomDatabaseOperations.PlayerLeavesGame(GetCurrentPlayerName());
        }
Example #9
0
        public async Task RemoveFromGroup()
        {
            string       group       = GetCurrentGroup();
            MonopolyUser currentUser = GetCurrentUser();
            string       player      = currentUser.FirstName + " " + currentUser.LastName;

            _gameRoomOperations.RemovePlayerFromRoom(player);
            await SendLeftRoomMessage(group, player);

            await Groups.RemoveFromGroupAsync(Context.ConnectionId, group);
        }
Example #10
0
        private async Task LoadAsync(MonopolyUser user)
        {
            var email = await _userManager.GetEmailAsync(user);

            Email = email;

            Input = new InputModel
            {
                NewEmail = email,
            };

            IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
        }
Example #11
0
        private async Task LoadAsync(MonopolyUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
Example #12
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new MonopolyUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #13
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(MonopolyUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }