예제 #1
0
        public async Task <IActionResult> Editor(int id, string sortOrder, string currentFilter, int?pageNumber)
        {
            var editor = await _context.Editors
                         .FirstOrDefaultAsync(m => m.Id == id);

            if (editor == null)
            {
                return(NotFound());
            }

            ViewBag.EditorName = editor.Name;
            ViewBag.EditorDesc = editor.Description;

            IQueryable <Game> games = _gameService.GetGamesByEditor(id);

            games = _gameService.GetGamesValidate(games);

            GamesIndexData gamesAllData = await SortGames(currentFilter, sortOrder, currentFilter, pageNumber, games);

            bool isAuthenticated = User.Identity.IsAuthenticated;

            if (isAuthenticated)
            {
                LudothequeUser user = await UserServices.GetUserAsync(userManager, User.Identity.Name);

                gamesAllData = _gameAllDataService.GamesPoss(gamesAllData, user.Id);
            }
            else
            {
                gamesAllData = _gameAllDataService.NoGamesPoss(gamesAllData);
            }
            return(View(gamesAllData));
        }
예제 #2
0
        private async Task LoadAsync(LudothequeUser user)
        {
            var email = await _userManager.GetEmailAsync(user);

            Email = email;

            Input = new InputModel
            {
                NewEmail = email,
            };

            IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
        }
예제 #3
0
        private async Task LoadAsync(LudothequeUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new LudothequeUser {
                    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());
        }
예제 #5
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(LudothequeUser 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);
        }
예제 #6
0
        public async Task <IActionResult> DeleteGame(int id)
        {
            LudothequeUser user = await UserServices.GetUserAsync(userManager, User.Identity.Name);


            var gameUser = _context.GamesUser.Single(s => s.GameId == id && s.LudothequeUserId.Equals(user.Id));

            if (gameUser == null)
            {
                return(NotFound());
            }
            else
            {
                var result = _context.GamesUser.Remove(gameUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #7
0
        public async Task <IActionResult> AddGameUser(int id)
        {
            LudothequeUser user = await UserServices.GetUserAsync(userManager, User.Identity.Name);


            var game = await _context.Games.FindAsync(id);

            if (game == null)
            {
                return(NotFound());
            }
            else
            {
                bool      notFIndGame = _context.GamesUser.SingleOrDefault(s => s.GameId == id && s.LudothequeUserId.Equals(user.Id)) == null;
                GamesUser gamesUser   = new GamesUser
                {
                    Game             = game,
                    GameId           = game.Id,
                    User             = user,
                    LudothequeUserId = user.Id
                };

                if (notFIndGame)
                {
                    var result = await _context.AddAsync(gamesUser);

                    TempData["message"] = "Le jeu est ajouté dans votre ludotheque";
                    TempData["success"] = "true";

                    //var result = _context.GamesUser.AddAsync(gamesUser);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index), "Games"));
                }
                else
                {
                    TempData["message"] = "Le jeu existe déja dans votre ludotheque";
                    TempData["success"] = "false";

                    return(RedirectToAction(nameof(Index)));
                }
            }
        }
예제 #8
0
        public async Task <IActionResult> Index(string searchString, string sortOrder, string currentFilter, int?pageNumber)
        {
            //Todo : Si ecran trop petit afficher des colonnes en moins
            //Todo : limiter le nombre de catégories montrées a 3
            //Todo : Probleme si critères vide sort ne trie pas bien

            IQueryable <Game> games;

            if (!String.IsNullOrEmpty(searchString))
            {
                games      = _gameService.GetGamesByName(searchString);
                pageNumber = 1;
            }
            else
            {
                games        = _gameService.GetGames();
                searchString = currentFilter;
            }
            games = _gameService.GetGamesValidate(games);
            GamesIndexData gamesAllData = await SortGames(searchString, sortOrder, currentFilter, pageNumber, games);

            bool isAuthenticated = User.Identity.IsAuthenticated;

            if (isAuthenticated)
            {
                LudothequeUser user = await UserServices.GetUserAsync(userManager, User.Identity.Name);

                gamesAllData = _gameAllDataService.GamesPoss(gamesAllData, user.Id);
            }
            else
            {
                gamesAllData = _gameAllDataService.NoGamesPoss(gamesAllData);
            }


            return(View(gamesAllData));
        }
예제 #9
0
        public async Task <IActionResult> Index(string searchString, string sortOrder, string currentFilter, int?pageNumber)
        {
            LudothequeUser user = await UserServices.GetUserAsync(userManager, User.Identity.Name);

            IQueryable <Game> games;

            games = _gameService.GetGamesByUser(user.Id);
            if (!String.IsNullOrEmpty(searchString))
            {
                games      = _gameService.GetGamesByName(searchString, games);
                pageNumber = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            games = _gameService.GetGamesValidate(games);
            GamesIndexData gamesAllData = await SortGames(searchString, sortOrder, currentFilter, pageNumber, games);

            gamesAllData = _gameAllDataService.GamesPoss(gamesAllData, user.Id);

            ViewBag.MyGames = "true";
            return(View(gamesAllData));
        }
예제 #10
0
        public static async Task SeedDB(LudothequeAccountContext context, UserManager <LudothequeUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            //======================================= Delete all data (temporary) =======================================

            //DropAllData(context);


            if (!roleManager.RoleExistsAsync("Admin").Result)
            {
                IdentityRole identityRole = new IdentityRole
                {
                    Name = "Admin"
                };
                await roleManager.CreateAsync(identityRole);
            }
            if (userManager.FindByEmailAsync("*****@*****.**").Result == null)
            {
                LudothequeUser identityUser = new LudothequeUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true
                };
                IdentityResult result = userManager.CreateAsync(identityUser, "Password.1234").Result;

                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(identityUser, "Admin").Wait();
                }
            }
            ;
            //======================================= Add Editors =======================================
            if (!context.Editors.Any())
            {
                context.Editors.AddRange(

                    );
                var editors = new Editor[]
                {
                    new Editor
                    {
                        Name        = "Asmodee",
                        Description = "Editeur Francais"
                    },
                    new Editor
                    {
                        Name = "Geek Attitude Games",
                    },
                    new Editor
                    {
                        Name        = "Repos Production",
                        Description = "éditeur européen de jeux de société"
                    }
                };
                AddInDataBase(editors, context);
            }
            //======================================= Add Illustrators =======================================
            if (!context.Illustrators.Any())
            {
                context.Illustrators.AddRange(

                    );
                var illu = new Illustrator[]
                {
                    new Illustrator
                    {
                        FirstName = "Alex ",
                        LastName  = "Pierangelini"
                    },
                    new Illustrator
                    {
                        FirstName = "Xavier ",
                        LastName  = "Colette"
                    }
                };
                AddInDataBase(illu, context);
            }

            //======================================= Add Difficulty =======================================
            if (!context.Difficulties.Any())
            {
                var diff = new Difficulty[]
                {
                    new Difficulty
                    {
                        label = Label.Easy
                    },
                    new Difficulty
                    {
                        label = Label.Moderate
                    },
                    new Difficulty
                    {
                        label = Label.Hard
                    }
                };
                AddInDataBase(diff, context);
            }

            //======================================= Add Theme =======================================
            if (!context.Theme.Any())
            {
                var themes = new Theme[]
                {
                    new Theme
                    {
                        Name = "FarWest"
                    },
                    new Theme
                    {
                        Name = "Abysse"
                    },
                    new Theme
                    {
                        Name = "Rêve"
                    },
                    new Theme
                    {
                        Name = "Science fiction"
                    }
                };
                AddInDataBase(themes, context);
            }

            //======================================= Add Material Supports =======================================
            if (!context.MaterialSupport.Any())
            {
                var ms = new MaterialSupport[]
                {
                    new MaterialSupport
                    {
                        Name = "Dé"
                    },
                    new MaterialSupport
                    {
                        Name = "Cartes"
                    },
                    new MaterialSupport
                    {
                        Name = "Plateau"
                    },
                    new MaterialSupport
                    {
                        Name = "Figurines"
                    }
                };
                AddInDataBase(ms, context);
            }

            //======================================= Add Mechanisms =======================================
            // Look for any games.
            if (!context.Mechanism.Any())
            {
                var mecha = new Mechanism[]
                {
                    new Mechanism
                    {
                        Name = "Triche"
                    },
                    new Mechanism
                    {
                        Name = "Mensonges"
                    },
                    new Mechanism
                    {
                        Name = "Collaboration"
                    },
                    new Mechanism
                    {
                        Name = "Economie"
                    },
                    new Mechanism
                    {
                        Name = "Physique"
                    },
                    new Mechanism
                    {
                        Name = "Devinettes"
                    }
                };
                AddInDataBase(mecha, context);
            }

            //======================================= TAll difficulties =======================================

            var difficultiesList = context.Difficulties;
            var ediors           = context.Editors;
            var illustrat        = context.Illustrators;

            //======================================= Add Games =======================================

            // Look for any games.
            if (!context.Games.Any())
            {
                var games = new Game[]
                {
                    new Game
                    {
                        Name          = "Abyss",
                        Description   = "Depuis des siècles, les Atlantes règnent sur les profondeurs des Océans. Leur royaume, Abyss, est respecté de tous les peuples alliés, heureux d'y trouver une protection contre les redoutables monstres sous-marins. Bientôt, le trône Atlante sera libre. Pour y accéder, fédérez les meilleurs représentants des peuples alliés, recrutez des seigneurs Atlantes et contrôlez les principaux territoires du royaume.",
                        Price         = 37.99m,
                        MaxPlayer     = 4,
                        MinPlayer     = 2,
                        MinimumAge    = 14,
                        DifficultyId  = difficultiesList.Single(s => s.label == Label.Hard).Id,
                        EditorId      = ediors.Single(s => s.Name == "Asmodee").Id,
                        IllustratorId = illustrat.Single(s => s.LastName == "Colette").Id,
                        Validate      = true,
                        ReleaseDate   = 2014
                    },
                    new Game
                    {
                        Name        = "Secret Hitler",
                        Description = "jeu avec rôles cachés",
                        Price       = 0,
                        MaxPlayer   = 10,
                        MinPlayer   = 5,
                        MinimumAge  = 18,
                        Validate    = true,
                        ReleaseDate = 2014
                    },
                    new Game
                    {
                        Name        = "Complot",
                        Description = "jeu avec rôles cachés",
                        Price       = 11.99m,
                        MaxPlayer   = 8,
                        MinPlayer   = 2,
                        MinimumAge  = 8,
                        Validate    = true,
                        ReleaseDate = 2013
                    }, new Game
                    {
                        Name        = "Bang the bullet",
                        Description = "Jeu western ",
                        Price       = 36.00m,
                        MaxPlayer   = 8,
                        MinPlayer   = 3,
                        MinimumAge  = 8,
                        Validate    = true,
                        ReleaseDate = 2013
                    }, new Game
                    {
                        Name        = "Bang",
                        Description = "Jeu western",
                        Price       = 18,
                        MaxPlayer   = 7,
                        MinPlayer   = 4,
                        MinimumAge  = 8,
                        Validate    = true,
                        ReleaseDate = 2011
                    }, new Game
                    {
                        Name        = "Sheriff de Nottingham",
                        Description = "Jeu de commerce",
                        Price       = 18,
                        MaxPlayer   = 5,
                        MinPlayer   = 3,
                        MinimumAge  = 13,
                        Validate    = true,
                        ReleaseDate = 2016
                    }, new Game
                    {
                        Name        = "When I dream",
                        Description = "Jeu de devinettes",
                        Price       = 18,
                        MaxPlayer   = 10,
                        MinPlayer   = 4,
                        MinimumAge  = 8,
                        GameTime    = 30,
                        EditorId    = ediors.Single(s => s.Name == "Repos Production").Id,
                        Validate    = false,
                        ReleaseDate = 2017
                    }, new Game
                    {
                        Name        = "Not Alone",
                        Description = "Jeu de d'exploration",
                        Price       = 18,
                        MaxPlayer   = 10,
                        MinPlayer   = 4,
                        MinimumAge  = 8,
                        GameTime    = 30,
                        EditorId    = ediors.Single(s => s.Name == "Geek Attitude Games").Id,
                        Validate    = true,
                        ReleaseDate = 2016
                    }
                };
                AddInDataBase(games, context);

                //======================================= Add Relation Theme =======================================
                var contextGames = context.Games;
                var contextTheme = context.Theme;

                var ThemesGames = new ThemesGames[]
                {
                    new ThemesGames()
                    {
                        GameId  = contextGames.Single(s => s.Name == "Abyss").Id,
                        ThemeId = contextTheme.Single(s => s.Name == "Abysse").Id,
                    }, new ThemesGames()
                    {
                        GameId  = contextGames.Single(s => s.Name == "When I Dream").Id,
                        ThemeId = contextTheme.Single(s => s.Name == "Rêve").Id,
                    }, new ThemesGames()
                    {
                        GameId  = contextGames.Single(s => s.Name == "Not Alone").Id,
                        ThemeId = contextTheme.Single(s => s.Name == "Science fiction").Id,
                    }
                };
                AddInDataBase(ThemesGames, context);
                //======================================= Add Relation Material =======================================
                var contextMaterialSupport = context.MaterialSupport;

                var materialSupportsGames = new MaterialSupportsGames[]
                {
                    new MaterialSupportsGames()
                    {
                        GameId            = contextGames.Single(s => s.Name == "Abyss").Id,
                        MaterialSupportId = contextMaterialSupport.Single(s => s.Name == "Plateau").Id,
                    }, new MaterialSupportsGames()
                    {
                        GameId            = contextGames.Single(s => s.Name == "Abyss").Id,
                        MaterialSupportId = contextMaterialSupport.Single(s => s.Name == "Cartes").Id,
                    }, new MaterialSupportsGames()
                    {
                        GameId            = contextGames.Single(s => s.Name == "When I Dream").Id,
                        MaterialSupportId = contextMaterialSupport.Single(s => s.Name == "Cartes").Id,
                    }
                };
                AddInDataBase(materialSupportsGames, context);
                //======================================= Add Mechansim =======================================
                var contextMechansim = context.Mechanism;

                var MechaGames = new MechanismsGames[]
                {
                    new MechanismsGames()
                    {
                        GameId      = contextGames.Single(s => s.Name == "Abyss").Id,
                        MechanismId = contextMaterialSupport.Single(s => s.Name == "Economie").Id,
                    }, new MechanismsGames()
                    {
                        GameId      = contextGames.Single(s => s.Name == "Bang").Id,
                        MechanismId = contextMaterialSupport.Single(s => s.Name == "Mensonges").Id,
                    }, new MechanismsGames()
                    {
                        GameId      = contextGames.Single(s => s.Name == "Bang").Id,
                        MechanismId = contextMaterialSupport.Single(s => s.Name == "Collaboration").Id,
                    }, new MechanismsGames()
                    {
                        GameId      = contextGames.Single(s => s.Name == "When I Dream").Id,
                        MechanismId = contextMaterialSupport.Single(s => s.Name == "Devinettes").Id,
                    }
                };
                AddInDataBase(materialSupportsGames, context);
            }
        }
예제 #11
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 LudothequeUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        {
                            return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }));
                        }

                        await _signInManager.SignInAsync(user, isPersistent : false);

                        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());
        }