public IActionResult Login(UserModel model) { if (!ModelState.IsValid) { return(View()); } var user = _userService.Get().FirstOrDefault(u => u.Username.Equals(model.Username) && u.PasswordHash.Equals(_passwordHashService.Hash(model.Password))); if (user == null) { return(View(model)); } var userClaims = new List <Claim> { new Claim(ClaimTypes.Name, user.Username), new Claim(ClaimTypes.Email, user.EmailAddress), new Claim(ClaimTypes.Role, user.Role), new Claim(ClaimTypes.UserData, user.Id) }; var identity = new ClaimsIdentity(userClaims, "User Identity"); var userPrincipal = new ClaimsPrincipal(new [] { identity }); HttpContext.SignInAsync(userPrincipal); return(RedirectToAction("Panel", "Home")); }
public override async Task UpdateAsync(UserModel model) { var command = new UpdateUserCommand(model.Id) { Entity = _mapper.Map <User>(model) }; if (!command.IsValid()) { await RaiseValidationErrorsAsync(command); return; } var dbEntity = await _userRepository.GetByIdAsync(command.Entity.Id); if (dbEntity == null) { await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, CoreUserMessages.RegistroNaoEncontrado.Message)); return; } var listaUser = await _userRepository.GetAllAsync(); if (listaUser.Any(c => c.Id != command.Entity.Id && string.Equals(c.Username, command.Entity.Username, StringComparison.CurrentCultureIgnoreCase))) { await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, CoreUserMessages.ValorDuplicadoO.Format("Username").Message)); return; } command.Entity.Password = PasswordHashService.Hash(command.Entity.Password); _mapper.Map(command.Entity, dbEntity); command.Entity = dbEntity; await _mediatorHandler.SendCommandAsync(command); }
static void Main(string[] args) { //var uof = new UnitOfWork(new ApplicationContext()); //using (var container = ConfigurerBLL.ConfigureDependencies()) //{ // var uof = container.Resolve<IUnitOfWork>(); // var userService = container.Resolve<IUserService>(); // var postService = container.Resolve<IPostService>(); // //postService.SetLike(new LikeDTO {PostId = 3, UserId = 1}); // //userService.CreateUser(new UserDTO() // //{ // // Name = "Maks", // // Password = "******", // // Surname = "Maks", // // Role = "Admin", // // Rating = 0, // // Email= "*****@*****.**", // //}); // //var user = userService.GetUserById(1); // //Console.WriteLine($"{user.Email} {user.Password} {user.GetType()}"); // //var x = userService.GetUserByEmailAndPass(user.Email, user.Password); // //Console.WriteLine(x.GetType()); // //foreach (var userDto in userService.GetAll()) // //{ // // Console.WriteLine($"{userDto.Name} {userDto.Password} {userDto.GetType()}"); // //} //} Console.WriteLine(PasswordHashService.Hash("Admin_123")); Console.WriteLine(PasswordHashService.Hash("Admin_123")); var x = PasswordHashService.Hash("Admin_123"); Console.WriteLine(PasswordHashService.Check(PasswordHashService.Hash("Admin_123"), "Admin_123")); Console.WriteLine(PasswordHashService.Check(PasswordHashService.Hash("Admin_123"), "Admin_12")); }