private UserApp authenticationUser(SignInRequest request) { UserApp userFound = new UserApp(); /** * Buscar al usuario por el correo o el nickname */ var context = _context; var query = from user in context.Set <UserApp>() .Where(u => u.userNicname == request.usernameOrEmail || u.userEmail == request.usernameOrEmail) select new { user.UserAppId, user.userNicname, user.userLastname, user.userName, user.userEmail, user.userNumDocument, user.userPassword, user.userType }; if (query.Count() == 0) { userFound = null; } else if (query.Count() > 1) { _logger.LogError("El nickname o email: " + request.usernameOrEmail + " posee más de dos registro."); userFound = null; } else { userFound.userEmail = query.Single().userEmail; userFound.userLastname = query.Single().userLastname; userFound.userName = query.Single().userName; userFound.userNicname = query.Single().userNicname; userFound.userNumDocument = query.Single().userNumDocument; userFound.userPassword = query.Single().userPassword; userFound.UserAppId = query.Single().UserAppId; } /// <summary> /// Si el usuario existe se procede a validar la contraseña /// </summary> if (userFound != null) { Boolean isValidPassword = PasswordServices.PasswordMatch(request.password, userFound.userPassword); if (!isValidPassword) { userFound = null; } } return(userFound); }
public string TryUpdate(UpdateCredentialsRequest request) { string msgValidation = null; var context = _context; var query = from user in context.Set <UserApp>() .Where(u => u.userNicname == request.nickname) select user; if (query.Count() > 0) { UserApp userFound = query.Single(); Boolean isValidPassword = PasswordServices.PasswordMatch(request.currentPass, userFound.userPassword); if (!isValidPassword) { _logger.LogError("[USER NOT MATCH CREDENCIALS] nickname: " + request.nickname); msgValidation = "Nombre de Usuario o Contraseña incorrecta."; } else if (!request.newPass.Equals(request.confirmNewPass)) { _logger.LogError("[NOT MATCH NEW PASSWORD WITH CONFIRMATION] nickname: " + request.nickname); msgValidation = "La contraseña nueva no coincide con la ingresada posteriormente."; } else { userFound.userPassword = PasswordServices.PasswordEncoder(request.newPass); userFound = _userModelServices.update(userFound); /*Actualización del Usuario a estado Activo*/ States stateActive = _statesModelServices.findByKeyword("S001"); StatesOfUser statesOfUser = _statesOfUserModelServices.findByUserAppId(userFound.UserAppId); if (statesOfUser != null) { statesOfUser.ModifiedAt = DateTime.Now; statesOfUser.StatesId = stateActive.StatesId; statesOfUser = _statesOfUserModelServices.update(statesOfUser); } else { msgValidation = "El usuario no tiene asignado un Estado. Contáctese con soporte"; } } } else { _logger.LogError("[USER NOT FOUND] nickname: " + request.nickname); msgValidation = "Nombre de Usuario o Contraseña incorrecta."; } return(msgValidation); }