public IActionResult CreateToken([FromBody] UsersAuth login) { if (login == null) { return(Unauthorized()); } DateTime dt = DateTime.UtcNow.AddDays(7); bool validUser = Authenticate(login); string tokenString = string.Empty; var getUser = _context.UsersItems.SingleOrDefault(x => x.Username == login.Username); if (validUser) { tokenString = MyFunctions.BuildToken(_config, login.Username, dt); } else { return(Unauthorized()); } return(Ok( new { id = getUser.Id, username = getUser.Username, email = getUser.Email, role = getUser.Role, firstName = getUser.FirstName, lastName = getUser.LastName, image = getUser.Image, token = tokenString, expiration = dt } )); }
protected override void OnModelCreating(ModelBuilder builder) { var apiurl = "https://*****:*****@local.loc", Image = apiurl + "/resources/images/luis.jpg", FirstName = "Luis", LastName = "Carvalho", Role = "admin", Token = MyFunctions.BuildToken(_config, "luis", dt) }, new Users() { Id = 2, Username = "******", Password = BC.HashPassword("guest1234"), Email = "*****@*****.**", Image = apiurl + "/resources/images/guest.png", FirstName = "Guest", LastName = "G", Role = "guest", Token = MyFunctions.BuildToken(_config, "guest", dt) }, new Users() { Id = 3, Username = "******", Password = BC.HashPassword("goku1234"), Email = "*****@*****.**", Image = apiurl + "/resources/images/goku.png", FirstName = "Son", LastName = "Goku", Role = "user", Token = MyFunctions.BuildToken(_config, "goku", dt) }, new Users() { Id = 4, Username = "******", Password = BC.HashPassword("danny1234"), Email = "*****@*****.**", Image = apiurl + "/resources/images/danny.png", FirstName = "Danny", LastName = "Phantom", Role = "user", Token = MyFunctions.BuildToken(_config, "danny_phantom", dt) }, new Users() { Id = 5, Username = "******", Password = BC.HashPassword("jimmy1234"), Email = "*****@*****.**", Image = apiurl + "/resources/images/jimmy.jpg", FirstName = "Jimmy", LastName = "Neutron", Role = "user", Token = MyFunctions.BuildToken(_config, "jimmy_neutron", dt) }, new Users() { Id = 6, Username = "******", Password = BC.HashPassword("timmy1234"), Email = "*****@*****.**", Image = apiurl + "/resources/images/timmy.png", FirstName = "Timmy", LastName = "Turner", Role = "user", Token = MyFunctions.BuildToken(_config, "timmy_turner", dt) }, new Users() { Id = 7, Username = "******", Password = BC.HashPassword("ironman1234"), Email = "*****@*****.**", Image = apiurl + "/resources/images/ironman.jpg", FirstName = "Iron", LastName = "Man", Role = "user", Token = MyFunctions.BuildToken(_config, "ironman", dt) } ); builder.Entity <RadiosList>().HasData( new RadiosList() { Id = 1, RadioTitle = "M80", RadioSrc = "http://mcrscast.mcr.iol.pt/m80", RadioImage = apiurl + "/resources/images/radios/m80.jpg" } ); builder.Entity <News>().HasData( new News() { Id = 1, Title = "Noticia 1", Desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.", Date = DateTime.UtcNow, Cover = "assets/images/cover.jpg", Category = "Exemplo", Text = "<p class='t-justify'>Lorem ipsum dolor sit amet, <b style='background-color: yellow;'>consectetur adipiscing elit</b>. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.</p><p>Youtube video: </p><iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/azdwsXLmrHE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>", Source = "/news/1", UsersId = 1 }, new News() { Id = 2, Title = "Noticia 2", Desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.", Date = DateTime.UtcNow, Cover = "assets/images/cover.jpg", Category = "Exemplo", Text = "<p class='t-justify'>Lorem ipsum dolor sit amet, <b style='background-color: orange;'>consectetur adipiscing elit</b>. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.</p><p>Youtube video: </p><iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/azdwsXLmrHE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>", Source = "/news/2", UsersId = 1 }, new News() { Id = 3, Title = "Noticia 3", Desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.", Date = DateTime.UtcNow, Cover = "assets/images/cover.jpg", Category = "Exemplo", Text = "<p class='t-justify'>Lorem ipsum dolor sit amet, <b style='background-color: lightblue;'>consectetur adipiscing elit</b>. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.</p><p>Youtube video: </p><iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/azdwsXLmrHE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>", Source = "/news/3", UsersId = 1 }, new News() { Id = 4, Title = "Noticia 4", Desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.", Date = DateTime.UtcNow, Cover = "assets/images/cover.jpg", Category = "Exemplo", Text = "<p class='t-justify'>Lorem ipsum dolor sit amet, <b style='background-color: orange;'>consectetur adipiscing elit</b>. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.</p><p>Youtube video: </p><iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/azdwsXLmrHE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>", Source = "/news/4", UsersId = 1 }, new News() { Id = 5, Title = "Noticia 5", Desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.", Date = DateTime.UtcNow, Cover = "assets/images/cover.jpg", Category = "Exemplo", Text = "<p class='t-justify'>Lorem ipsum dolor sit amet, <b style='background-color: yellow;'>consectetur adipiscing elit</b>. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.</p><p>Youtube video: </p><iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/azdwsXLmrHE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>", Source = "/news/5", UsersId = 1 }, new News() { Id = 6, Title = "Noticia 6", Desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.", Date = DateTime.UtcNow, Cover = "assets/images/cover.jpg", Category = "Exemplo", Text = "<p class='t-justify'>Lorem ipsum dolor sit amet, <b style='background-color: orange;'>consectetur adipiscing elit</b>. Suspendisse lobortis vitae elit id sagittis. Integer maximus leo in dapibus feugiat. Duis nulla orci, consequat in lobortis vel, condimentum vel turpis. Morbi quis tincidunt enim. Nunc finibus mi felis. Sed lobortis ornare dui, sit amet consequat felis. Suspendisse id orci accumsan, tincidunt quam ultrices, fringilla turpis.</p><p>Youtube video: </p><iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/azdwsXLmrHE' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>", Source = "/news/6", UsersId = 1 } ); builder.Entity <Videos>().HasData( new Videos() { Id = 1, Src = apiurl + "/resources/videos/v1.mp4", Type = "video/mp4" }, new Videos() { Id = 2, Src = apiurl + "/resources/videos/v2.mp4", Type = "video/mp4" }, new Videos() { Id = 3, Src = apiurl + "/resources/videos/v3.mp4", Type = "video/mp4" } ); builder.Entity <Games>().HasData( new Games() { Id = 1, Title = "GTA V", Desc = "GTA V", Cover = apiurl + "/resources/images/games/gtav.jpg", Platforms = "PS3,X360,PS3,XONE,PS4,PC,PS5,XSERIES X|S", Platform_used = "PC", Developer = "Rockstar North", Publisher = "Rockstar Games", Genre = "Action and Adventure", Release_date = new System.DateTime(2017, 9, 13, 0, 0, 0), UsersId = 1 } ); builder.Entity <SaveGames>().HasData( new SaveGames() { Id = 1, Title = "Prologue", Is_req_to_100 = true, Type_medal = "Gold", File_img = apiurl + "/resources/images/games/gtav.jpg", File_url = "https://gtasnp.com/v-prologue", GamesId = 1, UsersId = 1 } ); base.OnModelCreating(builder); }