Ejemplo n.º 1
0
        public async Task <ActionResult> Login([FromBody] LoginViewModel userFromView)
        {
            var user = await _userManager.FindByNameAsync(userFromView.Username);

            if (user != null && await _userManager.CheckPasswordAsync(user, userFromView.Password))
            {
                JwtSecurityToken accessToken = await TokenFactory.GenerateJwtToken(user, _configuration, _userManager);

                //generate refresh token
                var refreshToken       = TokenFactory.GenerateRefreshToken();
                var refreshTokenFromDb = _dbContext.UserTokens.Find(user.Id, "GetOnBoard", "refreshToken");

                if (refreshTokenFromDb == null)
                {
                    _dbContext.UserTokens.Add(new IdentityUserToken <string> {
                        UserId = user.Id, Name = "refreshToken", Value = refreshToken, LoginProvider = "GetOnBoard"
                    });
                }
                else
                {
                    refreshTokenFromDb.Value = refreshToken;
                }
                await _dbContext.SaveChangesAsync();

                _logger.LogInformation(LoggingEvents.LoginUser, "User: {ID} successfully login. Token: {token}", user.UserName, new JwtSecurityTokenHandler().WriteToken(accessToken));

                return(Ok(new JWTUserTokenViewModel(new JwtSecurityTokenHandler().WriteToken(accessToken), accessToken.ValidTo, refreshToken)));
            }
            else
            {
                _logger.LogInformation(LoggingEvents.LoginUser, "Login failed for UserName: {ID} and Password: {password}", userFromView.Username, userFromView.Password);
            }
            return(Unauthorized());
        }
Ejemplo n.º 2
0
        public static async Task LeaveGameSession(this GetOnBoardDbContext source, GameSessionApplicationUser gSAppUser, GameSession gameSession)
        {
            source.GameSessionApplicationUsers.Remove(gSAppUser);
            await source.SaveChangesAsync();

            await source.UpdateFreeSlotsInGS(gameSession, -1);
        }
Ejemplo n.º 3
0
        public static async Task <int> AddGameSession(this GetOnBoardDbContext source, GameSession gameSession)
        {
            source.GameSessions.Add(gameSession);
            await source.SaveChangesAsync();

            return(gameSession.ID);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Upload([FromBody] UpdateImageInProfile model)
        {
            string userID = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (userID == null)
            {
                throw new Exception("Uknown User");
            }

            //using (Stream stream = file.OpenReadStream())
            //{
            //	await _blobStorage.Save(stream, $"{userID}.jpg");
            //}
            UserProfile profile = _dbContext.UserProfiles.FirstOrDefault(x => x.ApplicationUserID == userID) ?? new UserProfile();

            byte[] imageBoardGameBytes = Convert.FromBase64String(model.Avatar);
            Stream stream = new MemoryStream(imageBoardGameBytes);
            await _blobStorage.Save(stream, $"{userID}.jpg");

            profile.Avatar = _blobStorage.Load($"{userID}.jpg").Uri.AbsoluteUri;

            await _dbContext.SaveChangesAsync();

            return(StatusCode((int)HttpStatusCode.Accepted, Json(profile)));
        }
Ejemplo n.º 5
0
 public static async Task UpdateDataInUserProfile(this GetOnBoardDbContext source, UserProfile userProfile, UpdateProfileViewModel model, string boardGameImage)
 {
     userProfile.FirstName   = model.FirstName;
     userProfile.LastName    = model.LastName;
     userProfile.City        = model.City;
     userProfile.Description = model.Description;
     userProfile.Avatar      = boardGameImage;
     source.UserProfiles.Update(userProfile);
     await source.SaveChangesAsync();
 }
        public async Task CreateNewMessageItemAsync(Message message, int gameSessionId)
        {
            await _db.MessageEntities.AddAsync(new MessageEntity()
            {
                Author        = message.Author,
                Message       = message.MessageContent,
                GameSessionId = gameSessionId,
                SendTime      = message.SendTime,
                Avatar        = message.Avatar
            });

            await _db.SaveChangesAsync();

            _logger.LogInformation($"New message added to GameSession: {gameSessionId}");
        }
 public static async Task RemoveGameSessionBoardGamesAsync(this GetOnBoardDbContext source, GameSessionBoardGame gameSessionBG)
 {
     source.GameSessionBoardGames.Remove(gameSessionBG);
     await source.SaveChangesAsync();
 }
Ejemplo n.º 8
0
        public static async Task AddMessageFromUser(this GetOnBoardDbContext source, Contact contact)
        {
            source.Contact.Add(contact);

            await source.SaveChangesAsync();
        }
Ejemplo n.º 9
0
 public static async Task UpdateNumberOfGamesSessionYouWereKickedOut(this GetOnBoardDbContext source, UserProfile userProfile)
 {
     userProfile.NumberOfGamesSessionYouWereKickedOut = userProfile.NumberOfGamesSessionYouWereKickedOut + 1;
     await source.SaveChangesAsync();
 }
Ejemplo n.º 10
0
 public static async Task UpdateNumberGamesJoined(this GetOnBoardDbContext source, UserProfile userProfile)
 {
     userProfile.NumberOfGamesSessionJoined = userProfile.NumberOfGamesSessionJoined + 1;
     await source.SaveChangesAsync();
 }
Ejemplo n.º 11
0
 public static async Task UpdateNumberGamesSessionDeletedasAdmin(this GetOnBoardDbContext source, UserProfile userProfile)
 {
     userProfile.NumberOfGamesSessionDeletedasAdmin = userProfile.NumberOfGamesSessionDeletedasAdmin + 1;
     await source.SaveChangesAsync();
 }
Ejemplo n.º 12
0
 public static async Task UpdateFreeSlotsInGS(this GetOnBoardDbContext source, GameSession gameSession, int count)
 {
     gameSession.SlotsFree = gameSession.SlotsFree + count;
     source.GameSessions.Update(gameSession);
     await source.SaveChangesAsync();
 }
Ejemplo n.º 13
0
 public static async Task RemoveGameSessionAsync(this GetOnBoardDbContext source, GameSession gameSession)
 {
     gameSession.IsCanceled = true;
     source.GameSessions.Update(gameSession);
     await source.SaveChangesAsync();
 }
Ejemplo n.º 14
0
 public static async Task AddBoardGame(this GetOnBoardDbContext source, BoardGame boardGame)
 {
     source.BoardGames.Add(boardGame);
     await source.SaveChangesAsync();
 }
Ejemplo n.º 15
0
 public static async Task AddBoardGameToGameSession(this GetOnBoardDbContext source, GameSessionBoardGame gameSessionBG)
 {
     source.GameSessionBoardGames.Add(gameSessionBG);
     await source.SaveChangesAsync();
 }
 public static async Task RemoveGameSessionApplicationUserAsync(this GetOnBoardDbContext source, GameSessionApplicationUser gameSessionAppUser)
 {
     source.GameSessionApplicationUsers.Remove(gameSessionAppUser);
     await source.SaveChangesAsync();
 }