public async Task <UserResponseEntities> Login(AuthRequestEntities authRequestEntities) { using (var connection = _configuration.GetConnectionSeguridad) { const string procedure = "PROC_S_Login"; var parameters = new DynamicParameters(); parameters.Add("@pEmail", authRequestEntities.Username, DbType.String); parameters.Add("@pPassword", authRequestEntities.Password, DbType.String); var response = await connection.QueryAsync <UserResponseEntities>(procedure, parameters, commandType : CommandType.StoredProcedure); return(response.FirstOrDefault()); } }
public async Task <Response <AuthResponseDto> > Login(AuthRequestDto authRequestDto) { AuthRequestEntities authRequest = _mapper.Map <AuthRequestEntities>(authRequestDto); var response = new Response <AuthResponseDto>(); string todo = null; try { if (authRequestDto == null) { response.IsSuccess = false; response.IsWarning = true; response.CodigoError = "0"; response.Message = "Envio de parametros inválido,intente denuevo."; return(response); } else if (string.IsNullOrEmpty(authRequestDto.Username) || string.IsNullOrEmpty(authRequestDto.Password)) { response.IsSuccess = false; response.IsWarning = true; response.CodigoError = "0"; response.Message = "Envio de parametros inválido,intente denuevo."; return(response); } //valida el usuario y password var responseData = await _usuarioDomain.Login(authRequest); response.Data = _mapper.Map <AuthResponseDto>(responseData); var ver = Convert.ToInt32(todo); if (response.Data == null) { response.IsSuccess = false; response.IsWarning = true; response.CodigoError = "0"; response.Message = "Usuario y/o contraseña incorrecta."; return(response); } else { response.Data.Token = JwtGenerator.CreateToken(_configuration, response.Data.UserName); response.Message = "Inicio de sesión correctamente."; //guardar sesion de usuario var sesion = new SesionUsuarioDto { IdUser = response.Data.Id, Token = response.Data.Token, DateStart = DateTime.Now, Status = 1 }; var sesionUsuarioEntities = _mapper.Map <SesionUsuarioEntities>(sesion); var responseSesion = await _usuarioDomain.GuardarSesion(sesionUsuarioEntities); } } catch (Exception ex) { throw ex; } return(response); }
public async Task <UserResponseEntities> Login(AuthRequestEntities authRequestEntities) { var response = await _usuarioRepository.Login(authRequestEntities); return(response); }